glider-rails 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,8 +12,6 @@ Demo is available here: http://evrone.github.io/glider
12
12
 
13
13
  `bower install glider`
14
14
 
15
- UPD: bower install is currently unavailable, due to project moving to a new location
16
-
17
15
  ### Ruby-on-Rails
18
16
 
19
17
  Add this to your Gemfile
@@ -49,7 +47,7 @@ To convert the `src/glider.coffee` to javascript, use coffeescript compiler.
49
47
  Install it with:
50
48
 
51
49
  ```
52
- npm -g install coffee-script'
50
+ npm -g install coffee-script
53
51
  ```
54
52
 
55
53
  Then compile the file with:
@@ -98,3 +96,10 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
98
96
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
99
97
 
100
98
  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.
99
+
100
+ [mit]: http://www.opensource.org/licenses/mit-license.php
101
+ [murmur]: http://en.wikipedia.org/wiki/MurmurHash
102
+ [research]: https://panopticlick.eff.org/browser-uniqueness.pdf
103
+ [phantomjs]: http://phantomjs.org/
104
+ [uglifyjs]: https://github.com/mishoo/UglifyJS
105
+ [closure]: http://closure-compiler.appspot.com
@@ -0,0 +1,106 @@
1
+ ###
2
+ glider 0.0.3 - AngularJS slider
3
+ https://github.com/evrone/glider
4
+ Copyright (c) 2013 Valentin Vasilyev, Dmitry Karpunin
5
+ Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
6
+ ###
7
+ app = angular.module("glider", [])
8
+ # example:
9
+ # <slider min="0" max="100" step="1" value="age"></slider>
10
+ #
11
+ app.directive "slider", ["$document", ($document) ->
12
+
13
+ getSubElement = (sliderElement, className) ->
14
+ sliderElement[0].getElementsByClassName(className)[0]
15
+
16
+ moveHandle = (elem, posX) ->
17
+ angular.element(getSubElement(elem, "handle")).css("left", "#{posX}%")
18
+ angular.element(getSubElement(elem, "range")).css("width", "#{posX}%")
19
+
20
+ template: """
21
+ <span class="g-slider horizontal">
22
+ <span class="slider">
23
+ <span class="range"></span>
24
+ <span class="handle" ng-mousedown="mouseDown($event)"></span>
25
+ </span>
26
+ <span class="side dec">
27
+ <span class="button" ng-click="step(-1)">-</span>
28
+ <span class="bound-value">{{min()}}</span>
29
+ </span>
30
+ <span class="side inc">
31
+ <span class="button" ng-click="step(+1)">+</span>
32
+ <span class="bound-value">{{max()}}</span>
33
+ </span>
34
+ </span>
35
+ """
36
+ replace: true
37
+ restrict: "E"
38
+ scope:
39
+ value: "="
40
+ min: "&"
41
+ max: "&"
42
+
43
+ link: (scope, element, attrs) ->
44
+ sliderElement = getSubElement(element, "slider")
45
+ dragging = false
46
+ xPosition = 0
47
+ step = if attrs.step? then parseInt(attrs.step, 10) else 1
48
+
49
+ scope.value = scope.min() unless scope.value?
50
+
51
+ refreshHandle = ->
52
+ range = scope.max() - scope.min()
53
+ if range is 0
54
+ xPosition = 0
55
+ else
56
+ xPosition = (scope.value - scope.min()) / range * 100
57
+ xPosition = Math.min(Math.max(0, xPosition), 100)
58
+ moveHandle element, xPosition
59
+
60
+ scope.$watch "min()", (minValue) ->
61
+ if scope.value < minValue
62
+ scope.value = minValue
63
+ else
64
+ refreshHandle()
65
+
66
+ scope.$watch "max()", (maxValue) ->
67
+ if scope.value > maxValue
68
+ scope.value = maxValue
69
+ else
70
+ refreshHandle()
71
+
72
+ scope.$watch "value", ->
73
+ return if dragging
74
+ refreshHandle()
75
+
76
+ scope.step = (steps) ->
77
+ newValue = scope.value + steps * step
78
+ if scope.min() <= newValue <= scope.max()
79
+ scope.value = newValue
80
+
81
+ scope.mouseDown = ($event) ->
82
+ dragging = true
83
+ startPointX = $event.pageX
84
+
85
+ $document.on "mousemove", ($event) ->
86
+ return unless dragging
87
+
88
+ # Calculate value handle position
89
+ moveDelta = $event.pageX - startPointX
90
+ xPosition += moveDelta / sliderElement.offsetWidth * 100
91
+ if xPosition < 0
92
+ xPosition = 0
93
+ else if xPosition > 100
94
+ xPosition = 100
95
+ else
96
+ startPointX = $event.pageX
97
+ scope.value = Math.round((((scope.max() - scope.min()) * (xPosition / 100)) + scope.min()) / step) * step
98
+ scope.$apply()
99
+
100
+ moveHandle element, xPosition
101
+
102
+ # TODO check binding leaks
103
+ $document.on "mouseup", ->
104
+ dragging = false
105
+ $document.off "mousemove"
106
+ ]
@@ -1,23 +1,25 @@
1
1
  /*
2
- glider 0.0.2 - Angularjs slider
3
- https://github.com/Valve/glider
2
+ glider 0.0.3 - AngularJS slider
3
+ https://github.com/evrone/glider
4
4
  Copyright (c) 2013 Valentin Vasilyev, Dmitry Karpunin
5
5
  Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
6
6
  */
