fomantic-ui-sass 2.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +5 -0
  5. data/CHANGELOG.md +370 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +177 -0
  9. data/Rakefile +8 -0
  10. data/app/assets/fonts/semantic-ui/brand-icons.eot +0 -0
  11. data/app/assets/fonts/semantic-ui/brand-icons.svg +1008 -0
  12. data/app/assets/fonts/semantic-ui/brand-icons.ttf +0 -0
  13. data/app/assets/fonts/semantic-ui/brand-icons.woff +0 -0
  14. data/app/assets/fonts/semantic-ui/brand-icons.woff2 +0 -0
  15. data/app/assets/fonts/semantic-ui/icons.eot +0 -0
  16. data/app/assets/fonts/semantic-ui/icons.otf +0 -0
  17. data/app/assets/fonts/semantic-ui/icons.svg +1518 -0
  18. data/app/assets/fonts/semantic-ui/icons.ttf +0 -0
  19. data/app/assets/fonts/semantic-ui/icons.woff +0 -0
  20. data/app/assets/fonts/semantic-ui/icons.woff2 +0 -0
  21. data/app/assets/fonts/semantic-ui/outline-icons.eot +0 -0
  22. data/app/assets/fonts/semantic-ui/outline-icons.svg +366 -0
  23. data/app/assets/fonts/semantic-ui/outline-icons.ttf +0 -0
  24. data/app/assets/fonts/semantic-ui/outline-icons.woff +0 -0
  25. data/app/assets/fonts/semantic-ui/outline-icons.woff2 +0 -0
  26. data/app/assets/images/semantic-ui/flags.png +0 -0
  27. data/app/assets/javascripts/semantic-ui.js +27 -0
  28. data/app/assets/javascripts/semantic-ui/accordion.js +613 -0
  29. data/app/assets/javascripts/semantic-ui/api.js +1167 -0
  30. data/app/assets/javascripts/semantic-ui/calendar.js +1476 -0
  31. data/app/assets/javascripts/semantic-ui/checkbox.js +828 -0
  32. data/app/assets/javascripts/semantic-ui/colorize.js +280 -0
  33. data/app/assets/javascripts/semantic-ui/dimmer.js +735 -0
  34. data/app/assets/javascripts/semantic-ui/dropdown.js +4030 -0
  35. data/app/assets/javascripts/semantic-ui/embed.js +706 -0
  36. data/app/assets/javascripts/semantic-ui/form.js +1707 -0
  37. data/app/assets/javascripts/semantic-ui/modal.js +1090 -0
  38. data/app/assets/javascripts/semantic-ui/nag.js +507 -0
  39. data/app/assets/javascripts/semantic-ui/popup.js +1532 -0
  40. data/app/assets/javascripts/semantic-ui/progress.js +923 -0
  41. data/app/assets/javascripts/semantic-ui/range.js +278 -0
  42. data/app/assets/javascripts/semantic-ui/rating.js +511 -0
  43. data/app/assets/javascripts/semantic-ui/search.js +1515 -0
  44. data/app/assets/javascripts/semantic-ui/shape.js +921 -0
  45. data/app/assets/javascripts/semantic-ui/sidebar.js +1033 -0
  46. data/app/assets/javascripts/semantic-ui/site.js +490 -0
  47. data/app/assets/javascripts/semantic-ui/state.js +708 -0
  48. data/app/assets/javascripts/semantic-ui/sticky.js +959 -0
  49. data/app/assets/javascripts/semantic-ui/tab.js +952 -0
  50. data/app/assets/javascripts/semantic-ui/toast.js +592 -0
  51. data/app/assets/javascripts/semantic-ui/transition.js +1106 -0
  52. data/app/assets/javascripts/semantic-ui/video.js +532 -0
  53. data/app/assets/javascripts/semantic-ui/visibility.js +1311 -0
  54. data/app/assets/javascripts/semantic-ui/visit.js +525 -0
  55. data/app/assets/stylesheets/semantic-ui.scss +5 -0
  56. data/app/assets/stylesheets/semantic-ui/collections/_all.scss +6 -0
  57. data/app/assets/stylesheets/semantic-ui/collections/_breadcrumb.scss +124 -0
  58. data/app/assets/stylesheets/semantic-ui/collections/_form.scss +1158 -0
  59. data/app/assets/stylesheets/semantic-ui/collections/_grid.scss +2093 -0
  60. data/app/assets/stylesheets/semantic-ui/collections/_menu.scss +2193 -0
  61. data/app/assets/stylesheets/semantic-ui/collections/_message.scss +606 -0
  62. data/app/assets/stylesheets/semantic-ui/collections/_table.scss +1117 -0
  63. data/app/assets/stylesheets/semantic-ui/elements/_all.scss +16 -0
  64. data/app/assets/stylesheets/semantic-ui/elements/_button.scss +4530 -0
  65. data/app/assets/stylesheets/semantic-ui/elements/_container.scss +145 -0
  66. data/app/assets/stylesheets/semantic-ui/elements/_divider.scss +259 -0
  67. data/app/assets/stylesheets/semantic-ui/elements/_flag.scss +1036 -0
  68. data/app/assets/stylesheets/semantic-ui/elements/_header.scss +762 -0
  69. data/app/assets/stylesheets/semantic-ui/elements/_icon.scss +6330 -0
  70. data/app/assets/stylesheets/semantic-ui/elements/_image.scss +310 -0
  71. data/app/assets/stylesheets/semantic-ui/elements/_input.scss +519 -0
  72. data/app/assets/stylesheets/semantic-ui/elements/_label.scss +1395 -0
  73. data/app/assets/stylesheets/semantic-ui/elements/_list.scss +959 -0
  74. data/app/assets/stylesheets/semantic-ui/elements/_loader.scss +458 -0
  75. data/app/assets/stylesheets/semantic-ui/elements/_placeholder.scss +242 -0
  76. data/app/assets/stylesheets/semantic-ui/elements/_rail.scss +152 -0
  77. data/app/assets/stylesheets/semantic-ui/elements/_reveal.scss +295 -0
  78. data/app/assets/stylesheets/semantic-ui/elements/_segment.scss +884 -0
  79. data/app/assets/stylesheets/semantic-ui/elements/_step.scss +675 -0
  80. data/app/assets/stylesheets/semantic-ui/globals/_all.scss +3 -0
  81. data/app/assets/stylesheets/semantic-ui/globals/_reset.scss +485 -0
  82. data/app/assets/stylesheets/semantic-ui/globals/_site.scss +206 -0
  83. data/app/assets/stylesheets/semantic-ui/globals/_variables.scss +4 -0
  84. data/app/assets/stylesheets/semantic-ui/modules/_accordion.scss +247 -0
  85. data/app/assets/stylesheets/semantic-ui/modules/_all.scss +20 -0
  86. data/app/assets/stylesheets/semantic-ui/modules/_calendar.scss +165 -0
  87. data/app/assets/stylesheets/semantic-ui/modules/_checkbox.scss +718 -0
  88. data/app/assets/stylesheets/semantic-ui/modules/_dimmer.scss +464 -0
  89. data/app/assets/stylesheets/semantic-ui/modules/_dropdown.scss +1745 -0
  90. data/app/assets/stylesheets/semantic-ui/modules/_embed.scss +165 -0
  91. data/app/assets/stylesheets/semantic-ui/modules/_modal.scss +646 -0
  92. data/app/assets/stylesheets/semantic-ui/modules/_nag.scss +148 -0
  93. data/app/assets/stylesheets/semantic-ui/modules/_popup.scss +789 -0
  94. data/app/assets/stylesheets/semantic-ui/modules/_progress.scss +523 -0
  95. data/app/assets/stylesheets/semantic-ui/modules/_range.scss +192 -0
  96. data/app/assets/stylesheets/semantic-ui/modules/_rating.scss +263 -0
  97. data/app/assets/stylesheets/semantic-ui/modules/_search.scss +445 -0
  98. data/app/assets/stylesheets/semantic-ui/modules/_shape.scss +154 -0
  99. data/app/assets/stylesheets/semantic-ui/modules/_sidebar.scss +626 -0
  100. data/app/assets/stylesheets/semantic-ui/modules/_sticky.scss +78 -0
  101. data/app/assets/stylesheets/semantic-ui/modules/_tab.scss +92 -0
  102. data/app/assets/stylesheets/semantic-ui/modules/_toast.scss +291 -0
  103. data/app/assets/stylesheets/semantic-ui/modules/_transition.scss +2059 -0
  104. data/app/assets/stylesheets/semantic-ui/modules/_video.scss +125 -0
  105. data/app/assets/stylesheets/semantic-ui/views/_ad.scss +275 -0
  106. data/app/assets/stylesheets/semantic-ui/views/_all.scss +6 -0
  107. data/app/assets/stylesheets/semantic-ui/views/_card.scss +1124 -0
  108. data/app/assets/stylesheets/semantic-ui/views/_comment.scss +296 -0
  109. data/app/assets/stylesheets/semantic-ui/views/_feed.scss +314 -0
  110. data/app/assets/stylesheets/semantic-ui/views/_item.scss +555 -0
  111. data/app/assets/stylesheets/semantic-ui/views/_statistic.scss +583 -0
  112. data/app/helpers/semantic_breadcrumbs_helper.rb +10 -0
  113. data/app/helpers/semantic_flash_helper.rb +22 -0
  114. data/app/helpers/semantic_icon_helper.rb +8 -0
  115. data/app/views/semantic/_breadcrumbs.html.erb +12 -0
  116. data/fomantic-ui-sass.gemspec +31 -0
  117. data/lib/fomantic-ui-sass.rb +62 -0
  118. data/lib/fomantic/ui/sass/breadcrumbs.rb +41 -0
  119. data/lib/fomantic/ui/sass/engine.rb +23 -0
  120. data/lib/fomantic/ui/sass/version.rb +8 -0
  121. data/spec/dummy/README.rdoc +28 -0
  122. data/spec/dummy/Rakefile +6 -0
  123. data/spec/dummy/app/assets/images/.keep +0 -0
  124. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  125. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  126. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  127. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  128. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  129. data/spec/dummy/app/mailers/.keep +0 -0
  130. data/spec/dummy/app/models/.keep +0 -0
  131. data/spec/dummy/app/models/concerns/.keep +0 -0
  132. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  133. data/spec/dummy/bin/bundle +3 -0
  134. data/spec/dummy/bin/rails +4 -0
  135. data/spec/dummy/bin/rake +4 -0
  136. data/spec/dummy/config.ru +4 -0
  137. data/spec/dummy/config/application.rb +28 -0
  138. data/spec/dummy/config/boot.rb +5 -0
  139. data/spec/dummy/config/environment.rb +5 -0
  140. data/spec/dummy/config/environments/development.rb +29 -0
  141. data/spec/dummy/config/environments/production.rb +80 -0
  142. data/spec/dummy/config/environments/test.rb +36 -0
  143. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  144. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  145. data/spec/dummy/config/initializers/inflections.rb +16 -0
  146. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  147. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  148. data/spec/dummy/config/initializers/session_store.rb +3 -0
  149. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  150. data/spec/dummy/config/locales/en.yml +23 -0
  151. data/spec/dummy/config/routes.rb +2 -0
  152. data/spec/dummy/lib/assets/.keep +0 -0
  153. data/spec/dummy/log/.keep +0 -0
  154. data/spec/dummy/public/404.html +58 -0
  155. data/spec/dummy/public/422.html +58 -0
  156. data/spec/dummy/public/500.html +57 -0
  157. data/spec/dummy/public/favicon.ico +0 -0
  158. data/spec/helpers/semantic_breadcrumbs_helper_spec.rb +38 -0
  159. data/spec/helpers/semantic_flash_helper_spec.rb +36 -0
  160. data/spec/helpers/semantic_icon_helper_spec.rb +48 -0
  161. data/spec/spec_helper.rb +17 -0
  162. data/tasks/converter.rb +216 -0
  163. data/templates/project/manifest.rb +29 -0
  164. data/templates/project/styles.scss +1 -0
  165. metadata +390 -0
@@ -0,0 +1,278 @@
1
+ /*!
2
+ * # Semantic UI - Range
3
+ * http://github.com/semantic-org/semantic-ui/
4
+ *
5
+ *
6
+ * Released under the MIT license
7
+ * http://opensource.org/licenses/MIT
8
+ *
9
+ */
10
+
11
+ ;(function ( $, window, document, undefined ) {
12
+
13
+ "use strict";
14
+
15
+ $.fn.range = function(parameters) {
16
+
17
+ var
18
+ $allModules = $(this),
19
+
20
+ offset = 10,
21
+
22
+ query = arguments[0],
23
+ methodInvoked = (typeof query == 'string'),
24
+ queryArguments = [].slice.call(arguments, 1)
25
+ ;
26
+
27
+ $allModules
28
+ .each(function() {
29
+
30
+ var
31
+ settings = ( $.isPlainObject(parameters) )
32
+ ? $.extend(true, {}, $.fn.range.settings, parameters)
33
+ : $.extend({}, $.fn.range.settings),
34
+
35
+ namespace = settings.namespace,
36
+ min = settings.min,
37
+ max = settings.max,
38
+ step = settings.step,
39
+ start = settings.start,
40
+ input = settings.input,
41
+
42
+ eventNamespace = '.' + namespace,
43
+ moduleNamespace = 'module-' + namespace,
44
+
45
+ $module = $(this),
46
+
47
+ element = this,
48
+ instance = $module.data(moduleNamespace),
49
+
50
+ inner,
51
+ thumb,
52
+ trackLeft,
53
+ precision,
54
+
55
+ module
56
+ ;
57
+
58
+ module = {
59
+
60
+ initialize: function() {
61
+ module.instantiate();
62
+ module.sanitize();
63
+ },
64
+
65
+ instantiate: function() {
66
+ instance = module;
67
+ $module
68
+ .data(moduleNamespace, module)
69
+ ;
70
+ $(element).html("<div class='inner'><div class='track'></div><div class='track-fill'></div><div class='thumb'></div></div>");
71
+ inner = $(element).children('.inner')[0];
72
+ thumb = $(element).find('.thumb')[0];
73
+ trackLeft = $(element).find('.track-fill')[0];
74
+ // find precision of step, used in calculating the value
75
+ module.determinePrecision();
76
+ // set start location
77
+ module.setValuePosition(settings.start);
78
+ // event listeners
79
+ $(element).find('.track, .thumb, .inner').on('mousedown', function(event) {
80
+ event.stopImmediatePropagation();
81
+ event.preventDefault();
82
+ $(this).closest(".range").trigger('mousedown', event);
83
+ });
84
+ $(element).find('.track, .thumb, .inner').on('touchstart', function(event) {
85
+ event.stopImmediatePropagation();
86
+ event.preventDefault();
87
+ $(this).closest(".range").trigger('touchstart', event);
88
+ });
89
+ $(element).on('mousedown', function(event, originalEvent) {
90
+ module.rangeMousedown(event, false, originalEvent);
91
+ });
92
+ $(element).on('touchstart', function(event, originalEvent) {
93
+ module.rangeMousedown(event, true, originalEvent);
94
+ });
95
+ module.addVisibilityListener(element);
96
+ },
97
+
98
+ sanitize: function() {
99
+ if (typeof settings.min != 'number') {
100
+ settings.min = parseInt(settings.min) || 0;
101
+ }
102
+ if (typeof settings.max != 'number') {
103
+ settings.max = parseInt(settings.max) || false;
104
+ }
105
+ if (typeof settings.start != 'number') {
106
+ settings.start = parseInt(settings.start) || 0;
107
+ }
108
+ },
109
+
110
+ determinePrecision: function() {
111
+ var split = String(settings.step).split('.');
112
+ var decimalPlaces;
113
+ if(split.length == 2) {
114
+ decimalPlaces = split[1].length;
115
+ } else {
116
+ decimalPlaces = 0;
117
+ }
118
+ precision = Math.pow(10, decimalPlaces);
119
+ },
120
+
121
+ determineValue: function(startPos, endPos, currentPos) {
122
+ var ratio = (currentPos - startPos) / (endPos - startPos);
123
+ var range = settings.max - settings.min;
124
+ var difference = Math.round(ratio * range / step) * step;
125
+ // Use precision to avoid ugly Javascript floating point rounding issues
126
+ // (like 35 * .01 = 0.35000000000000003)
127
+ difference = Math.round(difference * precision) / precision;
128
+ return difference + settings.min;
129
+ },
130
+
131
+ determinePosition: function(value) {
132
+ var ratio = (value - settings.min) / (settings.max - settings.min);
133
+ return Math.round(ratio * $(inner).width()) + $(trackLeft).position().left - offset;
134
+ },
135
+
136
+ setValue: function(newValue, triggeredByUser) {
137
+ if(typeof triggeredByUser === 'undefined') {
138
+ triggeredByUser = true;
139
+ }
140
+ if(settings.input) {
141
+ $(settings.input).val(newValue);
142
+ }
143
+ if(settings.onChange) {
144
+ settings.onChange(newValue, {triggeredByUser: triggeredByUser});
145
+ }
146
+ },
147
+
148
+ setPosition: function(value) {
149
+ $(thumb).css({left: String(value) + 'px'});
150
+ $(trackLeft).css({width: String(value + offset) + 'px'});
151
+ },
152
+
153
+ rangeMousedown: function(mdEvent, isTouch, originalEvent) {
154
+ if( !$(element).hasClass('disabled') ) {
155
+ mdEvent.preventDefault();
156
+ var left = $(inner).offset().left;
157
+ var right = left + $(inner).width();
158
+ var pageX;
159
+ if(isTouch) {
160
+ pageX = originalEvent.originalEvent.touches[0].pageX;
161
+ } else {
162
+ pageX = (typeof mdEvent.pageX != 'undefined') ? mdEvent.pageX : originalEvent.pageX;
163
+ }
164
+ var value = module.determineValue(left, right, pageX);
165
+ if(pageX >= left && pageX <= right) {
166
+ module.setPosition(pageX - left - offset);
167
+ module.setValue(value);
168
+ }
169
+ var rangeMousemove = function(mmEvent) {
170
+ mmEvent.preventDefault();
171
+ if(isTouch) {
172
+ pageX = mmEvent.originalEvent.touches[0].pageX;
173
+ } else {
174
+ pageX = mmEvent.pageX;
175
+ }
176
+ value = module.determineValue(left, right, pageX);
177
+ if(pageX >= left && pageX <= right) {
178
+ if(value >= settings.min && value <= settings.max) {
179
+ module.setPosition(pageX - left - offset);
180
+ module.setValue(value);
181
+ }
182
+ }
183
+ }
184
+ var rangeMouseup = function(muEvent) {
185
+ if(isTouch) {
186
+ $(document).off('touchmove', rangeMousemove);
187
+ $(document).off('touchend', rangeMouseup);
188
+ } else {
189
+ $(document).off('mousemove', rangeMousemove);
190
+ $(document).off('mouseup', rangeMouseup);
191
+ }
192
+ }
193
+ if(isTouch) {
194
+ $(document).on('touchmove', rangeMousemove);
195
+ $(document).on('touchend', rangeMouseup);
196
+ }
197
+ else {
198
+ $(document).on('mousemove', rangeMousemove);
199
+ $(document).on('mouseup', rangeMouseup);
200
+ }
201
+ }
202
+ },
203
+
204
+ setValuePosition: function(val, triggeredByUser) {
205
+ if(typeof triggeredByUser === 'undefined') {
206
+ triggeredByUser = true;
207
+ }
208
+ var position = module.determinePosition(val);
209
+ module.setPosition(position);
210
+ module.setValue(val, triggeredByUser);
211
+ },
212
+
213
+ invoke: function(query) {
214
+ switch(query) {
215
+ case 'set value':
216
+ if(queryArguments.length > 0) {
217
+ instance.setValuePosition(queryArguments[0], false);
218
+ }
219
+ break;
220
+ }
221
+ },
222
+
223
+ addVisibilityListener: function(elem) {
224
+
225
+ // Add a mutation observer (https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
226
+ // to detect when root invisible element is behing shown in order to initialize the thumb correctly
227
+ // when position and offets are available (https://stackoverflow.com/a/5974377)
228
+
229
+ var observer = new MutationObserver(function(mutationList) {
230
+ if ($(elem).is(':visible')) {
231
+ observer.disconnect(); // Avoid infinite recursion because « module.setValuePosition » will trigger this observer
232
+ module.setValuePosition(settings.start);
233
+ }
234
+ });
235
+
236
+ var closestHiddenParent = $(elem).parentsUntil(':visible');
237
+
238
+ if (closestHiddenParent.length != 0) {
239
+ observer.observe(closestHiddenParent[closestHiddenParent.length - 1], {attributes: true});
240
+ }
241
+ },
242
+
243
+ };
244
+
245
+ if(methodInvoked) {
246
+ if(instance === undefined) {
247
+ module.initialize();
248
+ }
249
+ module.invoke(query);
250
+ }
251
+ else {
252
+ module.initialize();
253
+ }
254
+
255
+ })
256
+ ;
257
+
258
+ return this;
259
+
260
+ };
261
+
262
+ $.fn.range.settings = {
263
+
264
+ name : 'Range',
265
+ namespace : 'range',
266
+
267
+ min : 0,
268
+ max : false,
269
+ step : 1,
270
+ start : 0,
271
+ input : false,
272
+
273
+ onChange : function(value){},
274
+
275
+ };
276
+
277
+
278
+ })( jQuery, window, document );
@@ -0,0 +1,511 @@
1
+ /*!
2
+ * # Semantic UI - Rating
3
+ * http://github.com/semantic-org/semantic-ui/
4
+ *
5
+ *
6
+ * Released under the MIT license
7
+ * http://opensource.org/licenses/MIT
8
+ *
9
+ */
10
+
11
+ ;(function ($, window, document, undefined) {
12
+
13
+ 'use strict';
14
+
15
+ window = (typeof window != 'undefined' && window.Math == Math)
16
+ ? window
17
+ : (typeof self != 'undefined' && self.Math == Math)
18
+ ? self
19
+ : Function('return this')()
20
+ ;
21
+
22
+ $.fn.rating = function(parameters) {
23
+ var
24
+ $allModules = $(this),
25
+ moduleSelector = $allModules.selector || '',
26
+
27
+ time = new Date().getTime(),
28
+ performance = [],
29
+
30
+ query = arguments[0],
31
+ methodInvoked = (typeof query == 'string'),
32
+ queryArguments = [].slice.call(arguments, 1),
33
+ returnedValue
34
+ ;
35
+ $allModules
36
+ .each(function() {
37
+ var
38
+ settings = ( $.isPlainObject(parameters) )
39
+ ? $.extend(true, {}, $.fn.rating.settings, parameters)
40
+ : $.extend({}, $.fn.rating.settings),
41
+
42
+ namespace = settings.namespace,
43
+ className = settings.className,
44
+ metadata = settings.metadata,
45
+ selector = settings.selector,
46
+ error = settings.error,
47
+
48
+ eventNamespace = '.' + namespace,
49
+ moduleNamespace = 'module-' + namespace,
50
+
51
+ element = this,
52
+ instance = $(this).data(moduleNamespace),
53
+
54
+ $module = $(this),
55
+ $icon = $module.find(selector.icon),
56
+
57
+ initialLoad,
58
+ module
59
+ ;
60
+
61
+ module = {
62
+
63
+ initialize: function() {
64
+ module.verbose('Initializing rating module', settings);
65
+
66
+ if($icon.length === 0) {
67
+ module.setup.layout();
68
+ }
69
+
70
+ if(settings.interactive && !module.is.disabled()) {
71
+ module.enable();
72
+ }
73
+ else {
74
+ module.disable();
75
+ }
76
+ module.set.initialLoad();
77
+ module.set.rating( module.get.initialRating() );
78
+ module.remove.initialLoad();
79
+ module.instantiate();
80
+ },
81
+
82
+ instantiate: function() {
83
+ module.verbose('Instantiating module', settings);
84
+ instance = module;
85
+ $module
86
+ .data(moduleNamespace, module)
87
+ ;
88
+ },
89
+
90
+ destroy: function() {
91
+ module.verbose('Destroying previous instance', instance);
92
+ module.remove.events();
93
+ $module
94
+ .removeData(moduleNamespace)
95
+ ;
96
+ },
97
+
98
+ refresh: function() {
99
+ $icon = $module.find(selector.icon);
100
+ },
101
+
102
+ setup: {
103
+ layout: function() {
104
+ var
105
+ maxRating = module.get.maxRating(),
106
+ html = $.fn.rating.settings.templates.icon(maxRating)
107
+ ;
108
+ module.debug('Generating icon html dynamically');
109
+ $module
110
+ .html(html)
111
+ ;
112
+ module.refresh();
113
+ }
114
+ },
115
+
116
+ event: {
117
+ mouseenter: function() {
118
+ var
119
+ $activeIcon = $(this)
120
+ ;
121
+ $activeIcon
122
+ .nextAll()
123
+ .removeClass(className.selected)
124
+ ;
125
+ $module
126
+ .addClass(className.selected)
127
+ ;
128
+ $activeIcon
129
+ .addClass(className.selected)
130
+ .prevAll()
131
+ .addClass(className.selected)
132
+ ;
133
+ },
134
+ mouseleave: function() {
135
+ $module
136
+ .removeClass(className.selected)
137
+ ;
138
+ $icon
139
+ .removeClass(className.selected)
140
+ ;
141
+ },
142
+ click: function() {
143
+ var
144
+ $activeIcon = $(this),
145
+ currentRating = module.get.rating(),
146
+ rating = $icon.index($activeIcon) + 1,
147
+ canClear = (settings.clearable == 'auto')
148
+ ? ($icon.length === 1)
149
+ : settings.clearable
150
+ ;
151
+ if(canClear && currentRating == rating) {
152
+ module.clearRating();
153
+ }
154
+ else {
155
+ module.set.rating( rating );
156
+ }
157
+ }
158
+ },
159
+
160
+ clearRating: function() {
161
+ module.debug('Clearing current rating');
162
+ module.set.rating(0);
163
+ },
164
+
165
+ bind: {
166
+ events: function() {
167
+ module.verbose('Binding events');
168
+ $module
169
+ .on('mouseenter' + eventNamespace, selector.icon, module.event.mouseenter)
170
+ .on('mouseleave' + eventNamespace, selector.icon, module.event.mouseleave)
171
+ .on('click' + eventNamespace, selector.icon, module.event.click)
172
+ ;
173
+ }
174
+ },
175
+
176
+ remove: {
177
+ events: function() {
178
+ module.verbose('Removing events');
179
+ $module
180
+ .off(eventNamespace)
181
+ ;
182
+ },
183
+ initialLoad: function() {
184
+ initialLoad = false;
185
+ }
186
+ },
187
+
188
+ enable: function() {
189
+ module.debug('Setting rating to interactive mode');
190
+ module.bind.events();
191
+ $module
192
+ .removeClass(className.disabled)
193
+ ;
194
+ },
195
+
196
+ disable: function() {
197
+ module.debug('Setting rating to read-only mode');
198
+ module.remove.events();
199
+ $module
200
+ .addClass(className.disabled)
201
+ ;
202
+ },
203
+
204
+ is: {
205
+ initialLoad: function() {
206
+ return initialLoad;
207
+ },
208
+ disabled: function() {
209
+ return $module.hasClass(className.disabled);
210
+ }
211
+ },
212
+
213
+ get: {
214
+ initialRating: function() {
215
+ if($module.data(metadata.rating) !== undefined) {
216
+ $module.removeData(metadata.rating);
217
+ return $module.data(metadata.rating);
218
+ }
219
+ return settings.initialRating;
220
+ },
221
+ maxRating: function() {
222
+ if($module.data(metadata.maxRating) !== undefined) {
223
+ $module.removeData(metadata.maxRating);
224
+ return $module.data(metadata.maxRating);
225
+ }
226
+ return settings.maxRating;
227
+ },
228
+ rating: function() {
229
+ var
230
+ currentRating = $icon.filter('.' + className.active).length
231
+ ;
232
+ module.verbose('Current rating retrieved', currentRating);
233
+ return currentRating;
234
+ }
235
+ },
236
+
237
+ set: {
238
+ rating: function(rating) {
239
+ var
240
+ ratingIndex = (rating - 1 >= 0)
241
+ ? (rating - 1)
242
+ : 0,
243
+ $activeIcon = $icon.eq(ratingIndex)
244
+ ;
245
+ $module
246
+ .removeClass(className.selected)
247
+ ;
248
+ $icon
249
+ .removeClass(className.selected)
250
+ .removeClass(className.active)
251
+ ;
252
+ if(rating > 0) {
253
+ module.verbose('Setting current rating to', rating);
254
+ $activeIcon
255
+ .prevAll()
256
+ .addBack()
257
+ .addClass(className.active)
258
+ ;
259
+ }
260
+ if(!module.is.initialLoad()) {
261
+ settings.onRate.call(element, rating);
262
+ }
263
+ },
264
+ initialLoad: function() {
265
+ initialLoad = true;
266
+ }
267
+ },
268
+
269
+ setting: function(name, value) {
270
+ module.debug('Changing setting', name, value);
271
+ if( $.isPlainObject(name) ) {
272
+ $.extend(true, settings, name);
273
+ }
274
+ else if(value !== undefined) {
275
+ if($.isPlainObject(settings[name])) {
276
+ $.extend(true, settings[name], value);
277
+ }
278
+ else {
279
+ settings[name] = value;
280
+ }
281
+ }
282
+ else {
283
+ return settings[name];
284
+ }
285
+ },
286
+ internal: function(name, value) {
287
+ if( $.isPlainObject(name) ) {
288
+ $.extend(true, module, name);
289
+ }
290
+ else if(value !== undefined) {
291
+ module[name] = value;
292
+ }
293
+ else {
294
+ return module[name];
295
+ }
296
+ },
297
+ debug: function() {
298
+ if(!settings.silent && settings.debug) {
299
+ if(settings.performance) {
300
+ module.performance.log(arguments);
301
+ }
302
+ else {
303
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
304
+ module.debug.apply(console, arguments);
305
+ }
306
+ }
307
+ },
308
+ verbose: function() {
309
+ if(!settings.silent && settings.verbose && settings.debug) {
310
+ if(settings.performance) {
311
+ module.performance.log(arguments);
312
+ }
313
+ else {
314
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
315
+ module.verbose.apply(console, arguments);
316
+ }
317
+ }
318
+ },
319
+ error: function() {
320
+ if(!settings.silent) {
321
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
322
+ module.error.apply(console, arguments);
323
+ }
324
+ },
325
+ performance: {
326
+ log: function(message) {
327
+ var
328
+ currentTime,
329
+ executionTime,
330
+ previousTime
331
+ ;
332
+ if(settings.performance) {
333
+ currentTime = new Date().getTime();
334
+ previousTime = time || currentTime;
335
+ executionTime = currentTime - previousTime;
336
+ time = currentTime;
337
+ performance.push({
338
+ 'Name' : message[0],
339
+ 'Arguments' : [].slice.call(message, 1) || '',
340
+ 'Element' : element,
341
+ 'Execution Time' : executionTime
342
+ });
343
+ }
344
+ clearTimeout(module.performance.timer);
345
+ module.performance.timer = setTimeout(module.performance.display, 500);
346
+ },
347
+ display: function() {
348
+ var
349
+ title = settings.name + ':',
350
+ totalTime = 0
351
+ ;
352
+ time = false;
353
+ clearTimeout(module.performance.timer);
354
+ $.each(performance, function(index, data) {
355
+ totalTime += data['Execution Time'];
356
+ });
357
+ title += ' ' + totalTime + 'ms';
358
+ if(moduleSelector) {
359
+ title += ' \'' + moduleSelector + '\'';
360
+ }
361
+ if($allModules.length > 1) {
362
+ title += ' ' + '(' + $allModules.length + ')';
363
+ }
364
+ if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
365
+ console.groupCollapsed(title);
366
+ if(console.table) {
367
+ console.table(performance);
368
+ }
369
+ else {
370
+ $.each(performance, function(index, data) {
371
+ console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
372
+ });
373
+ }
374
+ console.groupEnd();
375
+ }
376
+ performance = [];
377
+ }
378
+ },
379
+ invoke: function(query, passedArguments, context) {
380
+ var
381
+ object = instance,
382
+ maxDepth,
383
+ found,
384
+ response
385
+ ;
386
+ passedArguments = passedArguments || queryArguments;
387
+ context = element || context;
388
+ if(typeof query == 'string' && object !== undefined) {
389
+ query = query.split(/[\. ]/);
390
+ maxDepth = query.length - 1;
391
+ $.each(query, function(depth, value) {
392
+ var camelCaseValue = (depth != maxDepth)
393
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
394
+ : query
395
+ ;
396
+ if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
397
+ object = object[camelCaseValue];
398
+ }
399
+ else if( object[camelCaseValue] !== undefined ) {
400
+ found = object[camelCaseValue];
401
+ return false;
402
+ }
403
+ else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
404
+ object = object[value];
405
+ }
406
+ else if( object[value] !== undefined ) {
407
+ found = object[value];
408
+ return false;
409
+ }
410
+ else {
411
+ return false;
412
+ }
413
+ });
414
+ }
415
+ if ( $.isFunction( found ) ) {
416
+ response = found.apply(context, passedArguments);
417
+ }
418
+ else if(found !== undefined) {
419
+ response = found;
420
+ }
421
+ if($.isArray(returnedValue)) {
422
+ returnedValue.push(response);
423
+ }
424
+ else if(returnedValue !== undefined) {
425
+ returnedValue = [returnedValue, response];
426
+ }
427
+ else if(response !== undefined) {
428
+ returnedValue = response;
429
+ }
430
+ return found;
431
+ }
432
+ };
433
+ if(methodInvoked) {
434
+ if(instance === undefined) {
435
+ module.initialize();
436
+ }
437
+ module.invoke(query);
438
+ }
439
+ else {
440
+ if(instance !== undefined) {
441
+ instance.invoke('destroy');
442
+ }
443
+ module.initialize();
444
+ }
445
+ })
446
+ ;
447
+
448
+ return (returnedValue !== undefined)
449
+ ? returnedValue
450
+ : this
451
+ ;
452
+ };
453
+
454
+ $.fn.rating.settings = {
455
+
456
+ name : 'Rating',
457
+ namespace : 'rating',
458
+
459
+ slent : false,
460
+ debug : false,
461
+ verbose : false,
462
+ performance : true,
463
+
464
+ initialRating : 0,
465
+ interactive : true,
466
+ maxRating : 4,
467
+ clearable : 'auto',
468
+
469
+ fireOnInit : false,
470
+
471
+ onRate : function(rating){},
472
+
473
+ error : {
474
+ method : 'The method you called is not defined',
475
+ noMaximum : 'No maximum rating specified. Cannot generate HTML automatically'
476
+ },
477
+
478
+
479
+ metadata: {
480
+ rating : 'rating',
481
+ maxRating : 'maxRating'
482
+ },
483
+
484
+ className : {
485
+ active : 'active',
486
+ disabled : 'disabled',
487
+ selected : 'selected',
488
+ loading : 'loading'
489
+ },
490
+
491
+ selector : {
492
+ icon : '.icon'
493
+ },
494
+
495
+ templates: {
496
+ icon: function(maxRating) {
497
+ var
498
+ icon = 1,
499
+ html = ''
500
+ ;
501
+ while(icon <= maxRating) {
502
+ html += '<i class="icon"></i>';
503
+ icon++;
504
+ }
505
+ return html;
506
+ }
507
+ }
508
+
509
+ };
510
+
511
+ })( jQuery, window, document );