hierapolis-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 472dc4c8ddfc9b1eaa7af1169178d0dff339b7c4
4
+ data.tar.gz: 98f8c9db7311a0af6b52e99904f94e59e8ec0b37
5
+ SHA512:
6
+ metadata.gz: 7773ae9c593cac25e1d88d6dc32e70014bc163e708b0818ed1ff0830aa39e4d4bb738a859a0b8420b59db50e269515efa62b1f3fc4925d9759f42266d3c4be3d
7
+ data.tar.gz: d429d3eb9b63f143983e6ad2c50b517bec1aa0fffaa46afdc28eab891e7256ea21dd7e3ebd6808805e9533fa9b1d36d9458ef1038d44029099f5f3cb4faa2ae9
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/
@@ -0,0 +1,7 @@
1
+
2
+ #### [Current]
3
+
4
+ ####
5
+ * [e414ca9](../../commit/e414ca9) - __(Muhammet DILEK)__ readme updated
6
+ * [a81fcfc](../../commit/a81fcfc) - __(Muhammet DILEK)__ [#1](../../issues/1) Project created and assets added
7
+ * [89a5581](../../commit/89a5581) - __(Muhammet DILEK)__ Initial commit
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Muhammet DİLEK
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # Hierapolis::Rails
2
+
3
+ This gem using to  integrate [hierapolis](https://github.com/kebab-project/hierapolis) theme  on rails project.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hierapolis-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hierapolis-rails
18
+
19
+ ## Usage
20
+
21
+ Add these lines to application.css
22
+
23
+ ```ruby
24
+ @import 'bootstrap'
25
+ @import "hierapolis"
26
+ ```
27
+
28
+ Add these lines to application.js
29
+ ```ruby
30
+ #= require bootstrap
31
+ #= require hierapolis
32
+ ```
33
+
34
+
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hierapolis/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hierapolis-rails"
8
+ spec.version = Hierapolis::Rails::VERSION
9
+ spec.authors = ["Muhammet DİLEK"]
10
+ spec.email = ["muhammet.dilek@lab2023.com"]
11
+ spec.description = %q{This gem using to  integrate hierapolis theme  on rails project.}
12
+ spec.summary = %q{this gem using to  integrate hierapolis theme  on rails project.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,8 @@
1
+ require "hierapolis/rails/version"
2
+
3
+ module Hierapolis
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Hierapolis
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ #= require_tree
2
+
3
+ $(document).ready ->
4
+
5
+ # Enable Tips & Popovers
6
+ $('[data-toggle=tooltip]').tooltip()
7
+ $('[data-toggle=popover]').popover()
8
+
9
+ # Eable Dropdowns
10
+ $('.dropdown-toggle').dropdown()
11
+ $('.dropdown.hover').hover (->
12
+ $(this).find('.dropdown-menu').stop(true, true).fadeIn()
13
+ ), ->
14
+ $(this).find('.dropdown-menu').stop(true, true).delay(100).fadeOut()
15
+
16
+
17
+ $('#toggle').click ->
18
+ $('#dock .launcher a').toggle()
19
+ $('#dock li.launcher').each ->
20
+ $(this).find('.dropdown-menu').css 'top', $(this).position().top + 33
21
+
22
+ # Enable toolbar tooltips
23
+ $('[data-toggle=toolbar-tooltip]').tooltip
24
+ placement: 'bottom'
25
+
26
+ # Enable knob inputs
27
+ $('.knob').knob()
@@ -0,0 +1,8 @@
1
+ /*
2
+ HTML5 Shiv v3.6.2 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
3
+ */
4
+ (function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag();
5
+ a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x<style>article,aside,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}</style>";
6
+ c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="<xyz></xyz>";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode||
7
+ "undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup main mark meter nav output progress section summary time video",version:"3.6.2",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)return a.createDocumentFragment();
8
+ for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d<h;d++)c.createElement(e[d]);return c}};l.html5=e;q(f)})(this,document);
@@ -0,0 +1,685 @@
1
+ /*!jQuery Knob*/
2
+ /**
3
+ * Downward compatible, touchable dial
4
+ *
5
+ * Version: 1.2.0 (15/07/2012)
6
+ * Requires: jQuery v1.7+
7
+ *
8
+ * Copyright (c) 2012 Anthony Terrien
9
+ * Under MIT and GPL licenses:
10
+ * http://www.opensource.org/licenses/mit-license.php
11
+ * http://www.gnu.org/licenses/gpl.html
12
+ *
13
+ * Thanks to vor, eskimoblood, spiffistan, FabrizioC
14
+ */
15
+ (function($) {
16
+
17
+ /**
18
+ * Kontrol library
19
+ */
20
+ "use strict";
21
+
22
+ /**
23
+ * Definition of globals and core
24
+ */
25
+ var k = {}, // kontrol
26
+ max = Math.max,
27
+ min = Math.min;
28
+
29
+ k.c = {};
30
+ k.c.d = $(document);
31
+ k.c.t = function (e) {
32
+ return e.originalEvent.touches.length - 1;
33
+ };
34
+
35
+ /**
36
+ * Kontrol Object
37
+ *
38
+ * Definition of an abstract UI control
39
+ *
40
+ * Each concrete component must call this one.
41
+ * <code>
42
+ * k.o.call(this);
43
+ * </code>
44
+ */
45
+ k.o = function () {
46
+ var s = this;
47
+
48
+ this.o = null; // array of options
49
+ this.$ = null; // jQuery wrapped element
50
+ this.i = null; // mixed HTMLInputElement or array of HTMLInputElement
51
+ this.g = null; // 2D graphics context for 'pre-rendering'
52
+ this.v = null; // value ; mixed array or integer
53
+ this.cv = null; // change value ; not commited value
54
+ this.x = 0; // canvas x position
55
+ this.y = 0; // canvas y position
56
+ this.$c = null; // jQuery canvas element
57
+ this.c = null; // rendered canvas context
58
+ this.t = 0; // touches index
59
+ this.isInit = false;
60
+ this.fgColor = null; // main color
61
+ this.pColor = null; // previous color
62
+ this.dH = null; // draw hook
63
+ this.cH = null; // change hook
64
+ this.eH = null; // cancel hook
65
+ this.rH = null; // release hook
66
+ this.scale = 1; // scale factor
67
+
68
+ this.run = function () {
69
+ var cf = function (e, conf) {
70
+ var k;
71
+ for (k in conf) {
72
+ s.o[k] = conf[k];
73
+ }
74
+ s.init();
75
+ s._configure()
76
+ ._draw();
77
+ };
78
+
79
+ if(this.$.data('kontroled')) return;
80
+ this.$.data('kontroled', true);
81
+
82
+ this.extend();
83
+ this.o = $.extend(
84
+ {
85
+ // Config
86
+ min : this.$.data('min') || 0,
87
+ max : this.$.data('max') || 100,
88
+ stopper : true,
89
+ readOnly : this.$.data('readonly'),
90
+
91
+ // UI
92
+ cursor : (this.$.data('cursor') === true && 30)
93
+ || this.$.data('cursor')
94
+ || 0,
95
+ thickness : this.$.data('thickness') || 0.35,
96
+ lineCap : this.$.data('linecap') || 'butt',
97
+ width : this.$.data('width') || 200,
98
+ height : this.$.data('height') || 200,
99
+ displayInput : this.$.data('displayinput') == null || this.$.data('displayinput'),
100
+ displayPrevious : this.$.data('displayprevious'),
101
+ fgColor : this.$.data('fgcolor') || '#87CEEB',
102
+ inputColor: this.$.data('inputcolor') || this.$.data('fgcolor') || '#87CEEB',
103
+ inline : false,
104
+ step : this.$.data('step') || 1,
105
+
106
+ // Hooks
107
+ draw : null, // function () {}
108
+ change : null, // function (value) {}
109
+ cancel : null, // function () {}
110
+ release : null, // function (value) {}
111
+ error : null // function () {}
112
+ }, this.o
113
+ );
114
+
115
+ // routing value
116
+ if(this.$.is('fieldset')) {
117
+
118
+ // fieldset = array of integer
119
+ this.v = {};
120
+ this.i = this.$.find('input')
121
+ this.i.each(function(k) {
122
+ var $this = $(this);
123
+ s.i[k] = $this;
124
+ s.v[k] = $this.val();
125
+
126
+ $this.bind(
127
+ 'change'
128
+ , function () {
129
+ var val = {};
130
+ val[k] = $this.val();
131
+ s.val(val);
132
+ }
133
+ );
134
+ });
135
+ this.$.find('legend').remove();
136
+
137
+ } else {
138
+ // input = integer
139
+ this.i = this.$;
140
+ this.v = this.$.val();
141
+ (this.v == '') && (this.v = this.o.min);
142
+
143
+ this.$.bind(
144
+ 'change'
145
+ , function () {
146
+ s.val(s._validate(s.$.val()));
147
+ }
148
+ );
149
+ }
150
+
151
+ (!this.o.displayInput) && this.$.hide();
152
+
153
+ this.$c = $('<canvas width="' +
154
+ this.o.width + 'px" height="' +
155
+ this.o.height + 'px"></canvas>');
156
+
157
+ this.c = this.$c[0].getContext? this.$c[0].getContext('2d') : null;
158
+
159
+ if (!this.c) {
160
+ this.o.error && this.o.error();
161
+ return;
162
+ }
163
+
164
+ this.$
165
+ .wrap($('<div style="' + (this.o.inline ? 'display:inline;' : '') +
166
+ 'width:' + this.o.width + 'px;height:' +
167
+ this.o.height + 'px;"></div>'))
168
+ .before(this.$c);
169
+
170
+ this.scale = (window.devicePixelRatio || 1) /
171
+ (
172
+ this.c.webkitBackingStorePixelRatio ||
173
+ this.c.mozBackingStorePixelRatio ||
174
+ this.c.msBackingStorePixelRatio ||
175
+ this.c.oBackingStorePixelRatio ||
176
+ this.c.backingStorePixelRatio || 1
177
+ );
178
+ if (this.scale !== 1) {
179
+ this.$c[0].width = this.$c[0].width * this.scale;
180
+ this.$c[0].height = this.$c[0].height * this.scale;
181
+ this.$c.width(this.o.width);
182
+ this.$c.height(this.o.height);
183
+ }
184
+
185
+ if (this.v instanceof Object) {
186
+ this.cv = {};
187
+ this.copy(this.v, this.cv);
188
+ } else {
189
+ this.cv = this.v;
190
+ }
191
+
192
+ this.$
193
+ .bind("configure", cf)
194
+ .parent()
195
+ .bind("configure", cf);
196
+
197
+ this._listen()
198
+ ._configure()
199
+ ._xy()
200
+ .init();
201
+
202
+ this.isInit = true;
203
+
204
+ this._draw();
205
+
206
+ return this;
207
+ };
208
+
209
+ this._draw = function () {
210
+
211
+ // canvas pre-rendering
212
+ var d = true,
213
+ c = document.createElement('canvas');
214
+
215
+ c.width = s.o.width * s.scale;
216
+ c.height = s.o.height * s.scale;
217
+
218
+ s.g = c.getContext('2d');
219
+
220
+ s.clear();
221
+
222
+ s.dH
223
+ && (d = s.dH());
224
+
225
+ (d !== false) && s.draw();
226
+
227
+ s.c.drawImage(c, 0, 0);
228
+ c = null;
229
+ };
230
+
231
+ this._touch = function (e) {
232
+
233
+ var touchMove = function (e) {
234
+
235
+ var v = s.xy2val(
236
+ e.originalEvent.touches[s.t].pageX,
237
+ e.originalEvent.touches[s.t].pageY
238
+ );
239
+
240
+ if (v == s.cv) return;
241
+
242
+ if (
243
+ s.cH
244
+ && (s.cH(v) === false)
245
+ ) return;
246
+
247
+
248
+ s.change(s._validate(v));
249
+ s._draw();
250
+ };
251
+
252
+ // get touches index
253
+ this.t = k.c.t(e);
254
+
255
+ // First touch
256
+ touchMove(e);
257
+
258
+ // Touch events listeners
259
+ k.c.d
260
+ .bind("touchmove.k", touchMove)
261
+ .bind(
262
+ "touchend.k"
263
+ , function () {
264
+ k.c.d.unbind('touchmove.k touchend.k');
265
+
266
+ if (
267
+ s.rH
268
+ && (s.rH(s.cv) === false)
269
+ ) return;
270
+
271
+ s.val(s.cv);
272
+ }
273
+ );
274
+
275
+ return this;
276
+ };
277
+
278
+ this._mouse = function (e) {
279
+
280
+ var mouseMove = function (e) {
281
+ var v = s.xy2val(e.pageX, e.pageY);
282
+ if (v == s.cv) return;
283
+
284
+ if (
285
+ s.cH
286
+ && (s.cH(v) === false)
287
+ ) return;
288
+
289
+ s.change(s._validate(v));
290
+ s._draw();
291
+ };
292
+
293
+ // First click
294
+ mouseMove(e);
295
+
296
+ // Mouse events listeners
297
+ k.c.d
298
+ .bind("mousemove.k", mouseMove)
299
+ .bind(
300
+ // Escape key cancel current change
301
+ "keyup.k"
302
+ , function (e) {
303
+ if (e.keyCode === 27) {
304
+ k.c.d.unbind("mouseup.k mousemove.k keyup.k");
305
+
306
+ if (
307
+ s.eH
308
+ && (s.eH() === false)
309
+ ) return;
310
+
311
+ s.cancel();
312
+ }
313
+ }
314
+ )
315
+ .bind(
316
+ "mouseup.k"
317
+ , function (e) {
318
+ k.c.d.unbind('mousemove.k mouseup.k keyup.k');
319
+
320
+ if (
321
+ s.rH
322
+ && (s.rH(s.cv) === false)
323
+ ) return;
324
+
325
+ s.val(s.cv);
326
+ }
327
+ );
328
+
329
+ return this;
330
+ };
331
+
332
+ this._xy = function () {
333
+ var o = this.$c.offset();
334
+ this.x = o.left;
335
+ this.y = o.top;
336
+ return this;
337
+ };
338
+
339
+ this._listen = function () {
340
+
341
+ if (!this.o.readOnly) {
342
+ this.$c
343
+ .bind(
344
+ "mousedown"
345
+ , function (e) {
346
+ e.preventDefault();
347
+ s._xy()._mouse(e);
348
+ }
349
+ )
350
+ .bind(
351
+ "touchstart"
352
+ , function (e) {
353
+ e.preventDefault();
354
+ s._xy()._touch(e);
355
+ }
356
+ );
357
+ this.listen();
358
+ } else {
359
+ this.$.attr('readonly', 'readonly');
360
+ }
361
+
362
+ return this;
363
+ };
364
+
365
+ this._configure = function () {
366
+
367
+ // Hooks
368
+ if (this.o.draw) this.dH = this.o.draw;
369
+ if (this.o.change) this.cH = this.o.change;
370
+ if (this.o.cancel) this.eH = this.o.cancel;
371
+ if (this.o.release) this.rH = this.o.release;
372
+
373
+ if (this.o.displayPrevious) {
374
+ this.pColor = this.h2rgba(this.o.fgColor, "0.4");
375
+ this.fgColor = this.h2rgba(this.o.fgColor, "0.6");
376
+ } else {
377
+ this.fgColor = this.o.fgColor;
378
+ }
379
+
380
+ return this;
381
+ };
382
+
383
+ this._clear = function () {
384
+ this.$c[0].width = this.$c[0].width;
385
+ };
386
+
387
+ this._validate = function(v) {
388
+ return (~~ (((v < 0) ? -0.5 : 0.5) + (v/this.o.step))) * this.o.step;
389
+ };
390
+
391
+ // Abstract methods
392
+ this.listen = function () {}; // on start, one time
393
+ this.extend = function () {}; // each time configure triggered
394
+ this.init = function () {}; // each time configure triggered
395
+ this.change = function (v) {}; // on change
396
+ this.val = function (v) {}; // on release
397
+ this.xy2val = function (x, y) {}; //
398
+ this.draw = function () {}; // on change / on release
399
+ this.clear = function () { this._clear(); };
400
+
401
+ // Utils
402
+ this.h2rgba = function (h, a) {
403
+ var rgb;
404
+ h = h.substring(1,7)
405
+ rgb = [parseInt(h.substring(0,2),16)
406
+ ,parseInt(h.substring(2,4),16)
407
+ ,parseInt(h.substring(4,6),16)];
408
+ return "rgba(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + a + ")";
409
+ };
410
+
411
+ this.copy = function (f, t) {
412
+ for (var i in f) { t[i] = f[i]; }
413
+ };
414
+ };
415
+
416
+
417
+ /**
418
+ * k.Dial
419
+ */
420
+ k.Dial = function () {
421
+ k.o.call(this);
422
+
423
+ this.startAngle = null;
424
+ this.xy = null;
425
+ this.radius = null;
426
+ this.lineWidth = null;
427
+ this.cursorExt = null;
428
+ this.w2 = null;
429
+ this.PI2 = 2*Math.PI;
430
+
431
+ this.extend = function () {
432
+ this.o = $.extend(
433
+ {
434
+ bgColor : this.$.data('bgcolor') || '#EEEEEE',
435
+ angleOffset : this.$.data('angleoffset') || 0,
436
+ angleArc : this.$.data('anglearc') || 360,
437
+ inline : true
438
+ }, this.o
439
+ );
440
+ };
441
+
442
+ this.val = function (v) {
443
+ if (null != v) {
444
+ this.cv = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
445
+ this.v = this.cv;
446
+ this.$.val(this.v);
447
+ this._draw();
448
+ } else {
449
+ return this.v;
450
+ }
451
+ };
452
+
453
+ this.xy2val = function (x, y) {
454
+ var a, ret;
455
+
456
+ a = Math.atan2(
457
+ x - (this.x + this.w2)
458
+ , - (y - this.y - this.w2)
459
+ ) - this.angleOffset;
460
+
461
+ if(this.angleArc != this.PI2 && (a < 0) && (a > -0.5)) {
462
+ // if isset angleArc option, set to min if .5 under min
463
+ a = 0;
464
+ } else if (a < 0) {
465
+ a += this.PI2;
466
+ }
467
+
468
+ ret = ~~ (0.5 + (a * (this.o.max - this.o.min) / this.angleArc))
469
+ + this.o.min;
470
+
471
+ this.o.stopper
472
+ && (ret = max(min(ret, this.o.max), this.o.min));
473
+
474
+ return ret;
475
+ };
476
+
477
+ this.listen = function () {
478
+ // bind MouseWheel
479
+ var s = this,
480
+ mw = function (e) {
481
+ e.preventDefault();
482
+ var ori = e.originalEvent
483
+ ,deltaX = ori.detail || ori.wheelDeltaX
484
+ ,deltaY = ori.detail || ori.wheelDeltaY
485
+ ,v = parseInt(s.$.val()) + (deltaX>0 || deltaY>0 ? s.o.step : deltaX<0 || deltaY<0 ? -s.o.step : 0);
486
+
487
+ if (
488
+ s.cH
489
+ && (s.cH(v) === false)
490
+ ) return;
491
+
492
+ s.val(v);
493
+ }
494
+ , kval, to, m = 1, kv = {37:-s.o.step, 38:s.o.step, 39:s.o.step, 40:-s.o.step};
495
+
496
+ this.$
497
+ .bind(
498
+ "keydown"
499
+ ,function (e) {
500
+ var kc = e.keyCode;
501
+
502
+ // numpad support
503
+ if(kc >= 96 && kc <= 105) {
504
+ kc = e.keyCode = kc - 48;
505
+ }
506
+
507
+ kval = parseInt(String.fromCharCode(kc));
508
+
509
+ if (isNaN(kval)) {
510
+
511
+ (kc !== 13) // enter
512
+ && (kc !== 8) // bs
513
+ && (kc !== 9) // tab
514
+ && (kc !== 189) // -
515
+ && e.preventDefault();
516
+
517
+ // arrows
518
+ if ($.inArray(kc,[37,38,39,40]) > -1) {
519
+ e.preventDefault();
520
+
521
+ var v = parseInt(s.$.val()) + kv[kc] * m;
522
+
523
+ s.o.stopper
524
+ && (v = max(min(v, s.o.max), s.o.min));
525
+
526
+ s.change(v);
527
+ s._draw();
528
+
529
+ // long time keydown speed-up
530
+ to = window.setTimeout(
531
+ function () { m*=2; }
532
+ ,30
533
+ );
534
+ }
535
+ }
536
+ }
537
+ )
538
+ .bind(
539
+ "keyup"
540
+ ,function (e) {
541
+ if (isNaN(kval)) {
542
+ if (to) {
543
+ window.clearTimeout(to);
544
+ to = null;
545
+ m = 1;
546
+ s.val(s.$.val());
547
+ }
548
+ } else {
549
+ // kval postcond
550
+ (s.$.val() > s.o.max && s.$.val(s.o.max))
551
+ || (s.$.val() < s.o.min && s.$.val(s.o.min));
552
+ }
553
+
554
+ }
555
+ );
556
+
557
+ this.$c.bind("mousewheel DOMMouseScroll", mw);
558
+ this.$.bind("mousewheel DOMMouseScroll", mw)
559
+ };
560
+
561
+ this.init = function () {
562
+
563
+ if (
564
+ this.v < this.o.min
565
+ || this.v > this.o.max
566
+ ) this.v = this.o.min;
567
+
568
+ this.$.val(this.v);
569
+ this.w2 = this.o.width / 2;
570
+ this.cursorExt = this.o.cursor / 100;
571
+ this.xy = this.w2 * this.scale;
572
+ this.lineWidth = this.xy * this.o.thickness;
573
+ this.lineCap = this.o.lineCap;
574
+ this.radius = this.xy - this.lineWidth / 2;
575
+
576
+ this.o.angleOffset
577
+ && (this.o.angleOffset = isNaN(this.o.angleOffset) ? 0 : this.o.angleOffset);
578
+
579
+ this.o.angleArc
580
+ && (this.o.angleArc = isNaN(this.o.angleArc) ? this.PI2 : this.o.angleArc);
581
+
582
+ // deg to rad
583
+ this.angleOffset = this.o.angleOffset * Math.PI / 180;
584
+ this.angleArc = this.o.angleArc * Math.PI / 180;
585
+
586
+ // compute start and end angles
587
+ this.startAngle = 1.5 * Math.PI + this.angleOffset;
588
+ this.endAngle = 1.5 * Math.PI + this.angleOffset + this.angleArc;
589
+
590
+ var s = max(
591
+ String(Math.abs(this.o.max)).length
592
+ , String(Math.abs(this.o.min)).length
593
+ , 2
594
+ ) + 2;
595
+
596
+ this.o.displayInput
597
+ && this.i.css({
598
+ 'width' : ((this.o.width / 2 + 4) >> 0) + 'px'
599
+ ,'height' : ((this.o.width / 3) >> 0) + 'px'
600
+ ,'position' : 'absolute'
601
+ ,'vertical-align' : 'middle'
602
+ ,'margin-top' : ((this.o.width / 3) >> 0) + 'px'
603
+ ,'margin-left' : '-' + ((this.o.width * 3 / 4 + 2) >> 0) + 'px'
604
+ ,'border' : 0
605
+ ,'background' : 'none'
606
+ ,'font' : 'bold ' + ((this.o.width / s) >> 0) + 'px Arial'
607
+ ,'text-align' : 'center'
608
+ ,'color' : this.o.inputColor || this.o.fgColor
609
+ ,'padding' : '0px'
610
+ ,'-webkit-appearance': 'none'
611
+ })
612
+ || this.i.css({
613
+ 'width' : '0px'
614
+ ,'visibility' : 'hidden'
615
+ });
616
+ };
617
+
618
+ this.change = function (v) {
619
+ this.cv = v;
620
+ this.$.val(v);
621
+ };
622
+
623
+ this.angle = function (v) {
624
+ return (v - this.o.min) * this.angleArc / (this.o.max - this.o.min);
625
+ };
626
+
627
+ this.draw = function () {
628
+
629
+ var c = this.g, // context
630
+ a = this.angle(this.cv) // Angle
631
+ , sat = this.startAngle // Start angle
632
+ , eat = sat + a // End angle
633
+ , sa, ea // Previous angles
634
+ , r = 1;
635
+
636
+ c.lineWidth = this.lineWidth;
637
+
638
+ c.lineCap = this.lineCap;
639
+
640
+ this.o.cursor
641
+ && (sat = eat - this.cursorExt)
642
+ && (eat = eat + this.cursorExt);
643
+
644
+ c.beginPath();
645
+ c.strokeStyle = this.o.bgColor;
646
+ c.arc(this.xy, this.xy, this.radius, this.endAngle, this.startAngle, true);
647
+ c.stroke();
648
+
649
+ if (this.o.displayPrevious) {
650
+ ea = this.startAngle + this.angle(this.v);
651
+ sa = this.startAngle;
652
+ this.o.cursor
653
+ && (sa = ea - this.cursorExt)
654
+ && (ea = ea + this.cursorExt);
655
+
656
+ c.beginPath();
657
+ c.strokeStyle = this.pColor;
658
+ c.arc(this.xy, this.xy, this.radius, sa, ea, false);
659
+ c.stroke();
660
+ r = (this.cv == this.v);
661
+ }
662
+
663
+ c.beginPath();
664
+ c.strokeStyle = r ? this.o.fgColor : this.fgColor ;
665
+ c.arc(this.xy, this.xy, this.radius, sat, eat, false);
666
+ c.stroke();
667
+ };
668
+
669
+ this.cancel = function () {
670
+ this.val(this.v);
671
+ };
672
+ };
673
+
674
+ $.fn.dial = $.fn.knob = function (o) {
675
+ return this.each(
676
+ function () {
677
+ var d = new k.Dial();
678
+ d.o = o;
679
+ d.$ = $(this);
680
+ d.run();
681
+ }
682
+ ).parent();
683
+ };
684
+
685
+ })(jQuery);