Skip to content
Browse files

Wrap oncomplete event code when supplied from data-set

  • Loading branch information...
1 parent aa5ddc4 commit 85695d02d136bb1aec01b318202b0d203b8678f7 @leegee committed
Showing with 11 additions and 11 deletions.
  1. +1 −5 Demo/index.html
  2. +3 −4 README.md
  3. +7 −2 Source/Knob.js
View
6 Demo/index.html
@@ -192,11 +192,7 @@
aria-valuemax=100
data-value=0
data-forceint=1
- data-oncomplete='
- (function(){
- alert("My value is "+this.value)
- })
- '></span>
+ data-oncomplete=' alert("My value is "+this.value) '></span>
&mdash; Value
<input type='text' value='' id='knob-js95-value'></span>
</xmp>
View
7 README.md
@@ -135,12 +135,11 @@ In addition to the above options, the following events are supported:
* `onComplete`: fired when no changes have taken place for the number milliseconds defined in the `completedelay` option.
* `onTick`: fired as the knob is turned
-The options may be passed as HTML dataset attributes by prepending `data-`,
-though you will need to consider that supplied code will be evaluated when
-parsed from the DOM, so will need something like this:
+The options may be passed as HTML dataset attributes by prepending `data-`.
+The supplied code is wrapped:
(function(){
- alert("My value is "+this.value)
+ // Supplied code here
})
The `onTick` event is intended to allow the user to adjust the behaviour
View
9 Source/Knob.js
@@ -73,7 +73,7 @@ var Knob = new Class({
// Adjusts rotation by degrees: changes the knob type from a pan control to a 0-10 control, for eample.
degreesoffset: 0,
// Milliseconds after which onComplete is fired if render has been inactive
- completedelay: 500,
+ completedelay: 1000,
// Fired when all processing is done, but for rotation the control by the value in `this.degrees`
onTick: function(){},
@@ -487,8 +487,13 @@ Knob.parseDOM = function( selector ){
}
) || i;
+ // If key changed fron onx to onX, assume code to wrap:
+ if (keyToSet != i){
+ el.dataset[i] = '(function(){ ' + el.dataset[i] +'})';
+ }
+
// Rough casting
- try {
+ try {
opts[keyToSet] = eval( el.dataset[i] );
}
catch(e) {

0 comments on commit 85695d0

Please sign in to comment.
Something went wrong with that request. Please try again.