This repository is not maintained anymore.
- Disabling of user-select.
- Disabling of context menu.
- Disabling of specific key action.
- Disabling of console actions.
- Showing alerts on console.
AngularJS v1.0.3, or a newer version.
- Add one of dist files (original / min) to main file sources of project.
- Inject 'ngPrevent' as a dependency of your angular module.
- Start to prevent on any element you want!
When you define prevent options on scope - you can use the following options:
- userSelect
true
: Preventing a user selection on the element.
false
: Allowing a user selection on the element. - contextMenu
true
: Preventing a context menu on the element.
false
: Allowing a context menu on the element. - keys
[]
: Preventing a key press on the element.
Acceptable values are:BACKSPACE
,TAB
,ENTER
,WIN_KEY
,F11
andF12
. - console
[]
: Preventing an actions on console.
The values of array are messages to console.
A message object pattern:{ text: 'Message', style: 'CSS properties'}
Add a prevent attribute on your element:
<div prevent="myPreventOptions">
<p>Text</p>
</div>
myPreventOptions should be on scope:
demoModule.controller('MainController', function ($scope) {
$scope.myPreventOptions = {
userSelect: true,
contextMenu: false
};
});
Alternatively, definiton of preventOptions can be on rootScope:
demoModule.run(function ($rootScope) {
$rootScope.preventOptions = {
userSelect: true,
contextMenu: true,
console: [
{
text: 'Stop!',
style: 'color: red; font-size: 35pt'
},
{
text: 'Not allowed here!',
style: 'color: white; font-size: 30pt'
}
],
keys: [
'F12',
'F11',
'WIN_KEY'
]
};
});
Important note: Defintion of preventOptions on rootScope is overrides any other definition on children scopes. Use rootScope only if you want to prevent on the HTML tag. Any other mode, define on the appropriate scope.