From 0a883f3595620cef592ee804787219c376ed2403 Mon Sep 17 00:00:00 2001 From: aterrien Date: Sun, 15 Jul 2012 23:49:31 +0200 Subject: [PATCH 01/74] global refactoring / optimizations / fix #36 - refactoring of hooks - angleOffset, angleArc (fix #36) - canvas pre-rendering - (lot of) optimizations - 5+ digit support - improved positioning of the input - Knob is now part of Kontrol ^^ - tron skin removed - ticks removed --- README.md | 87 ++--- index.html | 284 ++++++++------ js/jquery.knob.js | 927 ++++++++++++++++++++++++++++------------------ 3 files changed, 791 insertions(+), 507 deletions(-) diff --git a/README.md b/README.md index b79a9b5..c8a4c3f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ jQuery Knob ============= - canvas based ; no png or jpg sprites. -- touch, mousewheel, keyboard events implemented. +- touch, mouse and mousewheel, keyboard events implemented. - downward compatible ; overloads an input element. Example @@ -33,11 +33,12 @@ Options are provided as attributes 'data-option': The following options are supported : Behaviors : -* min : min value || default=0. -* max : max value || default=100. -* stopper : stop at 0 & 100 on keydown/mousewheel || default=true. -* readOnly : disable input and events. -* angleOffset: change the 0 position of the knob (in degree), || default=0. +* min : min value | default=0. +* max : max value | default=100. +* angleOffset : starting angle in degrees | default=0. +* angleArc : arc size in degrees | default=360. +* stopper : stop at min & max on keydown/mousewheel | default=true. +* readOnly : disable input and events | default=false. UI : * cursor : display mode "cursor" | default=gauge. @@ -47,19 +48,13 @@ UI : * displayPrevious : default=false | true=displays the previous value with transparency. * fgColor : foreground color. * bgColor : background color. -* ticks : number of ticks | 0=disable. -* tickColor. -* tickLength. -* tickWidth. -* tickColorizeValues : colorize ticks. -* skin : default | "tron". Hooks ------- @@ -67,7 +62,6 @@ Hooks Parameters : + value : int, current value - + input : jQuery element, input element * 'change' : executed at each change of the value @@ -76,11 +70,16 @@ Hooks * 'draw' : when drawing the canvas - Parameters : - + angle : computed angle - + value : current value - + opt : plugin options - + context : Canvas context 2d + Context : + - this.g : canvas context 2D (see Canvas documentation) + - this.$ : jQuery wrapped element + - this.o : options + - this.i : input + - ... console.log(this); + +* 'cancel' : triggered on [esc] keydown + +The scope (this) of each hook function is the current Knob instance (refer to the demo code). Example ------- @@ -88,13 +87,9 @@ Example @@ -102,31 +97,29 @@ Dynamically configure ------- -Supported browser +Set the value ------- -Tested on Chrome, Safari, Firefox, IE 9.0. + -Revision 1.1.2 -------- -- removed padding around the wheel in default skin / default thickness = 0.35. -- 'configure' event. -- added 'displayPrevious' option. -- change color cgColor / 'displayPrevious' must be true. -- escape keycode supported while changing = restore the current value. -- tab keycode supported. -- added 'stopper'. -- bugfix init when 'value' attribute is not defined. -- JSLint qa. -- infinite mode demo. - -Revision 1.1.1 +Supported browser ------- -- keyboard/mousewheel control refactoring / acceleration. -- bugfix no keyboard or mousewheel when readonly. -- bugfix min/max can be exceeded. -- hooks / keyboard events. +Tested on Chrome, Safari, Firefox, IE 9.0. \ No newline at end of file diff --git a/index.html b/index.html index c55d500..f3e6785 100644 --- a/index.html +++ b/index.html @@ -6,142 +6,203 @@ -
- Knob demo - Flattr this +
+

jQuery Knob

-
+
+

Nice, downward compatible, touchable, jQuery dial. Flattr this

+

* implemented interactions : mouse click and wheel mouse, keyboard (on focus) and fingers (touch events)

+
+
+

× Disable display input

-data-width="75"
-data-fgColor="#fff"
-data-skin="tron"
-data-displayPrevious=true
+data-width="100"
+data-displayInput=false
             
- +
-
+
+

× 'cursor' mode

 data-width="150"
-data-fgColor="#fff"
-data-skin="tron"
-data-thickness=".2"
-data-displayPrevious=true
+data-cursor=true
+data-thickness=.3
+data-fgColor="#222222"
             
