transit 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/Gemfile +19 -11
  2. data/app/assets/images/transit/icon24x24.png +0 -0
  3. data/app/assets/images/transit/icon24x24_files.png +0 -0
  4. data/app/assets/images/transit/jplayer.swf +0 -0
  5. data/app/assets/images/transit/uploadify.swf +0 -0
  6. data/app/assets/images/transit/video_player.swf +0 -0
  7. data/app/assets/javascripts/jqtools/expose.js +224 -0
  8. data/app/assets/javascripts/jqtools/flashembed.js +300 -0
  9. data/app/assets/javascripts/jqtools/overlay.js +294 -0
  10. data/app/assets/javascripts/jqtools/scrollable.js +3 -0
  11. data/app/assets/javascripts/jqtools/scrollable/autoscroll.js +81 -0
  12. data/app/assets/javascripts/jqtools/scrollable/base.js +335 -0
  13. data/app/assets/javascripts/jqtools/scrollable/navigator.js +139 -0
  14. data/app/assets/javascripts/jqtools/validator.js +590 -0
  15. data/app/assets/javascripts/jqueryui/accordion.js +611 -0
  16. data/app/assets/javascripts/jqueryui/autocomplete.js +612 -0
  17. data/app/assets/javascripts/jqueryui/button.js +388 -0
  18. data/app/assets/javascripts/jqueryui/core.js +312 -0
  19. data/app/assets/javascripts/jqueryui/datepicker.js +1791 -0
  20. data/app/assets/javascripts/jqueryui/dialog.js +878 -0
  21. data/app/assets/javascripts/jqueryui/draggable.js +815 -0
  22. data/app/assets/javascripts/jqueryui/droppable.js +285 -0
  23. data/app/assets/javascripts/jqueryui/effects/blind.js +49 -0
  24. data/app/assets/javascripts/jqueryui/effects/bounce.js +78 -0
  25. data/app/assets/javascripts/jqueryui/effects/clip.js +54 -0
  26. data/app/assets/javascripts/jqueryui/effects/core.js +746 -0
  27. data/app/assets/javascripts/jqueryui/effects/drop.js +50 -0
  28. data/app/assets/javascripts/jqueryui/effects/explode.js +79 -0
  29. data/app/assets/javascripts/jqueryui/effects/fade.js +32 -0
  30. data/app/assets/javascripts/jqueryui/effects/fold.js +56 -0
  31. data/app/assets/javascripts/jqueryui/effects/highlight.js +50 -0
  32. data/app/assets/javascripts/jqueryui/effects/pulsate.js +51 -0
  33. data/app/assets/javascripts/jqueryui/effects/scale.js +178 -0
  34. data/app/assets/javascripts/jqueryui/effects/shake.js +57 -0
  35. data/app/assets/javascripts/jqueryui/effects/slide.js +50 -0
  36. data/app/assets/javascripts/jqueryui/effects/transfer.js +45 -0
  37. data/app/assets/javascripts/jqueryui/mouse.js +160 -0
  38. data/app/assets/javascripts/jqueryui/position.js +252 -0
  39. data/app/assets/javascripts/jqueryui/progressbar.js +109 -0
  40. data/app/assets/javascripts/jqueryui/resizable.js +814 -0
  41. data/app/assets/javascripts/jqueryui/selectable.js +266 -0
  42. data/app/assets/javascripts/jqueryui/slider.js +666 -0
  43. data/app/assets/javascripts/jqueryui/sortable.js +1077 -0
  44. data/app/assets/javascripts/jqueryui/tabs.js +758 -0
  45. data/app/assets/javascripts/jqueryui/widget.js +262 -0
  46. data/app/assets/javascripts/libs/backbone.js +1152 -0
  47. data/app/assets/javascripts/libs/cookie.js +89 -0
  48. data/app/assets/javascripts/libs/fileinput.js +130 -0
  49. data/app/assets/javascripts/libs/jplayer.js +1768 -0
  50. data/app/assets/javascripts/libs/proper.js +541 -0
  51. data/app/assets/javascripts/libs/sanitize.js +282 -0
  52. data/app/assets/javascripts/libs/selecttolist.js +75 -0
  53. data/app/assets/javascripts/libs/underscore.js +807 -0
  54. data/app/assets/javascripts/libs/uploadify.js +677 -0
  55. data/app/assets/javascripts/libs/wymeditor.js +9538 -0
  56. data/app/assets/javascripts/transit.js +4 -0
  57. data/app/assets/javascripts/transit/admin.js +22 -0
  58. data/app/assets/javascripts/transit/admin/contexts.js +52 -0
  59. data/app/assets/javascripts/transit/admin/fields.js +36 -0
  60. data/app/assets/javascripts/transit/admin/upload.js +109 -0
  61. data/app/assets/javascripts/transit/config.js.erb +101 -0
  62. data/app/assets/javascripts/transit/contexts/audio.js +39 -0
  63. data/app/assets/javascripts/transit/contexts/video.js +79 -0
  64. data/app/assets/javascripts/transit/core.js +171 -0
  65. data/app/assets/javascripts/transit/frontend.js +3 -0
  66. data/app/assets/javascripts/transit/lib/base64.js +120 -0
  67. data/app/assets/javascripts/transit/lib/editor.js +177 -0
  68. data/app/assets/javascripts/transit/views/audio_player.jst +22 -0
  69. data/app/assets/javascripts/transit/views/editor_toolbar.jst +12 -0
  70. data/app/assets/javascripts/transit/views/file_upload.jst +5 -0
  71. data/app/assets/javascripts/transit/views/video_player.jst +20 -0
  72. data/app/assets/javascripts/transit/views/wym_box.jst +4 -0
  73. data/app/assets/javascripts/transit/views/wym_iframe.jst +3 -0
  74. data/app/assets/stylesheets/transit.css.scss.erb +42 -0
  75. data/app/assets/stylesheets/transit/forms.css.scss +66 -0
  76. data/app/assets/stylesheets/transit/media/audio.css.scss +65 -0
  77. data/app/assets/stylesheets/transit/media/video.css.scss +30 -0
  78. data/app/assets/stylesheets/transit/panel.css.scss +100 -0
  79. data/app/assets/stylesheets/transit/ui.css.scss +507 -0
  80. data/app/controllers/pages_controller.rb +3 -0
  81. data/app/controllers/posts_controller.rb +3 -0
  82. data/app/controllers/transit/assets_controller.rb +38 -0
  83. data/app/controllers/transit/contexts_controller.rb +12 -9
  84. data/app/controllers/transit/pages_controller.rb +26 -0
  85. data/app/controllers/transit/posts_controller.rb +31 -0
  86. data/app/controllers/transit/topics_controller.rb +5 -0
  87. data/app/controllers/transit_controller.rb +16 -0
  88. data/app/helpers/transit/admin_helper.rb +43 -0
  89. data/app/helpers/transit/form_helper.rb +17 -0
  90. data/app/helpers/transit/package_helper.rb +41 -0
  91. data/app/helpers/transit/pagination_helper.rb +58 -0
  92. data/app/helpers/transit_helper.rb +42 -0
  93. data/app/models/comment.rb +37 -0
  94. data/app/models/contexts/audio.rb +12 -0
  95. data/app/models/{text.rb → contexts/text.rb} +0 -0
  96. data/app/models/contexts/video.rb +24 -0
  97. data/app/models/topic.rb +19 -0
  98. data/app/models/transit/asset.rb +68 -0
  99. data/{lib → app/models}/transit/context.rb +29 -0
  100. data/app/views/contexts/_text.html.erb +1 -1
  101. data/app/views/posts/index.rss.builder +18 -0
  102. data/app/views/transit/assets/_file.html.erb +4 -0
  103. data/app/views/transit/assets/_image.html.erb +13 -0
  104. data/app/views/transit/assets/create.js.erb +8 -0
  105. data/app/views/transit/assets/destroy.js.erb +3 -0
  106. data/app/views/transit/assets/manage.html.erb +20 -0
  107. data/app/views/transit/contexts/_audio.html.erb +18 -0
  108. data/app/views/transit/contexts/_text.html.erb +6 -0
  109. data/app/views/transit/contexts/_video.html.erb +13 -0
  110. data/app/views/transit/contexts/destroy.js.erb +1 -0
  111. data/app/views/transit/contexts/index.html.erb +5 -0
  112. data/app/views/transit/contexts/new.js.erb +7 -0
  113. data/app/views/transit/contexts/show.html.erb +8 -0
  114. data/app/views/transit/index.html.erb +26 -0
  115. data/app/views/transit/index.js.erb +1 -0
  116. data/app/views/transit/interface/post_panel.html.erb +96 -0
  117. data/app/views/transit/pages/_table.html.erb +7 -0
  118. data/app/views/transit/pages/edit.html.erb +17 -0
  119. data/app/views/transit/pages/index.html.erb +17 -0
  120. data/app/views/transit/pages/update.js.erb +1 -0
  121. data/app/views/transit/posts/_form.html.erb +49 -0
  122. data/app/views/transit/posts/edit.html.erb +14 -0
  123. data/app/views/transit/posts/new.html.erb +21 -0
  124. data/app/views/transit/table.html.erb +13 -0
  125. data/app/views/transit/table.js.erb +8 -0
  126. data/app/views/transit/topics/manage.html.erb +28 -0
  127. data/config/locales/en.yml +22 -0
  128. data/config/routes.rb +3 -3
  129. data/lib/transit.rb +51 -17
  130. data/lib/transit/admin.rb +85 -0
  131. data/lib/transit/builders/form_builder.rb +319 -0
  132. data/lib/transit/builders/jst_builder.rb +38 -0
  133. data/lib/transit/builders/package_builder.rb +45 -0
  134. data/lib/transit/config.rb +20 -0
  135. data/lib/transit/controller/generator.rb +42 -0
  136. data/lib/transit/controller/responder.rb +34 -0
  137. data/lib/transit/core_ext.rb +18 -0
  138. data/lib/transit/errors/resource_not_found.rb +6 -0
  139. data/lib/transit/model/assets.rb +14 -0
  140. data/lib/transit/model/attachments.rb +55 -0
  141. data/lib/transit/model/auto_increment.rb +22 -0
  142. data/lib/transit/model/base.rb +56 -0
  143. data/lib/transit/model/comments.rb +19 -0
  144. data/lib/transit/model/hooks.rb +38 -0
  145. data/lib/transit/model/owners.rb +14 -0
  146. data/lib/transit/model/paginator.rb +92 -0
  147. data/lib/transit/model/topics.rb +14 -0
  148. data/lib/transit/package/page.rb +20 -12
  149. data/lib/transit/package/post.rb +87 -33
  150. data/lib/transit/package/post/validations.rb +14 -0
  151. data/lib/transit/rails/engine.rb +29 -13
  152. data/lib/transit/rails/railtie.rb +31 -0
  153. data/lib/transit/rails/routing.rb +11 -6
  154. data/lib/transit/services.rb +13 -0
  155. data/lib/transit/services/base.rb +14 -0
  156. data/lib/transit/services/facebook.rb +13 -0
  157. data/lib/transit/services/ted.rb +10 -0
  158. data/lib/transit/services/twitter.rb +13 -0
  159. data/lib/transit/services/vimeo.rb +10 -0
  160. data/lib/transit/services/you_tube.rb +12 -0
  161. data/lib/transit/version.rb +1 -1
  162. metadata +178 -31
  163. data/app/assets/stylesheets/includes/_compat.scss +0 -24
  164. data/app/assets/stylesheets/includes/_defaults.scss +0 -99
  165. data/app/assets/stylesheets/includes/_global.scss +0 -16
  166. data/app/assets/stylesheets/includes/_imports.scss +0 -27
  167. data/app/assets/stylesheets/includes/_mixins.scss +0 -38
  168. data/app/assets/stylesheets/includes/_setup.scss +0 -85
  169. data/app/assets/stylesheets/layout.css.scss +0 -29
  170. data/app/assets/stylesheets/transit.css +0 -3
  171. data/app/controllers/application_controller.rb +0 -5
  172. data/app/controllers/transit/index_controller.rb +0 -7
  173. data/app/controllers/transit/packages_controller.rb +0 -64
  174. data/app/controllers/transit/transit_controller.rb +0 -4
  175. data/app/helpers/routing_helpers.rb +0 -7
  176. data/app/models/audio.rb +0 -4
  177. data/app/models/package_asset.rb +0 -11
  178. data/app/models/video.rb +0 -8
  179. data/app/views/contexts/_audio.html.erb +0 -1
  180. data/app/views/contexts/_video.html.erb +0 -1
  181. data/app/views/layouts/transit.html.erb +0 -31
  182. data/app/views/transit/index/index.html.erb +0 -0
  183. data/lib/transit/helpers/controller_helpers.rb +0 -40
  184. data/lib/transit/helpers/model_helpers.rb +0 -26
  185. data/lib/transit/package.rb +0 -25
  186. data/lib/transit/package/base.rb +0 -49
