jquery.knob.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. /*!jQuery Knob*/
  2. /**
  3. * Downward compatible, touchable dial
  4. *
  5. * Version: 1.2.8
  6. * Requires: jQuery v1.7+
  7. *
  8. * Copyright (c) 2012 Anthony Terrien
  9. * Under MIT License (http://www.opensource.org/licenses/mit-license.php)
  10. *
  11. * Thanks to vor, eskimoblood, spiffistan, FabrizioC
  12. */
  13. (function($) {
  14. /**
  15. * Kontrol library
  16. */
  17. "use strict";
  18. /**
  19. * Definition of globals and core
  20. */
  21. var k = {}, // kontrol
  22. max = Math.max,
  23. min = Math.min;
  24. k.c = {};
  25. k.c.d = $(document);
  26. k.c.t = function (e) {
  27. return e.originalEvent.touches.length - 1;
  28. };
  29. /**
  30. * Kontrol Object
  31. *
  32. * Definition of an abstract UI control
  33. *
  34. * Each concrete component must call this one.
  35. * <code>
  36. * k.o.call(this);
  37. * </code>
  38. */
  39. k.o = function () {
  40. var s = this;
  41. this.o = null; // array of options
  42. this.$ = null; // jQuery wrapped element
  43. this.i = null; // mixed HTMLInputElement or array of HTMLInputElement
  44. this.g = null; // deprecated 2D graphics context for 'pre-rendering'
  45. this.v = null; // value ; mixed array or integer
  46. this.cv = null; // change value ; not commited value
  47. this.x = 0; // canvas x position
  48. this.y = 0; // canvas y position
  49. this.w = 0; // canvas width
  50. this.h = 0; // canvas height
  51. this.$c = null; // jQuery canvas element
  52. this.c = null; // rendered canvas context
  53. this.t = 0; // touches index
  54. this.isInit = false;
  55. this.fgColor = null; // main color
  56. this.pColor = null; // previous color
  57. this.dH = null; // draw hook
  58. this.cH = null; // change hook
  59. this.eH = null; // cancel hook
  60. this.rH = null; // release hook
  61. this.scale = 1; // scale factor
  62. this.relative = false;
  63. this.relativeWidth = false;
  64. this.relativeHeight = false;
  65. this.$div = null; // component div
  66. this.run = function () {
  67. var cf = function (e, conf) {
  68. var k;
  69. for (k in conf) {
  70. s.o[k] = conf[k];
  71. }
  72. s._carve().init();
  73. s._configure()
  74. ._draw();
  75. };
  76. if(this.$.data('kontroled')) return;
  77. this.$.data('kontroled', true);
  78. this.extend();
  79. this.o = $.extend(
  80. {
  81. // Config
  82. min : this.$.data('min') !== undefined ? this.$.data('min') : 0,
  83. max : this.$.data('max') !== undefined ? this.$.data('max') : 100,
  84. stopper : true,
  85. readOnly : this.$.data('readonly') || (this.$.attr('readonly') === 'readonly'),
  86. // UI
  87. cursor : (this.$.data('cursor') === true && 30) ||
  88. this.$.data('cursor') || 0,
  89. thickness : (
  90. this.$.data('thickness') &&
  91. Math.max(Math.min(this.$.data('thickness'), 1), 0.01)
  92. ) || 0.35,
  93. lineCap : this.$.data('linecap') || 'butt',
  94. width : this.$.data('width') || 200,
  95. height : this.$.data('height') || 200,
  96. displayInput : this.$.data('displayinput') == null || this.$.data('displayinput'),
  97. displayPrevious : this.$.data('displayprevious'),
  98. fgColor : this.$.data('fgcolor') || '#87CEEB',
  99. inputColor: this.$.data('inputcolor'),
  100. font: this.$.data('font') || 'Arial',
  101. fontWeight: this.$.data('font-weight') || 'bold',
  102. inline : false,
  103. step : this.$.data('step') || 1,
  104. rotation: this.$.data('rotation'),
  105. // Hooks
  106. draw : null, // function () {}
  107. change : null, // function (value) {}
  108. cancel : null, // function () {}
  109. release : null, // function (value) {}
  110. // Output formatting, allows to add unit: %, ms ...
  111. format: function(v) {
  112. return v;
  113. },
  114. parse: function (v) {
  115. return parseFloat(v);
  116. }
  117. }, this.o
  118. );
  119. // finalize options
  120. this.o.flip = this.o.rotation === 'anticlockwise' || this.o.rotation === 'acw';
  121. if(!this.o.inputColor) {
  122. this.o.inputColor = this.o.fgColor;
  123. }
  124. // routing value
  125. if(this.$.is('fieldset')) {
  126. // fieldset = array of integer
  127. this.v = {};
  128. this.i = this.$.find('input');
  129. this.i.each(function(k) {
  130. var $this = $(this);
  131. s.i[k] = $this;
  132. s.v[k] = s.o.parse($this.val());
  133. $this.bind(
  134. 'change blur'
  135. , function () {
  136. var val = {};
  137. val[k] = $this.val();
  138. s.val(val);
  139. }
  140. );
  141. });
  142. this.$.find('legend').remove();
  143. } else {
  144. // input = integer
  145. this.i = this.$;
  146. this.v = this.o.parse(this.$.val());
  147. (this.v === '') && (this.v = this.o.min);
  148. this.$.bind(
  149. 'change blur'
  150. , function () {
  151. s.val(s._validate(s.o.parse(s.$.val())));
  152. }
  153. );
  154. }
  155. (!this.o.displayInput) && this.$.hide();
  156. // adds needed DOM elements (canvas, div)
  157. this.$c = $(document.createElement('canvas')).attr({
  158. width: this.o.width,
  159. height: this.o.height
  160. });
  161. // wraps all elements in a div
  162. // add to DOM before Canvas init is triggered
  163. this.$div = $('<div style="'
  164. + (this.o.inline ? 'display:inline;' : '')
  165. + 'width:' + this.o.width + 'px;height:' + this.o.height + 'px;'
  166. + '"></div>');
  167. this.$.wrap(this.$div).before(this.$c);
  168. this.$div = this.$.parent();
  169. if (typeof G_vmlCanvasManager !== 'undefined') {
  170. G_vmlCanvasManager.initElement(this.$c[0]);
  171. }
  172. this.c = this.$c[0].getContext ? this.$c[0].getContext('2d') : null;
  173. if (!this.c) {
  174. throw {
  175. name: "CanvasNotSupportedException",
  176. message: "Canvas not supported. Please use excanvas on IE8.0.",
  177. toString: function(){return this.name + ": " + this.message}
  178. }
  179. }
  180. // hdpi support
  181. this.scale = (window.devicePixelRatio || 1) /
  182. (
  183. this.c.webkitBackingStorePixelRatio ||
  184. this.c.mozBackingStorePixelRatio ||
  185. this.c.msBackingStorePixelRatio ||
  186. this.c.oBackingStorePixelRatio ||
  187. this.c.backingStorePixelRatio || 1
  188. );
  189. // detects relative width / height
  190. this.relativeWidth = ((this.o.width % 1 !== 0) &&
  191. this.o.width.indexOf('%'));
  192. this.relativeHeight = ((this.o.height % 1 !== 0) &&
  193. this.o.height.indexOf('%'));
  194. this.relative = (this.relativeWidth || this.relativeHeight);
  195. // computes size and carves the component
  196. this._carve();
  197. // prepares props for transaction
  198. if (this.v instanceof Object) {
  199. this.cv = {};
  200. this.copy(this.v, this.cv);
  201. } else {
  202. this.cv = this.v;
  203. }
  204. // binds configure event
  205. this.$
  206. .bind("configure", cf)
  207. .parent()
  208. .bind("configure", cf);
  209. // finalize init
  210. this._listen()
  211. ._configure()
  212. ._xy()
  213. .init();
  214. this.isInit = true;
  215. this.$.val(this.o.format(this.v));
  216. this._draw();
  217. return this;
  218. };
  219. this._carve = function() {
  220. if(this.relative) {
  221. var w = this.relativeWidth ?
  222. this.$div.parent().width() *
  223. parseInt(this.o.width) / 100 :
  224. this.$div.parent().width(),
  225. h = this.relativeHeight ?
  226. this.$div.parent().height() *
  227. parseInt(this.o.height) / 100 :
  228. this.$div.parent().height();
  229. // apply relative
  230. this.w = this.h = Math.min(w, h);
  231. } else {
  232. this.w = this.o.width;
  233. this.h = this.o.height;
  234. }
  235. // finalize div
  236. this.$div.css({
  237. 'width': this.w + 'px',
  238. 'height': this.h + 'px'
  239. });
  240. // finalize canvas with computed width
  241. this.$c.attr({
  242. width: this.w,
  243. height: this.h
  244. });
  245. // scaling
  246. if (this.scale !== 1) {
  247. this.$c[0].width = this.$c[0].width * this.scale;
  248. this.$c[0].height = this.$c[0].height * this.scale;
  249. this.$c.width(this.w);
  250. this.$c.height(this.h);
  251. }
  252. return this;
  253. }
  254. this._draw = function () {
  255. // canvas pre-rendering
  256. var d = true;
  257. s.g = s.c;
  258. s.clear();
  259. s.dH
  260. && (d = s.dH());
  261. (d !== false) && s.draw();
  262. };
  263. this._touch = function (e) {
  264. var touchMove = function (e) {
  265. var v = s.xy2val(
  266. e.originalEvent.touches[s.t].pageX,
  267. e.originalEvent.touches[s.t].pageY
  268. );
  269. if (v == s.cv) return;
  270. if (s.cH && (s.cH(v) === false)) return;
  271. s.change(s._validate(v));
  272. s._draw();
  273. };
  274. // get touches index
  275. this.t = k.c.t(e);
  276. // First touch
  277. touchMove(e);
  278. // Touch events listeners
  279. k.c.d
  280. .bind("touchmove.k", touchMove)
  281. .bind(
  282. "touchend.k"
  283. , function () {
  284. k.c.d.unbind('touchmove.k touchend.k');
  285. s.val(s.cv);
  286. }
  287. );
  288. return this;
  289. };
  290. this._mouse = function (e) {
  291. var mouseMove = function (e) {
  292. var v = s.xy2val(e.pageX, e.pageY);
  293. if (v == s.cv) return;
  294. if (s.cH && (s.cH(v) === false)) return;
  295. s.change(s._validate(v));
  296. s._draw();
  297. };
  298. // First click
  299. mouseMove(e);
  300. // Mouse events listeners
  301. k.c.d
  302. .bind("mousemove.k", mouseMove)
  303. .bind(
  304. // Escape key cancel current change
  305. "keyup.k"
  306. , function (e) {
  307. if (e.keyCode === 27) {
  308. k.c.d.unbind("mouseup.k mousemove.k keyup.k");
  309. if (
  310. s.eH
  311. && (s.eH() === false)
  312. ) return;
  313. s.cancel();
  314. }
  315. }
  316. )
  317. .bind(
  318. "mouseup.k"
  319. , function (e) {
  320. k.c.d.unbind('mousemove.k mouseup.k keyup.k');
  321. s.val(s.cv);
  322. }
  323. );
  324. return this;
  325. };
  326. this._xy = function () {
  327. var o = this.$c.offset();
  328. this.x = o.left;
  329. this.y = o.top;
  330. return this;
  331. };
  332. this._listen = function () {
  333. if (!this.o.readOnly) {
  334. this.$c
  335. .bind(
  336. "mousedown"
  337. , function (e) {
  338. e.preventDefault();
  339. s._xy()._mouse(e);
  340. }
  341. )
  342. .bind(
  343. "touchstart"
  344. , function (e) {
  345. e.preventDefault();
  346. s._xy()._touch(e);
  347. }
  348. );
  349. this.listen();
  350. } else {
  351. this.$.attr('readonly', 'readonly');
  352. }
  353. if(this.relative) {
  354. $(window).resize(function() {
  355. s._carve()
  356. .init();
  357. s._draw();
  358. });
  359. }
  360. return this;
  361. };
  362. this._configure = function () {
  363. // Hooks
  364. if (this.o.draw) this.dH = this.o.draw;
  365. if (this.o.change) this.cH = this.o.change;
  366. if (this.o.cancel) this.eH = this.o.cancel;
  367. if (this.o.release) this.rH = this.o.release;
  368. if (this.o.displayPrevious) {
  369. this.pColor = this.h2rgba(this.o.fgColor, "0.4");
  370. this.fgColor = this.h2rgba(this.o.fgColor, "0.6");
  371. } else {
  372. this.fgColor = this.o.fgColor;
  373. }
  374. return this;
  375. };
  376. this._clear = function () {
  377. this.$c[0].width = this.$c[0].width;
  378. };
  379. this._validate = function(v) {
  380. return (~~ (((v < 0) ? -0.5 : 0.5) + (v/this.o.step))) * this.o.step;
  381. };
  382. // Abstract methods
  383. this.listen = function () {}; // on start, one time
  384. this.extend = function () {}; // each time configure triggered
  385. this.init = function () {}; // each time configure triggered
  386. this.change = function (v) {}; // on change
  387. this.val = function (v) {}; // on release
  388. this.xy2val = function (x, y) {}; //
  389. this.draw = function () {}; // on change / on release
  390. this.clear = function () { this._clear(); };
  391. // Utils
  392. this.h2rgba = function (h, a) {
  393. var rgb;
  394. h = h.substring(1,7)
  395. rgb = [parseInt(h.substring(0,2),16)
  396. ,parseInt(h.substring(2,4),16)
  397. ,parseInt(h.substring(4,6),16)];
  398. return "rgba(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + a + ")";
  399. };
  400. this.copy = function (f, t) {
  401. for (var i in f) { t[i] = f[i]; }
  402. };
  403. };
  404. /**
  405. * k.Dial
  406. */
  407. k.Dial = function () {
  408. k.o.call(this);
  409. this.startAngle = null;
  410. this.xy = null;
  411. this.radius = null;
  412. this.lineWidth = null;
  413. this.cursorExt = null;
  414. this.w2 = null;
  415. this.PI2 = 2*Math.PI;
  416. this.extend = function () {
  417. this.o = $.extend(
  418. {
  419. bgColor : this.$.data('bgcolor') || '#EEEEEE',
  420. angleOffset : this.$.data('angleoffset') || 0,
  421. angleArc : this.$.data('anglearc') || 360,
  422. inline : true
  423. }, this.o
  424. );
  425. };
  426. this.val = function (v, triggerRelease) {
  427. if (null != v) {
  428. // reverse format
  429. v = this.o.parse(v);
  430. if (
  431. triggerRelease !== false && (v != this.v) && this.rH &&
  432. (this.rH(v) === false)
  433. ) return;
  434. this.cv = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
  435. this.v = this.cv;
  436. this.$.val(this.o.format(this.v));
  437. this._draw();
  438. } else {
  439. return this.v;
  440. }
  441. };
  442. this.xy2val = function (x, y) {
  443. var a, ret;
  444. a = Math.atan2(
  445. x - (this.x + this.w2)
  446. , - (y - this.y - this.w2)
  447. ) - this.angleOffset;
  448. if (this.o.flip) {
  449. a = this.angleArc - a - this.PI2;
  450. }
  451. if(this.angleArc != this.PI2 && (a < 0) && (a > -0.5)) {
  452. // if isset angleArc option, set to min if .5 under min
  453. a = 0;
  454. } else if (a < 0) {
  455. a += this.PI2;
  456. }
  457. ret = ~~ (0.5 + (a * (this.o.max - this.o.min) / this.angleArc))
  458. + this.o.min;
  459. this.o.stopper && (ret = max(min(ret, this.o.max), this.o.min));
  460. return ret;
  461. };
  462. this.listen = function () {
  463. // bind MouseWheel
  464. var s = this, mwTimerStop, mwTimerRelease,
  465. mw = function (e) {
  466. e.preventDefault();
  467. var ori = e.originalEvent
  468. ,deltaX = ori.detail || ori.wheelDeltaX
  469. ,deltaY = ori.detail || ori.wheelDeltaY
  470. ,v = s._validate(s.o.parse(s.$.val()))
  471. + (deltaX>0 || deltaY>0 ? s.o.step : deltaX<0 || deltaY<0 ? -s.o.step : 0);
  472. v = max(min(v, s.o.max), s.o.min);
  473. s.val(v, false);
  474. if(s.rH) {
  475. // Handle mousewheel stop
  476. clearTimeout(mwTimerStop);
  477. mwTimerStop = setTimeout(function() {
  478. s.rH(v);
  479. mwTimerStop = null;
  480. }, 100);
  481. // Handle mousewheel releases
  482. if(!mwTimerRelease) {
  483. mwTimerRelease = setTimeout(function() {
  484. if(mwTimerStop) s.rH(v);
  485. mwTimerRelease = null;
  486. }, 200);
  487. }
  488. }
  489. }
  490. , kval, to, m = 1, kv = {37:-s.o.step, 38:s.o.step, 39:s.o.step, 40:-s.o.step};
  491. this.$
  492. .bind(
  493. "keydown"
  494. ,function (e) {
  495. var kc = e.keyCode;
  496. // numpad support
  497. if(kc >= 96 && kc <= 105) {
  498. kc = e.keyCode = kc - 48;
  499. }
  500. kval = parseInt(String.fromCharCode(kc));
  501. if (isNaN(kval)) {
  502. (kc !== 13) // enter
  503. && (kc !== 8) // bs
  504. && (kc !== 9) // tab
  505. && (kc !== 189) // -
  506. && (kc !== 190 || s.$.val().match(/\./)) // . only allowed once
  507. && e.preventDefault();
  508. // arrows
  509. if ($.inArray(kc,[37,38,39,40]) > -1) {
  510. e.preventDefault();
  511. var v = s.o.parse(s.$.val()) + kv[kc] * m;
  512. s.o.stopper && (v = max(min(v, s.o.max), s.o.min));
  513. s.change(v);
  514. s._draw();
  515. // long time keydown speed-up
  516. to = window.setTimeout(
  517. function () { m *= 2; }, 30
  518. );
  519. }
  520. }
  521. }
  522. )
  523. .bind(
  524. "keyup"
  525. ,function (e) {
  526. if (isNaN(kval)) {
  527. if (to) {
  528. window.clearTimeout(to);
  529. to = null;
  530. m = 1;
  531. s.val(s.$.val());
  532. }
  533. } else {
  534. // kval postcond
  535. (s.$.val() > s.o.max && s.$.val(s.o.max))
  536. || (s.$.val() < s.o.min && s.$.val(s.o.min));
  537. }
  538. }
  539. );
  540. this.$c.bind("mousewheel DOMMouseScroll", mw);
  541. this.$.bind("mousewheel DOMMouseScroll", mw)
  542. };
  543. this.init = function () {
  544. if (
  545. this.v < this.o.min
  546. || this.v > this.o.max
  547. ) this.v = this.o.min;
  548. this.$.val(this.v);
  549. this.w2 = this.w / 2;
  550. this.cursorExt = this.o.cursor / 100;
  551. this.xy = this.w2 * this.scale;
  552. this.lineWidth = this.xy * this.o.thickness;
  553. this.lineCap = this.o.lineCap;
  554. this.radius = this.xy - this.lineWidth / 2;
  555. this.o.angleOffset
  556. && (this.o.angleOffset = isNaN(this.o.angleOffset) ? 0 : this.o.angleOffset);
  557. this.o.angleArc
  558. && (this.o.angleArc = isNaN(this.o.angleArc) ? this.PI2 : this.o.angleArc);
  559. // deg to rad
  560. this.angleOffset = this.o.angleOffset * Math.PI / 180;
  561. this.angleArc = this.o.angleArc * Math.PI / 180;
  562. // compute start and end angles
  563. this.startAngle = 1.5 * Math.PI + this.angleOffset;
  564. this.endAngle = 1.5 * Math.PI + this.angleOffset + this.angleArc;
  565. var s = max(
  566. String(Math.abs(this.o.max)).length
  567. , String(Math.abs(this.o.min)).length
  568. , 2
  569. ) + 2;
  570. this.o.displayInput
  571. && this.i.css({
  572. 'width' : ((this.w / 2 + 4) >> 0) + 'px'
  573. ,'height' : ((this.w / 3) >> 0) + 'px'
  574. ,'position' : 'absolute'
  575. ,'vertical-align' : 'middle'
  576. ,'margin-top' : ((this.w / 3) >> 0) + 'px'
  577. ,'margin-left' : '-' + ((this.w * 3 / 4 + 2) >> 0) + 'px'
  578. ,'border' : 0
  579. ,'background' : 'none'
  580. ,'font' : this.o.fontWeight + ' ' + ((this.w / s) >> 0) + 'px ' + this.o.font
  581. ,'text-align' : 'center'
  582. ,'color' : this.o.inputColor || this.o.fgColor
  583. ,'padding' : '0px'
  584. ,'-webkit-appearance': 'none'
  585. })
  586. || this.i.css({
  587. 'width' : '0px'
  588. ,'visibility' : 'hidden'
  589. });
  590. };
  591. this.change = function (v) {
  592. this.cv = v;
  593. this.$.val(this.o.format(v));
  594. };
  595. this.angle = function (v) {
  596. return (v - this.o.min) * this.angleArc / (this.o.max - this.o.min);
  597. };
  598. this.arc = function (v) {
  599. var sa, ea;
  600. v = this.angle(v);
  601. if (this.o.flip) {
  602. sa = this.endAngle + 0.00001;
  603. ea = sa - v - 0.00001;
  604. } else {
  605. sa = this.startAngle - 0.00001;
  606. ea = sa + v + 0.00001;
  607. }
  608. this.o.cursor
  609. && (sa = ea - this.cursorExt)
  610. && (ea = ea + this.cursorExt);
  611. return {
  612. s: sa,
  613. e: ea,
  614. d: this.o.flip && !this.o.cursor
  615. };
  616. };
  617. this.draw = function () {
  618. var c = this.g, // context
  619. a = this.arc(this.cv) // Arc
  620. , pa // Previous arc
  621. , r = 1;
  622. c.lineWidth = this.lineWidth;
  623. c.lineCap = this.lineCap;
  624. c.beginPath();
  625. c.strokeStyle = this.o.bgColor;
  626. c.arc(this.xy, this.xy, this.radius, this.endAngle - 0.00001, this.startAngle + 0.00001, true);
  627. c.stroke();
  628. if (this.o.displayPrevious) {
  629. pa = this.arc(this.v);
  630. c.beginPath();
  631. c.strokeStyle = this.pColor;
  632. c.arc(this.xy, this.xy, this.radius, pa.s, pa.e, pa.d);
  633. c.stroke();
  634. r = (this.cv == this.v);
  635. }
  636. c.beginPath();
  637. c.strokeStyle = r ? this.o.fgColor : this.fgColor ;
  638. c.arc(this.xy, this.xy, this.radius, a.s, a.e, a.d);
  639. c.stroke();
  640. };
  641. this.cancel = function () {
  642. this.val(this.v);
  643. };
  644. };
  645. $.fn.dial = $.fn.knob = function (o) {
  646. return this.each(
  647. function () {
  648. var d = new k.Dial();
  649. d.o = o;
  650. d.$ = $(this);
  651. d.run();
  652. }
  653. ).parent();
  654. };
  655. })(jQuery);