jquery.knob.js 25 KB

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