forked from rancher/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INT] Refactored some of the plugins - 2 (rancher#10944)
[INT] Refactored some of the plugins - 2
- Loading branch information
1 parent
eafedc0
commit ff7b136
Showing
8 changed files
with
58 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
import Vue from 'vue'; | ||
|
||
export default Vue.directive('positiveIntNumber', { | ||
inserted(el) { | ||
el.addEventListener('keypress', (e) => { | ||
e = e || window.event; | ||
const charcode = typeof e.charCode === 'number' ? e.charCode : e.keyCode; | ||
const re = /^\d+$/; // Use regex to match positive numbers | ||
function positiveIntNumber(el) { | ||
el.addEventListener('keypress', (e) => { | ||
e = e || window.event; | ||
const charcode = typeof e.charCode === 'number' ? e.charCode : e.keyCode; | ||
const re = /^\d+$/; // Use regex to match positive numbers | ||
|
||
if (!re.test(String.fromCharCode(charcode)) && charcode > 9 && !e.ctrlKey) { | ||
if (e.preventDefault) { | ||
e.preventDefault(); | ||
} else { | ||
e.returnValue = false; | ||
} | ||
if (!re.test(String.fromCharCode(charcode)) && charcode > 9 && !e.ctrlKey) { | ||
if (e.preventDefault) { | ||
e.preventDefault(); | ||
} else { | ||
e.returnValue = false; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
export default positiveIntNumber; | ||
|
||
// This is being done for backwards compatibility with our extensions that have written tests and didn't properly make use of Vue.use() when importing and mocking plugins | ||
|
||
const isThisFileBeingExecutedInATest = process.env.NODE_ENV === 'test'; | ||
|
||
if (isThisFileBeingExecutedInATest) { | ||
/* eslint-disable-next-line no-console */ | ||
console.warn('The implicit addition of positiveIntNumber has been deprecated in Rancher Shell and will be removed in a future version. Make sure to invoke `Vue.directive("positiveIntNumber", { inserted: positiveIntNumber })` to maintain compatibility.'); | ||
|
||
Vue.directive('positiveIntNumber', { inserted: positiveIntNumber }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters