ink_ui_rails 2.1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +21 -0
  3. data/README.md +39 -0
  4. data/lib/ink_ui_rails.rb +8 -0
  5. data/lib/ink_ui_rails/version.rb +3 -0
  6. data/vendor/assets/fonts/font/FontAwesome.otf +0 -0
  7. data/vendor/assets/fonts/font/fontawesome-webfont.eot +0 -0
  8. data/vendor/assets/fonts/font/fontawesome-webfont.svg +399 -0
  9. data/vendor/assets/fonts/font/fontawesome-webfont.ttf +0 -0
  10. data/vendor/assets/fonts/font/fontawesome-webfont.woff +0 -0
  11. data/vendor/assets/fonts/font/ubuntu-b-webfont.eot +0 -0
  12. data/vendor/assets/fonts/font/ubuntu-b-webfont.svg +245 -0
  13. data/vendor/assets/fonts/font/ubuntu-b-webfont.ttf +0 -0
  14. data/vendor/assets/fonts/font/ubuntu-b-webfont.woff +0 -0
  15. data/vendor/assets/fonts/font/ubuntu-bi-webfont.eot +0 -0
  16. data/vendor/assets/fonts/font/ubuntu-bi-webfont.svg +245 -0
  17. data/vendor/assets/fonts/font/ubuntu-bi-webfont.ttf +0 -0
  18. data/vendor/assets/fonts/font/ubuntu-bi-webfont.woff +0 -0
  19. data/vendor/assets/fonts/font/ubuntu-c-webfont.eot +0 -0
  20. data/vendor/assets/fonts/font/ubuntu-c-webfont.svg +245 -0
  21. data/vendor/assets/fonts/font/ubuntu-c-webfont.ttf +0 -0
  22. data/vendor/assets/fonts/font/ubuntu-c-webfont.woff +0 -0
  23. data/vendor/assets/fonts/font/ubuntu-l-webfont.eot +0 -0
  24. data/vendor/assets/fonts/font/ubuntu-l-webfont.svg +245 -0
  25. data/vendor/assets/fonts/font/ubuntu-l-webfont.ttf +0 -0
  26. data/vendor/assets/fonts/font/ubuntu-l-webfont.woff +0 -0
  27. data/vendor/assets/fonts/font/ubuntu-li-webfont.eot +0 -0
  28. data/vendor/assets/fonts/font/ubuntu-li-webfont.svg +245 -0
  29. data/vendor/assets/fonts/font/ubuntu-li-webfont.ttf +0 -0
  30. data/vendor/assets/fonts/font/ubuntu-li-webfont.woff +0 -0
  31. data/vendor/assets/fonts/font/ubuntu-m-webfont.eot +0 -0
  32. data/vendor/assets/fonts/font/ubuntu-m-webfont.svg +245 -0
  33. data/vendor/assets/fonts/font/ubuntu-m-webfont.ttf +0 -0
  34. data/vendor/assets/fonts/font/ubuntu-m-webfont.woff +0 -0
  35. data/vendor/assets/fonts/font/ubuntu-mi-webfont.eot +0 -0
  36. data/vendor/assets/fonts/font/ubuntu-mi-webfont.svg +245 -0
  37. data/vendor/assets/fonts/font/ubuntu-mi-webfont.ttf +0 -0
  38. data/vendor/assets/fonts/font/ubuntu-mi-webfont.woff +0 -0
  39. data/vendor/assets/fonts/font/ubuntu-r-webfont.eot +0 -0
  40. data/vendor/assets/fonts/font/ubuntu-r-webfont.svg +245 -0
  41. data/vendor/assets/fonts/font/ubuntu-r-webfont.ttf +0 -0
  42. data/vendor/assets/fonts/font/ubuntu-r-webfont.woff +0 -0
  43. data/vendor/assets/fonts/font/ubuntu-ri-webfont.eot +0 -0
  44. data/vendor/assets/fonts/font/ubuntu-ri-webfont.svg +245 -0
  45. data/vendor/assets/fonts/font/ubuntu-ri-webfont.ttf +0 -0
  46. data/vendor/assets/fonts/font/ubuntu-ri-webfont.woff +0 -0
  47. data/vendor/assets/fonts/font/ubuntumono-b-webfont.eot +0 -0
  48. data/vendor/assets/fonts/font/ubuntumono-b-webfont.svg +242 -0
  49. data/vendor/assets/fonts/font/ubuntumono-b-webfont.ttf +0 -0
  50. data/vendor/assets/fonts/font/ubuntumono-b-webfont.woff +0 -0
  51. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.eot +0 -0
  52. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.svg +242 -0
  53. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.ttf +0 -0
  54. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.woff +0 -0
  55. data/vendor/assets/fonts/font/ubuntumono-r-webfont.eot +0 -0
  56. data/vendor/assets/fonts/font/ubuntumono-r-webfont.svg +242 -0
  57. data/vendor/assets/fonts/font/ubuntumono-r-webfont.ttf +0 -0
  58. data/vendor/assets/fonts/font/ubuntumono-r-webfont.woff +0 -0
  59. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.eot +0 -0
  60. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.svg +242 -0
  61. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.ttf +0 -0
  62. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.woff +0 -0
  63. data/vendor/assets/images/img/SAPOlogo.png +0 -0
  64. data/vendor/assets/images/img/favicon.ico +0 -0
  65. data/vendor/assets/images/img/home_bkg.png +0 -0
  66. data/vendor/assets/images/img/home_logo_IE.jpg +0 -0
  67. data/vendor/assets/images/img/icon_Sprite.png +0 -0
  68. data/vendor/assets/images/img/ink-favicon.ico +0 -0
  69. data/vendor/assets/images/img/logo_home.png +0 -0
  70. data/vendor/assets/images/img/shot_ink.png +0 -0
  71. data/vendor/assets/images/img/shot_intra.png +0 -0
  72. data/vendor/assets/images/img/shot_livebots.png +0 -0
  73. data/vendor/assets/images/img/shot_meo.png +0 -0
  74. data/vendor/assets/images/img/shot_musicbox.png +0 -0
  75. data/vendor/assets/images/img/shot_pessoa.png +0 -0
  76. data/vendor/assets/images/img/splash.1024x748.png +0 -0
  77. data/vendor/assets/images/img/splash.320x460.png +0 -0
  78. data/vendor/assets/images/img/splash.768x1004.png +0 -0
  79. data/vendor/assets/images/img/touch-icon.114.png +0 -0
  80. data/vendor/assets/images/img/touch-icon.16.png +0 -0
  81. data/vendor/assets/images/img/touch-icon.256.png +0 -0
  82. data/vendor/assets/images/img/touch-icon.57.png +0 -0
  83. data/vendor/assets/images/img/touch-icon.72.png +0 -0
  84. data/vendor/assets/javascripts/autoload.js +85 -0
  85. data/vendor/assets/javascripts/example.json +1174 -0
  86. data/vendor/assets/javascripts/holder.js +440 -0
  87. data/vendor/assets/javascripts/html5shiv-printshiv.js +496 -0
  88. data/vendor/assets/javascripts/html5shiv.js +298 -0
  89. data/vendor/assets/javascripts/ink-all.js +18015 -0
  90. data/vendor/assets/javascripts/ink-ui.js +7737 -0
  91. data/vendor/assets/javascripts/ink.aux.js +506 -0
  92. data/vendor/assets/javascripts/ink.close.js +54 -0
  93. data/vendor/assets/javascripts/ink.datepicker.js +1194 -0
  94. data/vendor/assets/javascripts/ink.datepicker.pt.js +32 -0
  95. data/vendor/assets/javascripts/ink.draggable.js +437 -0
  96. data/vendor/assets/javascripts/ink.droppable.js +193 -0
  97. data/vendor/assets/javascripts/ink.formvalidator.js +712 -0
  98. data/vendor/assets/javascripts/ink.gallery.js +757 -0
  99. data/vendor/assets/javascripts/ink.imagequery.js +259 -0
  100. data/vendor/assets/javascripts/ink.js +10278 -0
  101. data/vendor/assets/javascripts/ink.modal.js +628 -0
  102. data/vendor/assets/javascripts/ink.pagination.js +473 -0
  103. data/vendor/assets/javascripts/ink.progressbar.js +110 -0
  104. data/vendor/assets/javascripts/ink.smoothscroller.js +234 -0
  105. data/vendor/assets/javascripts/ink.sortablelist.js +338 -0
  106. data/vendor/assets/javascripts/ink.spy.js +123 -0
  107. data/vendor/assets/javascripts/ink.sticky.js +254 -0
  108. data/vendor/assets/javascripts/ink.table.js +621 -0
  109. data/vendor/assets/javascripts/ink.tabs.js +426 -0
  110. data/vendor/assets/javascripts/ink.toggle.js +218 -0
  111. data/vendor/assets/javascripts/ink.treeview.js +179 -0
  112. data/vendor/assets/javascripts/ink_ui.js +1 -0
  113. data/vendor/assets/javascripts/modernizr.js +815 -0
  114. data/vendor/assets/javascripts/prettify.js +28 -0
  115. data/vendor/assets/stylesheets/ink/_ink-ie7.css +1662 -0
  116. data/vendor/assets/stylesheets/ink/_ink.css +7496 -0
  117. data/vendor/assets/stylesheets/ink/ink_ui.scss.css +2 -0
  118. data/vendor/assets/stylesheets/ink_ui.scss.css +1 -0
  119. metadata +203 -0
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @module Ink.UI.ProgressBar_1
3
+ * @author inkdev AT sapo.pt
4
+ * @version 1
5
+ */
6
+ Ink.createModule('Ink.UI.ProgressBar', '1', ['Ink.Dom.Selector_1','Ink.Dom.Element_1'], function( Selector, Element ) {
7
+ 'use strict';
8
+
9
+ /**
10
+ * Associated to a .ink-progress-bar element, it provides the necessary
11
+ * method - setValue() - for the user to change the element's value.
12
+ *
13
+ * @class Ink.UI.ProgressBar
14
+ * @constructor
15
+ * @version 1
16
+ * @uses Ink.Dom.Selector
17
+ * @uses Ink.Dom.Element
18
+ * @param {String|DOMElement} selector
19
+ * @param {Object} [options] Options for the datepicker
20
+ * @param {Number} [options.startValue] Percentage of the bar that is filled. Range between 0 and 100. Default: 0
21
+ * @param {Function} [options.onStart] Callback that is called when a change of value is started
22
+ * @param {Function} [options.onEnd] Callback that is called when a change of value ends
23
+ *
24
+ * @example
25
+ * <div class="ink-progress-bar grey" data-start-value="70%">
26
+ * <span class="caption">I am a grey progress bar</span>
27
+ * <div class="bar grey"></div>
28
+ * </div>
29
+ * <script>
30
+ * Ink.requireModules( ['Ink.Dom.Selector_1','Ink.UI.ProgressBar_1'], function( Selector, ProgressBar ){
31
+ * var progressBarElement = Ink.s('.ink-progress-bar');
32
+ * var progressBarObj = new ProgressBar( progressBarElement );
33
+ * });
34
+ * </script>
35
+ */
36
+ var ProgressBar = function( selector, options ){
37
+
38
+ if( typeof selector !== 'object' ){
39
+ if( typeof selector !== 'string' ){
40
+ throw '[Ink.UI.ProgressBar] :: Invalid selector';
41
+ } else {
42
+ this._element = Selector.select(selector);
43
+ if( this._element.length < 1 ){
44
+ throw "[Ink.UI.ProgressBar] :: Selector didn't find any elements";
45
+ }
46
+ this._element = this._element[0];
47
+ }
48
+ } else {
49
+ this._element = selector;
50
+ }
51
+
52
+
53
+ this._options = Ink.extendObj({
54
+ 'startValue': 0,
55
+ 'onStart': function(){},
56
+ 'onEnd': function(){}
57
+ },Element.data(this._element));
58
+
59
+ this._options = Ink.extendObj( this._options, options || {});
60
+ this._value = this._options.startValue;
61
+
62
+ this._init();
63
+ };
64
+
65
+ ProgressBar.prototype = {
66
+
67
+ /**
68
+ * Init function called by the constructor
69
+ *
70
+ * @method _init
71
+ * @private
72
+ */
73
+ _init: function(){
74
+ this._elementBar = Selector.select('.bar',this._element);
75
+ if( this._elementBar.length < 1 ){
76
+ throw '[Ink.UI.ProgressBar] :: Bar element not found';
77
+ }
78
+ this._elementBar = this._elementBar[0];
79
+
80
+ this._options.onStart = Ink.bind(this._options.onStart,this);
81
+ this._options.onEnd = Ink.bind(this._options.onEnd,this);
82
+ this.setValue( this._options.startValue );
83
+ },
84
+
85
+ /**
86
+ * Sets the value of the Progressbar
87
+ *
88
+ * @method setValue
89
+ * @param {Number} newValue Numeric value, between 0 and 100, that represents the percentage of the bar.
90
+ * @public
91
+ */
92
+ setValue: function( newValue ){
93
+ this._options.onStart( this._value);
94
+
95
+ newValue = parseInt(newValue,10);
96
+ if( isNaN(newValue) || (newValue < 0) ){
97
+ newValue = 0;
98
+ } else if( newValue>100 ){
99
+ newValue = 100;
100
+ }
101
+ this._value = newValue;
102
+ this._elementBar.style.width = this._value + '%';
103
+
104
+ this._options.onEnd( this._value );
105
+ }
106
+ };
107
+
108
+ return ProgressBar;
109
+
110
+ });
@@ -0,0 +1,234 @@
1
+ /**
2
+ * @module Ink.UI.SmoothScroller_1
3
+ * @author inkdev AT sapo.pt
4
+ * @version 1
5
+ */
6
+ Ink.createModule('Ink.UI.SmoothScroller', '1', ['Ink.Dom.Event_1','Ink.Dom.Selector_1','Ink.Dom.Loaded_1'], function(Event, Selector, Loaded ) {
7
+ 'use strict';
8
+
9
+ /**
10
+ * @class Ink.UI.SmoothScroller
11
+ * @version 1
12
+ * @uses Ink.Dom.Event
13
+ * @uses Ink.Dom.Selector
14
+ * @uses Ink.Dom.Loaded
15
+ * @static
16
+ */
17
+ var SmoothScroller = {
18
+
19
+ /**
20
+ * Sets the speed of the scrolling
21
+ *
22
+ * @property
23
+ * @type {Number}
24
+ * @readOnly
25
+ * @static
26
+ */
27
+ speed: 10,
28
+
29
+ /**
30
+ * Returns the Y position of the div
31
+ *
32
+ * @method gy
33
+ * @param {DOMElement} d DOMElement to get the Y position from
34
+ * @return {Number} Y position of div 'd'
35
+ * @public
36
+ * @static
37
+ */
38
+ gy: function(d) {
39
+ var gy;
40
+ gy = d.offsetTop;
41
+ if (d.offsetParent){
42
+ while ( (d = d.offsetParent) ){
43
+ gy += d.offsetTop;
44
+ }
45
+ }
46
+ return gy;
47
+ },
48
+
49
+
50
+ /**
51
+ * Returns the current scroll position
52
+ *
53
+ * @method scrollTop
54
+ * @return {Number} Current scroll position
55
+ * @public
56
+ * @static
57
+ */
58
+ scrollTop: function() {
59
+ var
60
+ body = document.body,
61
+ d = document.documentElement
62
+ ;
63
+ if (body && body.scrollTop){
64
+ return body.scrollTop;
65
+ }
66
+ if (d && d.scrollTop){
67
+ return d.scrollTop;
68
+ }
69
+ if (window.pageYOffset)
70
+ {
71
+ return window.pageYOffset;
72
+ }
73
+ return 0;
74
+ },
75
+
76
+ /**
77
+ * Attaches an event for an element
78
+ *
79
+ * @method add
80
+ * @param {DOMElement} el DOMElement to make the listening of the event
81
+ * @param {String} event Event name to be listened
82
+ * @param {DOMElement} fn Callback function to run when the event is triggered.
83
+ * @public
84
+ * @static
85
+ */
86
+ add: function(el, event, fn) {
87
+ Event.observe(el,event,fn);
88
+ return;
89
+ },
90
+
91
+
92
+ /**
93
+ * Kill an event of an element
94
+ *
95
+ * @method end
96
+ * @param {String} e Event to be killed/stopped
97
+ * @public
98
+ * @static
99
+ */
100
+ // kill an event of an element
101
+ end: function(e) {
102
+ if (window.event) {
103
+ window.event.cancelBubble = true;
104
+ window.event.returnValue = false;
105
+ return;
106
+ }
107
+ Event.stop(e);
108
+ },
109
+
110
+
111
+ /**
112
+ * Moves the scrollbar to the target element
113
+ *
114
+ * @method scroll
115
+ * @param {Number} d Y coordinate value to stop
116
+ * @public
117
+ * @static
118
+ */
119
+ scroll: function(d) {
120
+ var a = Ink.UI.SmoothScroller.scrollTop();
121
+ if (d > a) {
122
+ a += Math.ceil((d - a) / Ink.UI.SmoothScroller.speed);
123
+ } else {
124
+ a = a + (d - a) / Ink.UI.SmoothScroller.speed;
125
+ }
126
+
127
+ window.scrollTo(0, a);
128
+ if ((a) === d || Ink.UI.SmoothScroller.offsetTop === a)
129
+ {
130
+ clearInterval(Ink.UI.SmoothScroller.interval);
131
+ }
132
+ Ink.UI.SmoothScroller.offsetTop = a;
133
+ },
134
+
135
+
136
+ /**
137
+ * Initializer that adds the rendered to run when the page is ready
138
+ *
139
+ * @method init
140
+ * @public
141
+ * @static
142
+ */
143
+ // initializer that adds the renderer to the onload function of the window
144
+ init: function() {
145
+ Loaded.run(Ink.UI.SmoothScroller.render);
146
+ },
147
+
148
+ /**
149
+ * This method extracts all the anchors and validates thenm as # and attaches the events
150
+ *
151
+ * @method render
152
+ * @public
153
+ * @static
154
+ */
155
+ render: function() {
156
+ var a = Selector.select('a.scrollableLink');
157
+
158
+ Ink.UI.SmoothScroller.end(this);
159
+
160
+ for (var i = 0; i < a.length; i++) {
161
+ var _elm = a[i];
162
+ if (_elm.href && _elm.href.indexOf('#') !== -1 && ((_elm.pathname === location.pathname) || ('/' + _elm.pathname === location.pathname))) {
163
+ Ink.UI.SmoothScroller.add(_elm, 'click', Ink.UI.SmoothScroller.end);
164
+ Event.observe(_elm,'click', Ink.bindEvent(Ink.UI.SmoothScroller.clickScroll, this, _elm));
165
+ }
166
+ }
167
+ },
168
+
169
+
170
+ /**
171
+ * Click handler
172
+ *
173
+ * @method clickScroll
174
+ * @public
175
+ * @static
176
+ */
177
+ clickScroll: function(event, _elm) {
178
+ /*
179
+ Ink.UI.SmoothScroller.end(this);
180
+ var hash = this.hash.substr(1);
181
+ var elm = Selector.select('a[name="' + hash + '"],#' + hash);
182
+
183
+ if (typeof(elm[0]) !== 'undefined') {
184
+
185
+ if (this.parentNode.className.indexOf('active') === -1) {
186
+ var ul = this.parentNode.parentNode,
187
+ li = ul.firstChild;
188
+ do {
189
+ if ((typeof(li.tagName) !== 'undefined') && (li.tagName.toUpperCase() === 'LI') && (li.className.indexOf('active') !== -1)) {
190
+ li.className = li.className.replace('active', '');
191
+ break;
192
+ }
193
+ } while ((li = li.nextSibling));
194
+ this.parentNode.className += " active";
195
+ }
196
+ clearInterval(Ink.UI.SmoothScroller.interval);
197
+ Ink.UI.SmoothScroller.interval = setInterval('Ink.UI.SmoothScroller.scroll(' + Ink.UI.SmoothScroller.gy(elm[0]) + ')', 10);
198
+
199
+ }
200
+ */
201
+ Ink.UI.SmoothScroller.end(_elm);
202
+ if(_elm !== null && _elm.getAttribute('href') !== null) {
203
+ var hashIndex = _elm.href.indexOf('#');
204
+ if(hashIndex === -1) {
205
+ return;
206
+ }
207
+ var hash = _elm.href.substr((hashIndex + 1));
208
+ var elm = Selector.select('a[name="' + hash + '"],#' + hash);
209
+
210
+ if (typeof(elm[0]) !== 'undefined') {
211
+
212
+ if (_elm.parentNode.className.indexOf('active') === -1) {
213
+ var ul = _elm.parentNode.parentNode,
214
+ li = ul.firstChild;
215
+ do {
216
+ if ((typeof(li.tagName) !== 'undefined') && (li.tagName.toUpperCase() === 'LI') && (li.className.indexOf('active') !== -1)) {
217
+ li.className = li.className.replace('active', '');
218
+ break;
219
+ }
220
+ } while ((li = li.nextSibling));
221
+ _elm.parentNode.className += " active";
222
+ }
223
+ clearInterval(Ink.UI.SmoothScroller.interval);
224
+ Ink.UI.SmoothScroller.interval = setInterval('Ink.UI.SmoothScroller.scroll(' + Ink.UI.SmoothScroller.gy(elm[0]) + ')', 10);
225
+
226
+ }
227
+ }
228
+
229
+ }
230
+ };
231
+
232
+ return SmoothScroller;
233
+
234
+ });
@@ -0,0 +1,338 @@
1
+ /**
2
+ * @module Ink.UI.SortableList_1
3
+ * @author inkdev AT sapo.pt
4
+ * @version 1
5
+ */
6
+ Ink.createModule('Ink.UI.SortableList', '1', ['Ink.UI.Aux_1','Ink.Dom.Event_1','Ink.Dom.Css_1','Ink.Dom.Element_1','Ink.Dom.Selector_1','Ink.Util.Array_1'], function(Aux, Event, Css, Element, Selector, InkArray ) {
7
+ 'use strict';
8
+
9
+ /**
10
+ * Adds sortable behaviour to any list!
11
+ *
12
+ * @class Ink.UI.SortableList
13
+ * @constructor
14
+ * @version 1
15
+ * @uses Ink.UI.Aux
16
+ * @uses Ink.Dom.Event
17
+ * @uses Ink.Dom.Css
18
+ * @uses Ink.Dom.Element
19
+ * @uses Ink.Dom.Selector
20
+ * @uses Ink.Util.Array
21
+ * @param {String|DOMElement} selector
22
+ * @param {Object} [options] Options for the datepicker
23
+ * @param {String} [options.dragObject] CSS Selector. The element that will trigger the dragging in the list. Default is 'li'.
24
+ * @example
25
+ * <ul class="unstyled ink-sortable-list" id="slist" data-instance="sortableList9">
26
+ * <li><span class="ink-label info"><i class="icon-reorder"></i>drag here</span>primeiro</li>
27
+ * <li><span class="ink-label info"><i class="icon-reorder"></i>drag here</span>segundo</li>
28
+ * <li><span class="ink-label info"><i class="icon-reorder"></i>drag here</span>terceiro</li>
29
+ * </ul>
30
+ * <script>
31
+ * Ink.requireModules( ['Ink.Dom.Selector_1','Ink.UI.SortableList_1'], function( Selector, SortableList ){
32
+ * var sortableListElement = Ink.s('.ink-sortable-list');
33
+ * var sortableListObj = new SortableList( sortableListElement );
34
+ * });
35
+ * </script>
36
+ */
37
+ var SortableList = function(selector, options) {
38
+
39
+ this._element = Aux.elOrSelector(selector, '1st argument');
40
+
41
+ if( !Aux.isDOMElement(selector) && (typeof selector !== 'string') ){
42
+ throw '[Ink.UI.SortableList] :: Invalid selector';
43
+ } else if( typeof selector === 'string' ){
44
+ this._element = Ink.Dom.Selector.select( selector );
45
+
46
+ if( this._element.length < 1 ){
47
+ throw '[Ink.UI.SortableList] :: Selector has returned no elements';
48
+ }
49
+ this._element = this._element[0];
50
+
51
+ } else {
52
+ this._element = selector;
53
+ }
54
+
55
+ this._options = Ink.extendObj({
56
+ dragObject: 'li'
57
+ }, Ink.Dom.Element.data(this._element));
58
+
59
+ this._options = Ink.extendObj( this._options, options || {});
60
+
61
+ this._handlers = {
62
+ down: Ink.bindEvent(this._onDown,this),
63
+ move: Ink.bindEvent(this._onMove,this),
64
+ up: Ink.bindEvent(this._onUp,this)
65
+ };
66
+
67
+ this._model = [];
68
+ this._index = undefined;
69
+ this._isMoving = false;
70
+
71
+ if (this._options.model instanceof Array) {
72
+ this._model = this._options.model;
73
+ this._createdFrom = 'JSON';
74
+ }
75
+ else if (this._element.nodeName.toLowerCase() === 'ul') {
76
+ this._createdFrom = 'DOM';
77
+ }
78
+ else {
79
+ throw new TypeError('You must pass a selector expression/DOM element as 1st option or provide a model on 2nd argument!');
80
+ }
81
+
82
+
83
+ this._dragTriggers = Selector.select( this._options.dragObject, this._element );
84
+ if( !this._dragTriggers ){
85
+ throw "[Ink.UI.SortableList] :: Drag object not found";
86
+ }
87
+
88
+ this._init();
89
+ };
90
+
91
+ SortableList.prototype = {
92
+
93
+ /**
94
+ * Init function called by the constructor.
95
+ *
96
+ * @method _init
97
+ * @private
98
+ */
99
+ _init: function() {
100
+ // extract model
101
+ if (this._createdFrom === 'DOM') {
102
+ this._extractModelFromDOM();
103
+ this._createdFrom = 'JSON';
104
+ }
105
+
106
+ var isTouch = 'ontouchstart' in document.documentElement;
107
+
108
+ this._down = isTouch ? 'touchstart': 'mousedown';
109
+ this._move = isTouch ? 'touchmove' : 'mousemove';
110
+ this._up = isTouch ? 'touchend' : 'mouseup';
111
+
112
+ // subscribe events
113
+ var db = document.body;
114
+ Event.observe(db, this._move, this._handlers.move);
115
+ Event.observe(db, this._up, this._handlers.up);
116
+ this._observe();
117
+
118
+ Aux.registerInstance(this, this._element, 'sortableList');
119
+ },
120
+
121
+ /**
122
+ * Sets the event handlers.
123
+ *
124
+ * @method _observe
125
+ * @private
126
+ */
127
+ _observe: function() {
128
+ Event.observe(this._element, this._down, this._handlers.down);
129
+ },
130
+
131
+ /**
132
+ * Updates the model from the UL representation
133
+ *
134
+ * @method _extractModelFromDOM
135
+ * @private
136
+ */
137
+ _extractModelFromDOM: function() {
138
+ this._model = [];
139
+ var that = this;
140
+
141
+ var liEls = Selector.select('> li', this._element);
142
+
143
+ InkArray.each(liEls,function(liEl) {
144
+ //var t = Element.getChildrenText(liEl);
145
+ var t = liEl.innerHTML;
146
+ that._model.push(t);
147
+ });
148
+ },
149
+
150
+ /**
151
+ * Returns the top element for the gallery DOM representation
152
+ *
153
+ * @method _generateMarkup
154
+ * @return {DOMElement}
155
+ * @private
156
+ */
157
+ _generateMarkup: function() {
158
+ var el = document.createElement('ul');
159
+ el.className = 'unstyled ink-sortable-list';
160
+ var that = this;
161
+
162
+ InkArray.each(this._model,function(label, idx) {
163
+ var liEl = document.createElement('li');
164
+ if (idx === that._index) {
165
+ liEl.className = 'drag';
166
+ }
167
+ liEl.innerHTML = [
168
+ // '<span class="ink-label ink-info"><i class="icon-reorder"></i>', that._options.dragLabel, '</span>', label
169
+ label
170
+ ].join('');
171
+ el.appendChild(liEl);
172
+ });
173
+
174
+ return el;
175
+ },
176
+
177
+ /**
178
+ * Extracts the Y coordinate of the mouse from the given MouseEvent
179
+ *
180
+ * @method _getY
181
+ * @param {Event} ev
182
+ * @return {Number}
183
+ * @private
184
+ */
185
+ _getY: function(ev) {
186
+ if (ev.type.indexOf('touch') === 0) {
187
+ //console.log(ev.type, ev.changedTouches[0].pageY);
188
+ return ev.changedTouches[0].pageY;
189
+ }
190
+ if (typeof ev.pageY === 'number') {
191
+ return ev.pageY;
192
+ }
193
+ return ev.clientY;
194
+ },
195
+
196
+ /**
197
+ * Refreshes the markup.
198
+ *
199
+ * @method _refresh
200
+ * @param {Boolean} skipObs True if needs to set the event handlers, false if not.
201
+ * @private
202
+ */
203
+ _refresh: function(skipObs) {
204
+ var el = this._generateMarkup();
205
+ this._element.parentNode.replaceChild(el, this._element);
206
+ this._element = el;
207
+
208
+ Aux.restoreIdAndClasses(this._element, this);
209
+
210
+ this._dragTriggers = Selector.select( this._options.dragObject, this._element );
211
+
212
+ // subscribe events
213
+ if (!skipObs) { this._observe(); }
214
+ },
215
+
216
+ /**
217
+ * Mouse down handler
218
+ *
219
+ * @method _onDown
220
+ * @param {Event} ev
221
+ * @return {Boolean|undefined} [description]
222
+ * @private
223
+ */
224
+ _onDown: function(ev) {
225
+ if (this._isMoving) { return; }
226
+ var tgtEl = Event.element(ev);
227
+
228
+ if( !InkArray.inArray(tgtEl,this._dragTriggers) ){
229
+ while( !InkArray.inArray(tgtEl,this._dragTriggers) && (tgtEl.nodeName.toLowerCase() !== 'body') ){
230
+ tgtEl = tgtEl.parentNode;
231
+ }
232
+
233
+ if( tgtEl.nodeName.toLowerCase() === 'body' ){
234
+ return;
235
+ }
236
+ }
237
+
238
+ Event.stop(ev);
239
+
240
+ var liEl;
241
+ if( tgtEl.nodeName.toLowerCase() !== 'li' ){
242
+ while( (tgtEl.nodeName.toLowerCase() !== 'li') && (tgtEl.nodeName.toLowerCase() !== 'body') ){
243
+ tgtEl = tgtEl.parentNode;
244
+ }
245
+ }
246
+ liEl = tgtEl;
247
+
248
+ this._index = Aux.childIndex(liEl);
249
+ this._height = liEl.offsetHeight;
250
+ this._startY = this._getY(ev);
251
+ this._isMoving = true;
252
+
253
+ document.body.style.cursor = 'move';
254
+
255
+ this._refresh(false);
256
+
257
+ return false;
258
+ },
259
+
260
+ /**
261
+ * Mouse move handler
262
+ *
263
+ * @method _onMove
264
+ * @param {Event} ev
265
+ * @private
266
+ */
267
+ _onMove: function(ev) {
268
+ if (!this._isMoving) { return; }
269
+ Event.stop(ev);
270
+
271
+ var y = this._getY(ev);
272
+ //console.log(y);
273
+ var dy = y - this._startY;
274
+ var sign = dy > 0 ? 1 : -1;
275
+ var di = sign * Math.floor( Math.abs(dy) / this._height );
276
+ if (di === 0) { return; }
277
+ di = di / Math.abs(di);
278
+ if ( (di === -1 && this._index === 0) ||
279
+ (di === 1 && this._index === this._model.length - 1) ) { return; }
280
+
281
+ var a = di > 0 ? this._index : this._index + di;
282
+ var b = di < 0 ? this._index : this._index + di;
283
+ //console.log(a, b);
284
+ this._model.splice(a, 2, this._model[b], this._model[a]);
285
+ this._index += di;
286
+ this._startY = y;
287
+
288
+ this._refresh(false);
289
+ },
290
+
291
+ /**
292
+ * Mouse up handler
293
+ *
294
+ * @method _onUp
295
+ * @param {Event} ev
296
+ * @private
297
+ */
298
+ _onUp: function(ev) {
299
+ if (!this._isMoving) { return; }
300
+ Event.stop(ev);
301
+
302
+ this._index = undefined;
303
+ this._isMoving = false;
304
+ document.body.style.cursor = '';
305
+
306
+ this._refresh();
307
+ },
308
+
309
+
310
+
311
+ /**************
312
+ * PUBLIC API *
313
+ **************/
314
+
315
+ /**
316
+ * Returns a copy of the model
317
+ *
318
+ * @method getModel
319
+ * @return {Array} Copy of the model
320
+ * @public
321
+ */
322
+ getModel: function() {
323
+ return this._model.slice();
324
+ },
325
+
326
+ /**
327
+ * Unregisters the component and removes its markup from the DOM
328
+ *
329
+ * @method destroy
330
+ * @public
331
+ */
332
+ destroy: Aux.destroyComponent
333
+
334
+ };
335
+
336
+ return SortableList;
337
+
338
+ });