- +
-
+
+

× Display previous value

-data-width="150"
-data-fgColor="#fff"
-data-skin="tron"
-data-thickness=".1"
+data-displayPrevious=true
+data-min="-100"
             
- +
-
+
+

× Angle offset

-data-width="100"
-data-displayInput=false
+data-angleOffset=90
             
- +
-
+
+

× Angle offset and arc

-data-width="200"
-data-cursor=true
+data-fgColor="#66CC66"
+data-angleOffset=-125
+data-angleArc=250
             
- +
-
+
+

× 5-digit values

-data-width="200"
-data-min="-100"
-data-cgColor="#A9EFFD"
-data-displayPrevious=true
-data-angleOffset="90"
+data-min="-15000"
+data-max="15000"
             
- +
-
-

Ticks

-
-data-cursor=true
-data-skin="tron"
-data-ticks="8"
-            
- +
+

× Overloaded 'draw' method

+
+
+
+
+    data-width="75"
+    data-fgColor="#ffec03"
+    data-skin="tron"
+    data-thickness=".2"
+    data-displayPrevious=true
+                
+ +
+
+
+    data-width="150"
+    data-fgColor="#ffec03"
+    data-skin="tron"
+    data-thickness=".2"
+    data-displayPrevious=true
+                
+ +
+
+
+    data-width="150"
+    data-fgColor="#C0ffff"
+    data-skin="tron"
+    data-thickness=".1"
+    data-angleOffset="180"
+                
+ +
-
-

Readonly

+
+
+

× Readonly

 data-thickness=".4"
 data-fgColor="chartreuse"
@@ -149,8 +210,8 @@ 

Readonly

-
-

Knobify!

+
+

× Dynamic

 data-width="200"
             
@@ -163,10 +224,9 @@

Knobify!

-
-
-

Infinite / iPod click wheel

-
+
+

× Infinite || iPod click wheel

+
 data-width="150"
 data-cursor=true
@@ -179,10 +239,22 @@ 

Infinite / iPod click wheel

-
0
-
+
0
+
+
+
+

× Big !

+
+data-width="700"
+            
+ +
+
+
+

jQuery Knob is © 2012 Anthony Terrien and dual licensed under the MIT or GPL licenses.