7
7
 
8
8
 
9
9
  (function() {
10
- var app,
11
- __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
10
+ var app;
12
11
 
13
12
  app = angular.module("glider", []);
14
13
 
15
14
  app.directive("slider", [
16
15
  "$document", function($document) {
17
- var moveHandle;
16
+ var getSubElement, moveHandle;
17
+ getSubElement = function(sliderElement, className) {
18
+ return sliderElement[0].getElementsByClassName(className)[0];
19
+ };
18
20
  moveHandle = function(elem, posX) {
19
- angular.element(elem[0].getElementsByClassName('handle')[0]).css("left", "" + posX + "%");
20
- return angular.element(elem[0].getElementsByClassName('range')[0]).css("width", "" + posX + "%");
21
+ angular.element(getSubElement(elem, "handle")).css("left", "" + posX + "%");
22
+ return angular.element(getSubElement(elem, "range")).css("width", "" + posX + "%");
21
23
  };
22
24
  return {
23
25
  template: "<span class=\"g-slider horizontal\">\n <span class=\"slider\">\n <span class=\"range\"></span>\n <span class=\"handle\" ng-mousedown=\"mouseDown($event)\"></span>\n </span>\n <span class=\"side dec\">\n <span class=\"button\" ng-click=\"step(-1)\">-</span>\n <span class=\"bound-value\">{{min()}}</span>\n </span>\n <span class=\"side inc\">\n <span class=\"button\" ng-click=\"step(+1)\">+</span>\n <span class=\"bound-value\">{{max()}}</span>\n </span>\n</span>",
@@ -25,44 +27,58 @@
25
27
  restrict: "E",
26
28
  scope: {
27
29
  value: "=",
28
- min: '&',
29
- max: '&'
30
+ min: "&",
31
+ max: "&"
30
32
  },
31
33
  link: function(scope, element, attrs) {
32
- var dragging, startPointX, step, xPosition;
34
+ var dragging, refreshHandle, sliderElement, step, xPosition;
35
+ sliderElement = getSubElement(element, "slider");
33
36
  dragging = false;
34
- startPointX = 0;
35
37
  xPosition = 0;
36
38
  step = attrs.step != null ? parseInt(attrs.step, 10) : 1;
37
39
  if (scope.value == null) {
38
40
  scope.value = scope.min();
39
41
  }
40
- scope.$watch("value", function() {
41
- if (dragging) {
42
- return;
43
- }
44
- xPosition = (scope.value - scope.min()) / (scope.max() - scope.min()) * 100;
45
- if (xPosition < 0) {
42
+ refreshHandle = function() {
43
+ var range;
44
+ range = scope.max() - scope.min();
45
+ if (range === 0) {
46
46
  xPosition = 0;
47
47
  } else {
48
- if (xPosition > 100) {
49
- xPosition = 100;
50
- }
48
+ xPosition = (scope.value - scope.min()) / range * 100;
49
+ xPosition = Math.min(Math.max(0, xPosition), 100);
51
50
  }
52
51
  return moveHandle(element, xPosition);
52
+ };
53
+ scope.$watch("min()", function(minValue) {
54
+ if (scope.value < minValue) {
55
+ return scope.value = minValue;
56
+ } else {
57
+ return refreshHandle();
58
+ }
59
+ });
60
+ scope.$watch("max()", function(maxValue) {
61
+ if (scope.value > maxValue) {
62
+ return scope.value = maxValue;
63
+ } else {
64
+ return refreshHandle();
65
+ }
66
+ });
67
+ scope.$watch("value", function() {
68
+ if (dragging) {
69
+ return;
70
+ }
71
+ return refreshHandle();
53
72
  });
54
- scope.step = function(step_value) {
55
- var inc, _i, _ref, _ref1, _ref2, _results;
56
- inc = step_value * step;
57
- if (_ref = scope.value + inc, __indexOf.call((function() {
58
- _results = [];
59
- for (var _i = _ref1 = scope.min(), _ref2 = scope.max(); _ref1 <= _ref2 ? _i <= _ref2 : _i >= _ref2; _ref1 <= _ref2 ? _i++ : _i--){ _results.push(_i); }
60
- return _results;
61
- }).apply(this), _ref) >= 0) {
62
- return scope.value += inc;
73
+ scope.step = function(steps) {
74
+ var newValue;
75
+ newValue = scope.value + steps * step;
76
+ if ((scope.min() <= newValue && newValue <= scope.max())) {
77
+ return scope.value = newValue;
63
78
  }
64
79
  };
65
80
  return scope.mouseDown = function($event) {
81
+ var startPointX;
66
82
  dragging = true;
67
83
  startPointX = $event.pageX;
68
84
  $document.on("mousemove", function($event) {
@@ -71,7 +87,7 @@
71
87
  return;
72
88
  }
73
89
  moveDelta = $event.pageX - startPointX;
74
- xPosition = xPosition + ((moveDelta / element[0].offsetWidth) * 100);
90
+ xPosition += moveDelta / sliderElement.offsetWidth * 100;
75
91
  if (xPosition < 0) {
76
92
  xPosition = 0;
77
93
  } else if (xPosition > 100) {
@@ -83,7 +99,7 @@
83
99
  scope.$apply();
84
100
  return moveHandle(element, xPosition);
85
101
  });
86
- return $document.on('mouseup', function() {
102
+ return $document.on("mouseup", function() {
87
103
  dragging = false;
88
104
  return $document.off("mousemove");
89
105
  });
@@ -1 +1 @@
1
- !function(){var n,a=[].indexOf||function(n){for(var a=0,e=this.length;e>a;a++)if(a in this&&this[a]===n)return a;return-1};n=angular.module("glider",[]),n.directive("slider",["$document",function(n){var e;return e=function(n,a){return angular.element(n[0].getElementsByClassName("handle")[0]).css("left",""+a+"%"),angular.element(n[0].getElementsByClassName("range")[0]).css("width",""+a+"%")},{template:'<span class="g-slider horizontal">\n <span class="slider">\n <span class="range"></span>\n <span class="handle" ng-mousedown="mouseDown($event)"></span>\n </span>\n <span class="side dec">\n <span class="button" ng-click="step(-1)">-</span>\n <span class="bound-value">{{min()}}</span>\n </span>\n <span class="side inc">\n <span class="button" ng-click="step(+1)">+</span>\n <span class="bound-value">{{max()}}</span>\n </span>\n</span>',replace:!0,restrict:"E",scope:{value:"=",min:"&",max:"&"},link:function(s,t,l){var u,r,i,o;return u=!1,r=0,o=0,i=null!=l.step?parseInt(l.step,10):1,null==s.value&&(s.value=s.min()),s.$watch("value",function(){return u?void 0:(o=100*((s.value-s.min())/(s.max()-s.min())),0>o?o=0:o>100&&(o=100),e(t,o))}),s.step=function(n){var e,t,l,u;return e=n*i,t=s.value+e,a.call(function(){u=[];for(var n=l=s.min(),a=s.max();a>=l?a>=n:n>=a;a>=l?n++:n--)u.push(n);return u}.apply(this),t)>=0?s.value+=e:void 0},s.mouseDown=function(a){return u=!0,r=a.pageX,n.on("mousemove",function(n){var a;if(u)return a=n.pageX-r,o+=100*(a/t[0].offsetWidth),0>o?o=0:o>100?o=100:r=n.pageX,s.value=Math.round(((s.max()-s.min())*(o/100)+s.min())/i)*i,s.$apply(),e(t,o)}),n.on("mouseup",function(){return u=!1,n.off("mousemove")})}}}}])}.call(this);
1
+ (function(){var n;n=angular.module("glider",[]),n.directive("slider",["$document",function(n){var a,e;return a=function(n,a){return n[0].getElementsByClassName(a)[0]},e=function(n,e){return angular.element(a(n,"handle")).css("left",""+e+"%"),angular.element(a(n,"range")).css("width",""+e+"%")},{template:'<span class="g-slider horizontal">\n <span class="slider">\n <span class="range"></span>\n <span class="handle" ng-mousedown="mouseDown($event)"></span>\n </span>\n <span class="side dec">\n <span class="button" ng-click="step(-1)">-</span>\n <span class="bound-value">{{min()}}</span>\n </span>\n <span class="side inc">\n <span class="button" ng-click="step(+1)">+</span>\n <span class="bound-value">{{max()}}</span>\n </span>\n</span>',replace:!0,restrict:"E",scope:{value:"=",min:"&",max:"&"},link:function(s,t,u){var l,r,i,c,o;return i=a(t,"slider"),l=!1,o=0,c=null!=u.step?parseInt(u.step,10):1,null==s.value&&(s.value=s.min()),r=function(){var n;return n=s.max()-s.min(),0===n?o=0:(o=100*((s.value-s.min())/n),o=Math.min(Math.max(0,o),100)),e(t,o)},s.$watch("min()",function(n){return s.value<n?s.value=n:r()}),s.$watch("max()",function(n){return s.value>n?s.value=n:r()}),s.$watch("value",function(){return l?void 0:r()}),s.step=function(n){var a;return a=s.value+n*c,s.min()<=a&&a<=s.max()?s.value=a:void 0},s.mouseDown=function(a){var u;return l=!0,u=a.pageX,n.on("mousemove",function(n){var a;if(l)return a=n.pageX-u,o+=100*(a/i.offsetWidth),0>o?o=0:o>100?o=100:u=n.pageX,s.value=Math.round(((s.max()-s.min())*(o/100)+s.min())/c)*c,s.$apply(),e(t,o)}),n.on("mouseup",function(){return l=!1,n.off("mousemove")})}}}}])}).call(this);
data/glider-rails.gemspec CHANGED
@@ -4,11 +4,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "glider-rails"
7
- gem.version = "0.0.2"
7
+ gem.version = "0.0.3"
8
8
  gem.authors = ["Valentin Vasilyev", "Dmitry Karpunin"]
9
- gem.email = ["iamvalentin@gmail.com"]
10
- gem.description = "Glider, angularjs UI slider for rails asset pipeline"
11
- gem.summary = "Glider - angularjs UI slider library, packaged for Ruby-on-Rails asset pipeline"
9
+ gem.email = ["iamvalentin@gmail.com", "koderfunk@gmail.com"]
10
+ gem.description = "Glider, AngularJS UI slider for rails asset pipeline"
11
+ gem.summary = "Glider AngularJS UI slider library, packaged for Ruby-on-Rails asset pipeline"
12
12
  gem.homepage = "http://evrone.github.com/glider-rails"
13
13
 
14
14
  gem.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glider-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,12 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-09 00:00:00.000000000 Z
13
+ date: 2013-09-16 00:00:00.000000000 Z
14
14
  dependencies: []
15
- description: Glider, angularjs UI slider for rails asset pipeline
15
+ description: Glider, AngularJS UI slider for rails asset pipeline
16
16
  email:
17
17
  - iamvalentin@gmail.com
18
+ - koderfunk@gmail.com
18
19
  executables: []
19
20
  extensions: []
20
21
  extra_rdoc_files: []
@@ -24,6 +25,7 @@ files:
24
25
  - LICENSE.txt
25
26
  - README.md
26
27
  - Rakefile
28
+ - app/assets/javascripts/glider.coffee
27
29
  - app/assets/javascripts/glider.js
28
30
  - app/assets/javascripts/glider.min.js
29
31
  - glider-rails.gemspec
@@ -48,8 +50,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
50
  version: '0'
49
51
  requirements: []
50
52
  rubyforge_project:
51
- rubygems_version: 1.8.23
53
+ rubygems_version: 1.8.25
52
54
  signing_key:
53
55
  specification_version: 3
54
- summary: Glider - angularjs UI slider library, packaged for Ruby-on-Rails asset pipeline
56
+ summary: Glider AngularJS UI slider library, packaged for Ruby-on-Rails asset pipeline
55
57
  test_files: []