@@ -0,0 +1,266 @@
1
+ /*
2
+ * jQuery UI Selectable 1.8.13
3
+ *
4
+ * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
5
+ * Dual licensed under the MIT or GPL Version 2 licenses.
6
+ * http://jquery.org/license
7
+ *
8
+ * http://docs.jquery.com/UI/Selectables
9
+ *
10
+ * Depends:
11
+ * jquery.ui.core.js
12
+ * jquery.ui.mouse.js
13
+ * jquery.ui.widget.js
14
+ */
15
+ (function( $, undefined ) {
16
+
17
+ $.widget("ui.selectable", $.ui.mouse, {
18
+ options: {
19
+ appendTo: 'body',
20
+ autoRefresh: true,
21
+ distance: 0,
22
+ filter: '*',
23
+ tolerance: 'touch'
24
+ },
25
+ _create: function() {
26
+ var self = this;
27
+
28
+ this.element.addClass("ui-selectable");
29
+
30
+ this.dragged = false;
31
+
32
+ // cache selectee children based on filter
33
+ var selectees;
34
+ this.refresh = function() {
35
+ selectees = $(self.options.filter, self.element[0]);
36
+ selectees.each(function() {
37
+ var $this = $(this);
38
+ var pos = $this.offset();
39
+ $.data(this, "selectable-item", {
40
+ element: this,
41
+ $element: $this,
42
+ left: pos.left,
43
+ top: pos.top,
44
+ right: pos.left + $this.outerWidth(),
45
+ bottom: pos.top + $this.outerHeight(),
46
+ startselected: false,
47
+ selected: $this.hasClass('ui-selected'),
48
+ selecting: $this.hasClass('ui-selecting'),
49
+ unselecting: $this.hasClass('ui-unselecting')
50
+ });
51
+ });
52
+ };
53
+ this.refresh();
54
+
55
+ this.selectees = selectees.addClass("ui-selectee");
56
+
57
+ this._mouseInit();
58
+
59
+ this.helper = $("<div class='ui-selectable-helper'></div>");
60
+ },
61
+
62
+ destroy: function() {
63
+ this.selectees
64
+ .removeClass("ui-selectee")
65
+ .removeData("selectable-item");
66
+ this.element
67
+ .removeClass("ui-selectable ui-selectable-disabled")
68
+ .removeData("selectable")
69
+ .unbind(".selectable");
70
+ this._mouseDestroy();
71
+
72
+ return this;
73
+ },
74
+
75
+ _mouseStart: function(event) {
76
+ var self = this;
77
+
78
+ this.opos = [event.pageX, event.pageY];
79
+
80
+ if (this.options.disabled)
81
+ return;
82
+
83
+ var options = this.options;
84
+
85
+ this.selectees = $(options.filter, this.element[0]);
86
+
87
+ this._trigger("start", event);
88
+
89
+ $(options.appendTo).append(this.helper);
90
+ // position helper (lasso)
91
+ this.helper.css({
92
+ "left": event.clientX,
93
+ "top": event.clientY,
94
+ "width": 0,
95
+ "height": 0
96
+ });
97
+
98
+ if (options.autoRefresh) {
99
+ this.refresh();
100
+ }
101
+
102
+ this.selectees.filter('.ui-selected').each(function() {
103
+ var selectee = $.data(this, "selectable-item");
104
+ selectee.startselected = true;
105
+ if (!event.metaKey) {
106
+ selectee.$element.removeClass('ui-selected');
107
+ selectee.selected = false;
108
+ selectee.$element.addClass('ui-unselecting');
109
+ selectee.unselecting = true;
110
+ // selectable UNSELECTING callback
111
+ self._trigger("unselecting", event, {
112
+ unselecting: selectee.element
113
+ });
114
+ }
115
+ });
116
+
117
+ $(event.target).parents().andSelf().each(function() {
118
+ var selectee = $.data(this, "selectable-item");
119
+ if (selectee) {
120
+ var doSelect = !event.metaKey || !selectee.$element.hasClass('ui-selected');
121
+ selectee.$element
122
+ .removeClass(doSelect ? "ui-unselecting" : "ui-selected")
123
+ .addClass(doSelect ? "ui-selecting" : "ui-unselecting");
124
+ selectee.unselecting = !doSelect;
125
+ selectee.selecting = doSelect;
126
+ selectee.selected = doSelect;
127
+ // selectable (UN)SELECTING callback
128
+ if (doSelect) {
129
+ self._trigger("selecting", event, {
130
+ selecting: selectee.element
131
+ });
132
+ } else {
133
+ self._trigger("unselecting", event, {
134
+ unselecting: selectee.element
135
+ });
136
+ }
137
+ return false;
138
+ }
139
+ });
140
+
141
+ },
142
+
143
+ _mouseDrag: function(event) {
144
+ var self = this;
145
+ this.dragged = true;
146
+
147
+ if (this.options.disabled)
148
+ return;
149
+
150
+ var options = this.options;
151
+
152
+ var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY;
153
+ if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
154
+ if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
155
+ this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
156
+
157
+ this.selectees.each(function() {
158
+ var selectee = $.data(this, "selectable-item");
159
+ //prevent helper from being selected if appendTo: selectable
160
+ if (!selectee || selectee.element == self.element[0])
161
+ return;
162
+ var hit = false;
163
+ if (options.tolerance == 'touch') {
164
+ hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) );
165
+ } else if (options.tolerance == 'fit') {
166
+ hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2);
167
+ }
168
+
169
+ if (hit) {
170
+ // SELECT
171
+ if (selectee.selected) {
172
+ selectee.$element.removeClass('ui-selected');
173
+ selectee.selected = false;
174
+ }
175
+ if (selectee.unselecting) {
176
+ selectee.$element.removeClass('ui-unselecting');
177
+ selectee.unselecting = false;
178
+ }
179
+ if (!selectee.selecting) {
180
+ selectee.$element.addClass('ui-selecting');
181
+ selectee.selecting = true;
182
+ // selectable SELECTING callback
183
+ self._trigger("selecting", event, {
184
+ selecting: selectee.element
185
+ });
186
+ }
187
+ } else {
188
+ // UNSELECT
189
+ if (selectee.selecting) {
190
+ if (event.metaKey && selectee.startselected) {
191
+ selectee.$element.removeClass('ui-selecting');
192
+ selectee.selecting = false;
193
+ selectee.$element.addClass('ui-selected');
194
+ selectee.selected = true;
195
+ } else {
196
+ selectee.$element.removeClass('ui-selecting');
197
+ selectee.selecting = false;
198
+ if (selectee.startselected) {
199
+ selectee.$element.addClass('ui-unselecting');
200
+ selectee.unselecting = true;
201
+ }
202
+ // selectable UNSELECTING callback
203
+ self._trigger("unselecting", event, {
204
+ unselecting: selectee.element
205
+ });
206
+ }
207
+ }
208
+ if (selectee.selected) {
209
+ if (!event.metaKey && !selectee.startselected) {
210
+ selectee.$element.removeClass('ui-selected');
211
+ selectee.selected = false;
212
+
213
+ selectee.$element.addClass('ui-unselecting');
214
+ selectee.unselecting = true;
215
+ // selectable UNSELECTING callback
216
+ self._trigger("unselecting", event, {
217
+ unselecting: selectee.element
218
+ });
219
+ }
220
+ }
221
+ }
222
+ });
223
+
224
+ return false;
225
+ },
226
+
227
+ _mouseStop: function(event) {
228
+ var self = this;
229
+
230
+ this.dragged = false;
231
+
232
+ var options = this.options;
233
+
234
+ $('.ui-unselecting', this.element[0]).each(function() {
235
+ var selectee = $.data(this, "selectable-item");
236
+ selectee.$element.removeClass('ui-unselecting');
237
+ selectee.unselecting = false;
238
+ selectee.startselected = false;
239
+ self._trigger("unselected", event, {
240
+ unselected: selectee.element
241
+ });
242
+ });
243
+ $('.ui-selecting', this.element[0]).each(function() {
244
+ var selectee = $.data(this, "selectable-item");
245
+ selectee.$element.removeClass('ui-selecting').addClass('ui-selected');
246
+ selectee.selecting = false;
247
+ selectee.selected = true;
248
+ selectee.startselected = true;
249
+ self._trigger("selected", event, {
250
+ selected: selectee.element
251
+ });
252
+ });
253
+ this._trigger("stop", event);
254
+
255
+ this.helper.remove();
256
+
257
+ return false;
258
+ }
259
+
260
+ });
261
+
262
+ $.extend($.ui.selectable, {
263
+ version: "1.8.13"
264
+ });
265
+
266
+ })(jQuery);
@@ -0,0 +1,666 @@
1
+ /*
2
+ * jQuery UI Slider 1.8.13
3
+ *
4
+ * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
5
+ * Dual licensed under the MIT or GPL Version 2 licenses.
6
+ * http://jquery.org/license
7
+ *
8
+ * http://docs.jquery.com/UI/Slider
9
+ *
10
+ * Depends:
11
+ * jquery.ui.core.js
12
+ * jquery.ui.mouse.js
13
+ * jquery.ui.widget.js
14
+ */
15
+ (function( $, undefined ) {
16
+
17
+ // number of pages in a slider
18
+ // (how many times can you page up/down to go through the whole range)
19
+ var numPages = 5;
20
+
21
+ $.widget( "ui.slider", $.ui.mouse, {
22
+
23
+ widgetEventPrefix: "slide",
24
+
25
+ options: {
26
+ animate: false,
27
+ distance: 0,
28
+ max: 100,
29
+ min: 0,
30
+ orientation: "horizontal",
31
+ range: false,
32
+ step: 1,
33
+ value: 0,
34
+ values: null
35
+ },
36
+
37
+ _create: function() {
38
+ var self = this,
39
+ o = this.options,
40
+ existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ),
41
+ handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>",
42
+ handleCount = ( o.values && o.values.length ) || 1,
43
+ handles = [];
44
+
45
+ this._keySliding = false;
46
+ this._mouseSliding = false;
47
+ this._animateOff = true;
48
+ this._handleIndex = null;
49
+ this._detectOrientation();
50
+ this._mouseInit();
51
+
52
+ this.element
53
+ .addClass( "ui-slider" +
54
+ " ui-slider-" + this.orientation +
55
+ " ui-widget" +
56
+ " ui-widget-content" +
57
+ " ui-corner-all" +
58
+ ( o.disabled ? " ui-slider-disabled ui-disabled" : "" ) );
59
+
60
+ this.range = $([]);
61
+
62
+ if ( o.range ) {
63
+ if ( o.range === true ) {
64
+ if ( !o.values ) {
65
+ o.values = [ this._valueMin(), this._valueMin() ];
66
+ }
67
+ if ( o.values.length && o.values.length !== 2 ) {
68
+ o.values = [ o.values[0], o.values[0] ];
69
+ }
70
+ }
71
+
72
+ this.range = $( "<div></div>" )
73
+ .appendTo( this.element )
74
+ .addClass( "ui-slider-range" +
75
+ // note: this isn't the most fittingly semantic framework class for this element,
76
+ // but worked best visually with a variety of themes
77
+ " ui-widget-header" +
78
+ ( ( o.range === "min" || o.range === "max" ) ? " ui-slider-range-" + o.range : "" ) );
79
+ }
80
+
81
+ for ( var i = existingHandles.length; i < handleCount; i += 1 ) {
82
+ handles.push( handle );
83
+ }
84
+
85
+ this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( self.element ) );
86
+
87
+ this.handle = this.handles.eq( 0 );
88
+
89
+ this.handles.add( this.range ).filter( "a" )
90
+ .click(function( event ) {
91
+ event.preventDefault();
92
+ })
93
+ .hover(function() {
94
+ if ( !o.disabled ) {
95
+ $( this ).addClass( "ui-state-hover" );
96
+ }
97
+ }, function() {
98
+ $( this ).removeClass( "ui-state-hover" );
99
+ })
100
+ .focus(function() {
101
+ if ( !o.disabled ) {
102
+ $( ".ui-slider .ui-state-focus" ).removeClass( "ui-state-focus" );
103
+ $( this ).addClass( "ui-state-focus" );
104
+ } else {
105
+ $( this ).blur();
106
+ }
107
+ })
108
+ .blur(function() {
109
+ $( this ).removeClass( "ui-state-focus" );
110
+ });
111
+
112
+ this.handles.each(function( i ) {
113
+ $( this ).data( "index.ui-slider-handle", i );
114
+ });
115
+
116
+ this.handles
117
+ .keydown(function( event ) {
118
+ var ret = true,
119
+ index = $( this ).data( "index.ui-slider-handle" ),
120
+ allowed,
121
+ curVal,
122
+ newVal,
123
+ step;
124
+
125
+ if ( self.options.disabled ) {
126
+ return;
127
+ }
128
+
129
+ switch ( event.keyCode ) {
130
+ case $.ui.keyCode.HOME:
131
+ case $.ui.keyCode.END:
132
+ case $.ui.keyCode.PAGE_UP:
133
+ case $.ui.keyCode.PAGE_DOWN:
134
+ case $.ui.keyCode.UP:
135
+ case $.ui.keyCode.RIGHT:
136
+ case $.ui.keyCode.DOWN:
137
+ case $.ui.keyCode.LEFT:
138
+ ret = false;
139
+ if ( !self._keySliding ) {
140
+ self._keySliding = true;
141
+ $( this ).addClass( "ui-state-active" );
142
+ allowed = self._start( event, index );
143
+ if ( allowed === false ) {
144
+ return;
145
+ }
146
+ }
147
+ break;
148
+ }
149
+
150
+ step = self.options.step;
151
+ if ( self.options.values && self.options.values.length ) {
152
+ curVal = newVal = self.values( index );
153
+ } else {
154
+ curVal = newVal = self.value();
155
+ }
156
+
157
+ switch ( event.keyCode ) {
158
+ case $.ui.keyCode.HOME:
159
+ newVal = self._valueMin();
160
+ break;
161
+ case $.ui.keyCode.END:
162
+ newVal = self._valueMax();
163
+ break;
164
+ case $.ui.keyCode.PAGE_UP:
165
+ newVal = self._trimAlignValue( curVal + ( (self._valueMax() - self._valueMin()) / numPages ) );
166
+ break;
167
+ case $.ui.keyCode.PAGE_DOWN:
168
+ newVal = self._trimAlignValue( curVal - ( (self._valueMax() - self._valueMin()) / numPages ) );
169
+ break;
170
+ case $.ui.keyCode.UP:
171
+ case $.ui.keyCode.RIGHT:
172
+ if ( curVal === self._valueMax() ) {
173
+ return;
174
+ }
175
+ newVal = self._trimAlignValue( curVal + step );
176
+ break;
177
+ case $.ui.keyCode.DOWN:
178
+ case $.ui.keyCode.LEFT:
179
+ if ( curVal === self._valueMin() ) {
180
+ return;
181
+ }
182
+ newVal = self._trimAlignValue( curVal - step );
183
+ break;
184
+ }
185
+
186
+ self._slide( event, index, newVal );
187
+
188
+ return ret;
189
+
190
+ })
191
+ .keyup(function( event ) {
192
+ var index = $( this ).data( "index.ui-slider-handle" );
193
+
194
+ if ( self._keySliding ) {
195
+ self._keySliding = false;
196
+ self._stop( event, index );
197
+ self._change( event, index );
198
+ $( this ).removeClass( "ui-state-active" );
199
+ }
200
+
201
+ });
202
+
203
+ this._refreshValue();
204
+
205
+ this._animateOff = false;
206
+ },
207
+
208
+ destroy: function() {
209
+ this.handles.remove();
210
+ this.range.remove();
211
+
212
+ this.element
213
+ .removeClass( "ui-slider" +
214
+ " ui-slider-horizontal" +
215
+ " ui-slider-vertical" +
216
+ " ui-slider-disabled" +
217
+ " ui-widget" +
218
+ " ui-widget-content" +
219
+ " ui-corner-all" )
220
+ .removeData( "slider" )
221
+ .unbind( ".slider" );
222
+
223
+ this._mouseDestroy();
224
+
225
+ return this;
226
+ },
227
+
228
+ _mouseCapture: function( event ) {
229
+ var o = this.options,
230
+ position,
231
+ normValue,
232
+ distance,
233
+ closestHandle,
234
+ self,
235
+ index,
236
+ allowed,
237
+ offset,
238
+ mouseOverHandle;
239
+
240
+ if ( o.disabled ) {
241
+ return false;
242
+ }
243
+
244
+ this.elementSize = {
245
+ width: this.element.outerWidth(),
246
+ height: this.element.outerHeight()
247
+ };
248
+ this.elementOffset = this.element.offset();
249
+
250
+ position = { x: event.pageX, y: event.pageY };
251
+ normValue = this._normValueFromMouse( position );
252
+ distance = this._valueMax() - this._valueMin() + 1;
253
+ self = this;
254
+ this.handles.each(function( i ) {
255
+ var thisDistance = Math.abs( normValue - self.values(i) );
256
+ if ( distance > thisDistance ) {
257
+ distance = thisDistance;
258
+ closestHandle = $( this );
259
+ index = i;
260
+ }
261
+ });
262
+
263
+ // workaround for bug #3736 (if both handles of a range are at 0,
264
+ // the first is always used as the one with least distance,
265
+ // and moving it is obviously prevented by preventing negative ranges)
266
+ if( o.range === true && this.values(1) === o.min ) {
267
+ index += 1;
268
+ closestHandle = $( this.handles[index] );
269
+ }
270
+
271
+ allowed = this._start( event, index );
272
+ if ( allowed === false ) {
273
+ return false;
274
+ }
275
+ this._mouseSliding = true;
276
+
277
+ self._handleIndex = index;
278
+
279
+ closestHandle
280
+ .addClass( "ui-state-active" )
281
+ .focus();
282
+
283
+ offset = closestHandle.offset();
284
+ mouseOverHandle = !$( event.target ).parents().andSelf().is( ".ui-slider-handle" );
285
+ this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
286
+ left: event.pageX - offset.left - ( closestHandle.width() / 2 ),
287
+ top: event.pageY - offset.top -
288
+ ( closestHandle.height() / 2 ) -
289
+ ( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) -
290
+ ( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) +
291
+ ( parseInt( closestHandle.css("marginTop"), 10 ) || 0)
292
+ };
293
+
294
+ if ( !this.handles.hasClass( "ui-state-hover" ) ) {
295
+ this._slide( event, index, normValue );
296
+ }
297
+ this._animateOff = true;
298
+ return true;
299
+ },
300
+
301
+ _mouseStart: function( event ) {
302
+ return true;
303
+ },
304
+
305
+ _mouseDrag: function( event ) {
306
+ var position = { x: event.pageX, y: event.pageY },
307
+ normValue = this._normValueFromMouse( position );
308
+
309
+ this._slide( event, this._handleIndex, normValue );
310
+
311
+ return false;
312
+ },
313
+
314
+ _mouseStop: function( event ) {
315
+ this.handles.removeClass( "ui-state-active" );
316
+ this._mouseSliding = false;
317
+
318
+ this._stop( event, this._handleIndex );
319
+ this._change( event, this._handleIndex );
320
+
321
+ this._handleIndex = null;
322
+ this._clickOffset = null;
323
+ this._animateOff = false;
324
+
325
+ return false;
326
+ },
327
+
328
+ _detectOrientation: function() {
329
+ this.orientation = ( this.options.orientation === "vertical" ) ? "vertical" : "horizontal";
330
+ },
331
+
332
+ _normValueFromMouse: function( position ) {
333
+ var pixelTotal,
334
+ pixelMouse,
335
+ percentMouse,
336
+ valueTotal,
337
+ valueMouse;
338
+
339
+ if ( this.orientation === "horizontal" ) {
340
+ pixelTotal = this.elementSize.width;
341
+ pixelMouse = position.x - this.elementOffset.left - ( this._clickOffset ? this._clickOffset.left : 0 );
342
+ } else {
343
+ pixelTotal = this.elementSize.height;
344
+ pixelMouse = position.y - this.elementOffset.top - ( this._clickOffset ? this._clickOffset.top : 0 );
345
+ }
346
+
347
+ percentMouse = ( pixelMouse / pixelTotal );
348
+ if ( percentMouse > 1 ) {
349
+ percentMouse = 1;
350
+ }
351
+ if ( percentMouse < 0 ) {
352
+ percentMouse = 0;
353
+ }
354
+ if ( this.orientation === "vertical" ) {
355
+ percentMouse = 1 - percentMouse;
356
+ }
357
+
358
+ valueTotal = this._valueMax() - this._valueMin();
359
+ valueMouse = this._valueMin() + percentMouse * valueTotal;
360
+
361
+ return this._trimAlignValue( valueMouse );
362
+ },
363
+
364
+ _start: function( event, index ) {
365
+ var uiHash = {
366
+ handle: this.handles[ index ],
367
+ value: this.value()
368
+ };
369
+ if ( this.options.values && this.options.values.length ) {
370
+ uiHash.value = this.values( index );
371
+ uiHash.values = this.values();
372
+ }
373
+ return this._trigger( "start", event, uiHash );
374
+ },
375
+
376
+ _slide: function( event, index, newVal ) {
377
+ var otherVal,
378
+ newValues,
379
+ allowed;
380
+
381
+ if ( this.options.values && this.options.values.length ) {
382
+ otherVal = this.values( index ? 0 : 1 );
383
+
384
+ if ( ( this.options.values.length === 2 && this.options.range === true ) &&
385
+ ( ( index === 0 && newVal > otherVal) || ( index === 1 && newVal < otherVal ) )
386
+ ) {
387
+ newVal = otherVal;
388
+ }
389
+
390
+ if ( newVal !== this.values( index ) ) {
391
+ newValues = this.values();
392
+ newValues[ index ] = newVal;
393
+ // A slide can be canceled by returning false from the slide callback
394
+ allowed = this._trigger( "slide", event, {
395
+ handle: this.handles[ index ],
396
+ value: newVal,
397
+ values: newValues
398
+ } );
399
+ otherVal = this.values( index ? 0 : 1 );
400
+ if ( allowed !== false ) {
401
+ this.values( index, newVal, true );
402
+ }
403
+ }
404
+ } else {
405
+ if ( newVal !== this.value() ) {
406
+ // A slide can be canceled by returning false from the slide callback
407
+ allowed = this._trigger( "slide", event, {
408
+ handle: this.handles[ index ],
409
+ value: newVal
410
+ } );
411
+ if ( allowed !== false ) {
412
+ this.value( newVal );
413
+ }
414
+ }
415
+ }
416
+ },
417
+
418
+ _stop: function( event, index ) {
419
+ var uiHash = {
420
+ handle: this.handles[ index ],
421
+ value: this.value()
422
+ };
423
+ if ( this.options.values && this.options.values.length ) {
424
+ uiHash.value = this.values( index );
425
+ uiHash.values = this.values();
426
+ }
427
+
428
+ this._trigger( "stop", event, uiHash );
429
+ },
430
+
431
+ _change: function( event, index ) {
432
+ if ( !this._keySliding && !this._mouseSliding ) {
433
+ var uiHash = {
434
+ handle: this.handles[ index ],
435
+ value: this.value()
436
+ };
437
+ if ( this.options.values && this.options.values.length ) {
438
+ uiHash.value = this.values( index );
439
+ uiHash.values = this.values();
440
+ }
441
+
442
+ this._trigger( "change", event, uiHash );
443
+ }
444
+ },
445
+
446
+ value: function( newValue ) {
447
+ if ( arguments.length ) {
448
+ this.options.value = this._trimAlignValue( newValue );
449
+ this._refreshValue();
450
+ this._change( null, 0 );
451
+ return;
452
+ }
453
+
454
+ return this._value();
455
+ },
456
+
457
+ values: function( index, newValue ) {
458
+ var vals,
459
+ newValues,
460
+ i;
461
+
462
+ if ( arguments.length > 1 ) {
463
+ this.options.values[ index ] = this._trimAlignValue( newValue );
464
+ this._refreshValue();
465
+ this._change( null, index );
466
+ return;
467
+ }
468
+
469
+ if ( arguments.length ) {
470
+ if ( $.isArray( arguments[ 0 ] ) ) {
471
+ vals = this.options.values;
472
+ newValues = arguments[ 0 ];
473
+ for ( i = 0; i < vals.length; i += 1 ) {
474
+ vals[ i ] = this._trimAlignValue( newValues[ i ] );
475
+ this._change( null, i );
476
+ }
477
+ this._refreshValue();
478
+ } else {
479
+ if ( this.options.values && this.options.values.length ) {
480
+ return this._values( index );
481
+ } else {
482
+ return this.value();
483
+ }
484
+ }
485
+ } else {
486
+ return this._values();
487
+ }
488
+ },
489
+
490
+ _setOption: function( key, value ) {
491
+ var i,
492
+ valsLength = 0;
493
+
494
+ if ( $.isArray( this.options.values ) ) {
495
+ valsLength = this.options.values.length;
496
+ }
497
+
498
+ $.Widget.prototype._setOption.apply( this, arguments );
499
+
500
+ switch ( key ) {
501
+ case "disabled":
502
+ if ( value ) {
503
+ this.handles.filter( ".ui-state-focus" ).blur();
504
+ this.handles.removeClass( "ui-state-hover" );
505
+ this.handles.attr( "disabled", "disabled" );
506
+ this.element.addClass( "ui-disabled" );
507
+ } else {
508
+ this.handles.removeAttr( "disabled" );
509
+ this.element.removeClass( "ui-disabled" );
510
+ }
511
+ break;
512
+ case "orientation":
513
+ this._detectOrientation();
514
+ this.element
515
+ .removeClass( "ui-slider-horizontal ui-slider-vertical" )
516
+ .addClass( "ui-slider-" + this.orientation );
517
+ this._refreshValue();
518
+ break;
519
+ case "value":
520
+ this._animateOff = true;
521
+ this._refreshValue();
522
+ this._change( null, 0 );
523
+ this._animateOff = false;
524
+ break;
525
+ case "values":
526
+ this._animateOff = true;
527
+ this._refreshValue();
528
+ for ( i = 0; i < valsLength; i += 1 ) {
529
+ this._change( null, i );
530
+ }
531
+ this._animateOff = false;
532
+ break;
533
+ }
534
+ },
535
+
536
+ //internal value getter
537
+ // _value() returns value trimmed by min and max, aligned by step
538
+ _value: function() {
539
+ var val = this.options.value;
540
+ val = this._trimAlignValue( val );
541
+
542
+ return val;
543
+ },
544
+
545
+ //internal values getter
546
+ // _values() returns array of values trimmed by min and max, aligned by step
547
+ // _values( index ) returns single value trimmed by min and max, aligned by step
548
+ _values: function( index ) {
549
+ var val,
550
+ vals,
551
+ i;
552
+
553
+ if ( arguments.length ) {
554
+ val = this.options.values[ index ];
555
+ val = this._trimAlignValue( val );
556
+
557
+ return val;
558
+ } else {
559
+ // .slice() creates a copy of the array
560
+ // this copy gets trimmed by min and max and then returned
561
+ vals = this.options.values.slice();
562
+ for ( i = 0; i < vals.length; i+= 1) {
563
+ vals[ i ] = this._trimAlignValue( vals[ i ] );
564
+ }
565
+
566
+ return vals;
567
+ }
568
+ },
569
+
570
+ // returns the step-aligned value that val is closest to, between (inclusive) min and max
571
+ _trimAlignValue: function( val ) {
572
+ if ( val <= this._valueMin() ) {
573
+ return this._valueMin();
574
+ }
575
+ if ( val >= this._valueMax() ) {
576
+ return this._valueMax();
577
+ }
578
+ var step = ( this.options.step > 0 ) ? this.options.step : 1,
579
+ valModStep = (val - this._valueMin()) % step;
580
+ alignValue = val - valModStep;
581
+
582
+ if ( Math.abs(valModStep) * 2 >= step ) {
583
+ alignValue += ( valModStep > 0 ) ? step : ( -step );
584
+ }
585
+
586
+ // Since JavaScript has problems with large floats, round
587
+ // the final value to 5 digits after the decimal point (see #4124)
588
+ return parseFloat( alignValue.toFixed(5) );
589
+ },
590
+
591
+ _valueMin: function() {
592
+ return this.options.min;
593
+ },
594
+
595
+ _valueMax: function() {
596
+ return this.options.max;
597
+ },
598
+
599
+ _refreshValue: function() {
600
+ var oRange = this.options.range,
601
+ o = this.options,
602
+ self = this,
603
+ animate = ( !this._animateOff ) ? o.animate : false,
604
+ valPercent,
605
+ _set = {},
606
+ lastValPercent,
607
+ value,
608
+ valueMin,
609
+ valueMax;
610
+
611
+ if ( this.options.values && this.options.values.length ) {
612
+ this.handles.each(function( i, j ) {
613
+ valPercent = ( self.values(i) - self._valueMin() ) / ( self._valueMax() - self._valueMin() ) * 100;
614
+ _set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
615
+ $( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
616
+ if ( self.options.range === true ) {
617
+ if ( self.orientation === "horizontal" ) {
618
+ if ( i === 0 ) {
619
+ self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate );
620
+ }
621
+ if ( i === 1 ) {
622
+ self.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
623
+ }
624
+ } else {
625
+ if ( i === 0 ) {
626
+ self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate );
627
+ }
628
+ if ( i === 1 ) {
629
+ self.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
630
+ }
631
+ }
632
+ }
633
+ lastValPercent = valPercent;
634
+ });
635
+ } else {
636
+ value = this.value();
637
+ valueMin = this._valueMin();
638
+ valueMax = this._valueMax();
639
+ valPercent = ( valueMax !== valueMin ) ?
640
+ ( value - valueMin ) / ( valueMax - valueMin ) * 100 :
641
+ 0;
642
+ _set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
643
+ this.handle.stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
644
+
645
+ if ( oRange === "min" && this.orientation === "horizontal" ) {
646
+ this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { width: valPercent + "%" }, o.animate );
647
+ }
648
+ if ( oRange === "max" && this.orientation === "horizontal" ) {
649
+ this.range[ animate ? "animate" : "css" ]( { width: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
650
+ }
651
+ if ( oRange === "min" && this.orientation === "vertical" ) {
652
+ this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { height: valPercent + "%" }, o.animate );
653
+ }
654
+ if ( oRange === "max" && this.orientation === "vertical" ) {
655
+ this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
656
+ }
657
+ }
658
+ }
659
+
660
+ });
661
+
662
+ $.extend( $.ui.slider, {
663
+ version: "1.8.13"
664
+ });
665
+
666
+ }(jQuery));