+
- \ No newline at end of file From 6bda39943e34fec3c9e76812ed59a7ac636e3ca6 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 24 Jan 2013 22:32:59 +0100 Subject: [PATCH 10/74] Release 1.2.0 --- README.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c8a4c3f..be26c6e 100644 --- a/README.md +++ b/README.md @@ -122,4 +122,26 @@ Set the value Supported browser ------- -Tested on Chrome, Safari, Firefox, IE 9.0. \ No newline at end of file +Tested on Chrome, Safari, Firefox, IE 9.0. + +MIT License +------- + +Copyright (C) 2013 Anthony Terrien + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file From 9a3e5a76c507766400b6bceb9b2eb98d630e789c Mon Sep 17 00:00:00 2001 From: Anthony Terrien Date: Thu, 24 Jan 2013 23:08:08 +0100 Subject: [PATCH 11/74] Add jQuery manifest --- knob.jquery.json | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 knob.jquery.json diff --git a/knob.jquery.json b/knob.jquery.json new file mode 100644 index 0000000..fae6b41 --- /dev/null +++ b/knob.jquery.json @@ -0,0 +1,35 @@ +{ + "name": "knob", + "title": "jQuery Knob", + "description": "Nice, downward compatible, touchable, jQuery dial.", + "keywords": [ + "dial", + "button", + "knob" + ], + "version": "1.2.0", + "author": { + "name": "Anthony Terrien", + "url": "https://github.com/aterrien" + }, + "maintainers": [ + { + "name": "Anthony Terrien", + "email": "kontrol@anthonyterrien.com", + "url": "http://anthonyterrien.com/knob" + } + ], + "licenses": [ + { + "type": "MIT", + "url": "http://opensource.org/licenses/mit-license.php" + } + ], + "bugs": "https://github.com/aterrien/jQuery-Knob/issues", + "homepage": "https://github.com/aterrien/jQuery-Knob", + "docs": "https://github.com/aterrien/jQuery-Knob", + "download": "https://github.com/aterrien/jQuery-Knob/tags", + "dependencies": { + "jquery": ">=1.7" + } +} \ No newline at end of file From 4ba94db55ae863487d5710299bd55c15e8a3a0b7 Mon Sep 17 00:00:00 2001 From: Anthony Terrien Date: Thu, 24 Jan 2013 23:19:45 +0100 Subject: [PATCH 12/74] jquery manifest --- knob.jquery.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/knob.jquery.json b/knob.jquery.json index fae6b41..f130ac1 100644 --- a/knob.jquery.json +++ b/knob.jquery.json @@ -28,8 +28,7 @@ "bugs": "https://github.com/aterrien/jQuery-Knob/issues", "homepage": "https://github.com/aterrien/jQuery-Knob", "docs": "https://github.com/aterrien/jQuery-Knob", - "download": "https://github.com/aterrien/jQuery-Knob/tags", "dependencies": { - "jquery": ">=1.7" + "jquery": ">=1.7.0" } } \ No newline at end of file From 44f3207f48010c4a81024e7440e68942853934ff Mon Sep 17 00:00:00 2001 From: Anthony Terrien Date: Thu, 24 Jan 2013 23:26:52 +0100 Subject: [PATCH 13/74] add some popular tags --- knob.jquery.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/knob.jquery.json b/knob.jquery.json index f130ac1..b6c8e5b 100644 --- a/knob.jquery.json +++ b/knob.jquery.json @@ -5,7 +5,9 @@ "keywords": [ "dial", "button", - "knob" + "knob", + "ui", + "input" ], "version": "1.2.0", "author": { From 979795e50ed7f6e3f6a70dde6d0cdaf859b6e897 Mon Sep 17 00:00:00 2001 From: aterrien Date: Fri, 25 Jan 2013 16:29:40 +0100 Subject: [PATCH 14/74] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 29dcd24..4fc2ba4 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Example Options @@ -28,7 +28,7 @@ Options are provided as attributes 'data-option': $(".dial").knob({ 'min':-50 ,'max':50 - }) + }); The following options are supported : From bc89c87cca60a9128bce5f8b1def99f3530f8357 Mon Sep 17 00:00:00 2001 From: Anthony Terrien Date: Fri, 25 Jan 2013 19:37:17 +0100 Subject: [PATCH 15/74] Add download link --- knob.jquery.json | 1 + 1 file changed, 1 insertion(+) diff --git a/knob.jquery.json b/knob.jquery.json index b6c8e5b..40b2337 100644 --- a/knob.jquery.json +++ b/knob.jquery.json @@ -30,6 +30,7 @@ "bugs": "https://github.com/aterrien/jQuery-Knob/issues", "homepage": "https://github.com/aterrien/jQuery-Knob", "docs": "https://github.com/aterrien/jQuery-Knob", + "download": "https://github.com/aterrien/jQuery-Knob/tags", "dependencies": { "jquery": ">=1.7.0" } From bf70456ca13329158ad48c9e2049967b9133cdec Mon Sep 17 00:00:00 2001 From: root Date: Wed, 30 Jan 2013 00:07:10 +0100 Subject: [PATCH 16/74] Release 1.2.2 --- knob.jquery.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/knob.jquery.json b/knob.jquery.json index 40b2337..28f295d 100644 --- a/knob.jquery.json +++ b/knob.jquery.json @@ -9,7 +9,7 @@ "ui", "input" ], - "version": "1.2.0", + "version": "1.2.2", "author": { "name": "Anthony Terrien", "url": "https://github.com/aterrien" @@ -34,4 +34,4 @@ "dependencies": { "jquery": ">=1.7.0" } -} \ No newline at end of file +} From 9dea10469ac9e6e576bc866f11162187ac1e913d Mon Sep 17 00:00:00 2001 From: Anthony Terrien Date: Sat, 9 Feb 2013 19:19:25 +0100 Subject: [PATCH 17/74] use of $ passed to the ready() function / compat with noConflict --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 6123e93..9d61a9a 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ +
+

× Superpose (clock)

+
+
+ +
+
+ +
+
+ +
+
+
+

× Readonly


From 738eabcd49a3a66ad750833da5c0348137447c13 Mon Sep 17 00:00:00 2001
From: Philippe Masset 
Date: Tue, 9 Apr 2013 16:05:55 +0200
Subject: [PATCH 22/74] Prevent errors in browsers that don't support canvases.

Added feature detection to prevent the plugin from executing if the
browser doesn't support canvases.
Added the `error` hook, triggered if the browser doesn't support
canvases.
---
 js/jquery.knob.js | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/js/jquery.knob.js b/js/jquery.knob.js
index 32caa3d..ef3ab5f 100644
--- a/js/jquery.knob.js
+++ b/js/jquery.knob.js
@@ -106,7 +106,8 @@
                     draw : null, // function () {}
                     change : null, // function (value) {}
                     cancel : null, // function () {}
-                    release : null // function (value) {}
+                    release : null, // function (value) {}
+                    error : null // function () {}
                 }, this.o
             );
 
@@ -151,7 +152,13 @@
             this.$c = $('');
-            this.c = this.$c[0].getContext("2d");
+            
+            this.c = this.$c[0].getContext? this.$c[0].getContext('2d') : null;
+			
+            if (!this.c) {
+                this.o.error && this.o.error();
+                return;
+            }
 
             this.$
                 .wrap($('
Date: Thu, 27 Jun 2013 23:16:02 +0200 Subject: [PATCH 25/74] Support for HiDPI screens #99 #93 #61 --- js/jquery.knob.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/js/jquery.knob.js b/js/jquery.knob.js index ef3ab5f..ae36b6b 100644 --- a/js/jquery.knob.js +++ b/js/jquery.knob.js @@ -63,6 +63,7 @@ this.cH = null; // change hook this.eH = null; // cancel hook this.rH = null; // release hook + this.scale = 1; // scale factor this.run = function () { var cf = function (e, conf) { @@ -166,6 +167,21 @@ this.o.height + 'px;">
')) .before(this.$c); + this.scale = (window.devicePixelRatio || 1) / + ( + this.c.webkitBackingStorePixelRatio || + this.c.mozBackingStorePixelRatio || + this.c.msBackingStorePixelRatio || + this.c.oBackingStorePixelRatio || + this.c.backingStorePixelRatio || 1 + ); + if (this.scale !== 1) { + this.$c[0].width = this.$c[0].width * this.scale; + this.$c[0].height = this.$c[0].height * this.scale; + this.$c.width(this.o.width); + this.$c.height(this.o.height); + } + if (this.v instanceof Object) { this.cv = {}; this.copy(this.v, this.cv); @@ -196,8 +212,9 @@ var d = true, c = document.createElement('canvas'); - c.width = s.o.width; - c.height = s.o.height; + c.width = s.o.width * s.scale; + c.height = s.o.height * s.scale; + s.g = c.getContext('2d'); s.clear(); @@ -551,7 +568,7 @@ this.$.val(this.v); this.w2 = this.o.width / 2; this.cursorExt = this.o.cursor / 100; - this.xy = this.w2; + this.xy = this.w2 * this.scale; this.lineWidth = this.xy * this.o.thickness; this.lineCap = this.o.lineCap; this.radius = this.xy - this.lineWidth / 2; From bc468f9540e507e6ba557bc754e1355d9d7f4f9d Mon Sep 17 00:00:00 2001 From: fadomire Date: Tue, 27 Aug 2013 09:54:13 +0200 Subject: [PATCH 26/74] excanvas support for IE7/8 compatibility added excanvas support code from @buradleix https://github.com/buradleix/jQuery-Knob/ --- js/jquery.knob.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/js/jquery.knob.js b/js/jquery.knob.js index ae36b6b..a0b4729 100644 --- a/js/jquery.knob.js +++ b/js/jquery.knob.js @@ -150,10 +150,15 @@ (!this.o.displayInput) && this.$.hide(); - this.$c = $(''); + this.$c = $(document.createElement('canvas')).attr({ + width: this.o.width, + height: this.o.height + }); + if (typeof G_vmlCanvasManager !== 'undefined') { + G_vmlCanvasManager.initElement(this.$c[0]); + } + this.c = this.$c[0].getContext? this.$c[0].getContext('2d') : null; if (!this.c) { @@ -209,13 +214,9 @@ this._draw = function () { // canvas pre-rendering - var d = true, - c = document.createElement('canvas'); - - c.width = s.o.width * s.scale; - c.height = s.o.height * s.scale; + var d = true; - s.g = c.getContext('2d'); + s.g = s.c; s.clear(); @@ -224,8 +225,6 @@ (d !== false) && s.draw(); - s.c.drawImage(c, 0, 0); - c = null; }; this._touch = function (e) { @@ -682,4 +681,4 @@ ).parent(); }; -})(jQuery); \ No newline at end of file +})(jQuery); From 6dca8a7a79ade47c70835b06b2509ce688ecd3b9 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 2 Sep 2013 22:13:19 +0200 Subject: [PATCH 27/74] font and fontWeight support #100 @kylestetz @asnyder --- README.md | 0 index.html | 0 js/jquery.knob.js | 10 ++++++---- knob.jquery.json | 0 4 files changed, 6 insertions(+), 4 deletions(-) mode change 100644 => 100755 README.md mode change 100644 => 100755 index.html mode change 100644 => 100755 js/jquery.knob.js mode change 100644 => 100755 knob.jquery.json diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/index.html b/index.html old mode 100644 new mode 100755 diff --git a/js/jquery.knob.js b/js/jquery.knob.js old mode 100644 new mode 100755 index a0b4729..79b4f0e --- a/js/jquery.knob.js +++ b/js/jquery.knob.js @@ -48,7 +48,7 @@ this.o = null; // array of options this.$ = null; // jQuery wrapped element this.i = null; // mixed HTMLInputElement or array of HTMLInputElement - this.g = null; // 2D graphics context for 'pre-rendering' + this.g = null; // deprecated 2D graphics context for 'pre-rendering' this.v = null; // value ; mixed array or integer this.cv = null; // change value ; not commited value this.x = 0; // canvas x position @@ -100,6 +100,8 @@ displayPrevious : this.$.data('displayprevious'), fgColor : this.$.data('fgcolor') || '#87CEEB', inputColor: this.$.data('inputcolor') || this.$.data('fgcolor') || '#87CEEB', + font: this.$.data('font') || 'Arial', + fontWeight: this.$.data('font-weight') || 'bold', inline : false, step : this.$.data('step') || 1, @@ -154,13 +156,13 @@ width: this.o.width, height: this.o.height }); - + if (typeof G_vmlCanvasManager !== 'undefined') { G_vmlCanvasManager.initElement(this.$c[0]); } this.c = this.$c[0].getContext? this.$c[0].getContext('2d') : null; - + if (!this.c) { this.o.error && this.o.error(); return; @@ -602,7 +604,7 @@ ,'margin-left' : '-' + ((this.o.width * 3 / 4 + 2) >> 0) + 'px' ,'border' : 0 ,'background' : 'none' - ,'font' : 'bold ' + ((this.o.width / s) >> 0) + 'px Arial' + ,'font' : this.o.fontWeight + ' ' + ((this.o.width / s) >> 0) + 'px ' + this.o.font ,'text-align' : 'center' ,'color' : this.o.inputColor || this.o.fgColor ,'padding' : '0px' diff --git a/knob.jquery.json b/knob.jquery.json old mode 100644 new mode 100755 From ac5e0b8d478b2b17ed22e40849c4801b49db7e15 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 2 Sep 2013 22:18:03 +0200 Subject: [PATCH 28/74] font and fontWeight support #100 @kylestetz @asnyder --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2b33108..8c6dd33 100755 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ UI : * displayPrevious : default=false | true=displays the previous value with transparency. * fgColor : foreground color. * inputColor : input value (number) color. +* font : font family. +* fontWeight : font weight. * bgColor : background color. Hooks From e83f4fb9f92837caa6402eac72ccf5480fe0970a Mon Sep 17 00:00:00 2001 From: root Date: Fri, 13 Sep 2013 01:01:18 +0200 Subject: [PATCH 29/74] First implem of responsive support #98 --- index.html | 18 ++++++++ js/jquery.knob.js | 106 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 98 insertions(+), 26 deletions(-) diff --git a/index.html b/index.html index 67b1530..d003bb0 100755 --- a/index.html +++ b/index.html @@ -205,6 +205,24 @@

jQuery Knob

+
+

× Responsive

+
+data-width="80%"
+            
+
+ + Current div width is 30% of window width.
+ Knob width is 80% of current div.
+ Knob width is 80% of 30% of window width.
+ Test resizing window. +
+
+
+ +
+
+
+ + + - + + +``` Options ------- Options are provided as attributes 'data-option': - +```html + +``` ... or in the "knob()" call : - $(".dial").knob({ - 'min':-50 - ,'max':50 - }); +```javascript +$(".dial").knob({ + 'min':-50, + 'max':50 +}); +``` The following options are supported : @@ -58,11 +64,13 @@ UI : Hooks ------- - + 'release' : function (v) { /*make something*/ } + }); + +``` * 'release' : executed on release @@ -92,40 +100,44 @@ The scope (this) of each hook function is the current Knob instance (refer to th Example ------- - +```html + - - + 'change' : function (v) { console.log(v); } + }); + +``` Dynamically configure ------- - + } + ); + +``` Set the value ------- - + +``` Supported browser -------