semantic-ui-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +26 -0
- data/Rakefile +1 -0
- data/lib/generators/semantic/install/install_generator.rb +38 -0
- data/lib/generators/semantic/install/templates/semantic-ui.js +21 -0
- data/lib/generators/semantic/install/templates/semantic-ui/collections.less +6 -0
- data/lib/generators/semantic/install/templates/semantic-ui/elements.less +11 -0
- data/lib/generators/semantic/install/templates/semantic-ui/modules.less +18 -0
- data/lib/generators/semantic/install/templates/semantic-ui/views.less +6 -0
- data/lib/semantic/ui/rails.rb +10 -0
- data/lib/semantic/ui/rails/engine.rb +8 -0
- data/lib/semantic/ui/rails/version.rb +7 -0
- data/semantic-ui-rails.gemspec +23 -0
- data/vendor/assets/fonts/icons.eot +0 -0
- data/vendor/assets/fonts/icons.svg +450 -0
- data/vendor/assets/fonts/icons.ttf +0 -0
- data/vendor/assets/fonts/icons.woff +0 -0
- data/vendor/assets/images/semantic-ui/loader-large-inverted.gif +0 -0
- data/vendor/assets/images/semantic-ui/loader-large.gif +0 -0
- data/vendor/assets/images/semantic-ui/loader-medium-inverted.gif +0 -0
- data/vendor/assets/images/semantic-ui/loader-medium.gif +0 -0
- data/vendor/assets/images/semantic-ui/loader-mini-inverted.gif +0 -0
- data/vendor/assets/images/semantic-ui/loader-mini.gif +0 -0
- data/vendor/assets/images/semantic-ui/loader-small-inverted.gif +0 -0
- data/vendor/assets/images/semantic-ui/loader-small.gif +0 -0
- data/vendor/assets/javascripts/semantic-ui/accordion.js +411 -0
- data/vendor/assets/javascripts/semantic-ui/behavior/api.js +666 -0
- data/vendor/assets/javascripts/semantic-ui/behavior/colorize.js +271 -0
- data/vendor/assets/javascripts/semantic-ui/behavior/form.js +657 -0
- data/vendor/assets/javascripts/semantic-ui/behavior/state.js +752 -0
- data/vendor/assets/javascripts/semantic-ui/carousel.js +327 -0
- data/vendor/assets/javascripts/semantic-ui/chatroom.js +766 -0
- data/vendor/assets/javascripts/semantic-ui/checkbox.js +348 -0
- data/vendor/assets/javascripts/semantic-ui/dimmer.js +525 -0
- data/vendor/assets/javascripts/semantic-ui/dropdown.js +697 -0
- data/vendor/assets/javascripts/semantic-ui/modal.js +478 -0
- data/vendor/assets/javascripts/semantic-ui/nag.js +542 -0
- data/vendor/assets/javascripts/semantic-ui/popup.js +721 -0
- data/vendor/assets/javascripts/semantic-ui/rating.js +358 -0
- data/vendor/assets/javascripts/semantic-ui/search.js +770 -0
- data/vendor/assets/javascripts/semantic-ui/shape.js +776 -0
- data/vendor/assets/javascripts/semantic-ui/sidebar.js +489 -0
- data/vendor/assets/javascripts/semantic-ui/tab.js +674 -0
- data/vendor/assets/javascripts/semantic-ui/transition.js +645 -0
- data/vendor/assets/javascripts/semantic-ui/video.js +459 -0
- data/vendor/assets/stylesheets/semantic-ui/collections/breadcrumb.less +79 -0
- data/vendor/assets/stylesheets/semantic-ui/collections/form.less +536 -0
- data/vendor/assets/stylesheets/semantic-ui/collections/grid.less +655 -0
- data/vendor/assets/stylesheets/semantic-ui/collections/menu.less +1736 -0
- data/vendor/assets/stylesheets/semantic-ui/collections/message.less +337 -0
- data/vendor/assets/stylesheets/semantic-ui/collections/table.less +526 -0
- data/vendor/assets/stylesheets/semantic-ui/elements/button.less +1294 -0
- data/vendor/assets/stylesheets/semantic-ui/elements/divider.less +200 -0
- data/vendor/assets/stylesheets/semantic-ui/elements/header.less +325 -0
- data/vendor/assets/stylesheets/semantic-ui/elements/icon.less +449 -0
- data/vendor/assets/stylesheets/semantic-ui/elements/image.less +170 -0
- data/vendor/assets/stylesheets/semantic-ui/elements/input.less +287 -0
- data/vendor/assets/stylesheets/semantic-ui/elements/label.less +805 -0
- data/vendor/assets/stylesheets/semantic-ui/elements/loader.less +178 -0
- data/vendor/assets/stylesheets/semantic-ui/elements/progress.less +353 -0
- data/vendor/assets/stylesheets/semantic-ui/elements/segment.less +465 -0
- data/vendor/assets/stylesheets/semantic-ui/elements/step.less +294 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/accordion.less +135 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/carousel.less +71 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/chatroom.less +271 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/checkbox.less +378 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/dimmer.less +230 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/dropdown.less +506 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/extra.transition.less +1197 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/modal.less +154 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/nag.less +175 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/popup.less +238 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/rating.less +151 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/reveal.less +367 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/search.less +275 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/shape.less +115 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/sidebar.less +147 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/tab.less +59 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/transition.less +839 -0
- data/vendor/assets/stylesheets/semantic-ui/modules/video.less +99 -0
- data/vendor/assets/stylesheets/semantic-ui/views/comment.less +221 -0
- data/vendor/assets/stylesheets/semantic-ui/views/feed.less +151 -0
- data/vendor/assets/stylesheets/semantic-ui/views/item.less +641 -0
- data/vendor/assets/stylesheets/semantic-ui/views/list.less +491 -0
- data/vendor/assets/stylesheets/semantic-ui/views/sitemap.less +47 -0
- data/vendor/assets/stylesheets/semantic-ui/views/statistic.less +34 -0
- metadata +161 -0
@@ -0,0 +1,697 @@
|
|
1
|
+
/* ******************************
|
2
|
+
Semantic dropdown: Dropdown
|
3
|
+
Author: Jack Lukic
|
4
|
+
Notes: First Commit May 25, 2013
|
5
|
+
|
6
|
+
****************************** */
|
7
|
+
|
8
|
+
;(function ( $, window, document, undefined ) {
|
9
|
+
|
10
|
+
$.fn.dropdown = function(parameters) {
|
11
|
+
var
|
12
|
+
$allDropdowns = $(this),
|
13
|
+
$document = $(document),
|
14
|
+
|
15
|
+
settings = ( $.isPlainObject(parameters) )
|
16
|
+
? $.extend(true, {}, $.fn.dropdown.settings, parameters)
|
17
|
+
: $.fn.dropdown.settings,
|
18
|
+
|
19
|
+
className = settings.className,
|
20
|
+
metadata = settings.metadata,
|
21
|
+
namespace = settings.namespace,
|
22
|
+
selector = settings.selector,
|
23
|
+
error = settings.error,
|
24
|
+
|
25
|
+
eventNamespace = '.' + namespace,
|
26
|
+
dropdownNamespace = 'module-' + namespace,
|
27
|
+
dropdownSelector = $allDropdowns.selector || '',
|
28
|
+
|
29
|
+
time = new Date().getTime(),
|
30
|
+
performance = [],
|
31
|
+
|
32
|
+
query = arguments[0],
|
33
|
+
methodInvoked = (typeof query == 'string'),
|
34
|
+
queryArguments = [].slice.call(arguments, 1),
|
35
|
+
invokedResponse
|
36
|
+
;
|
37
|
+
|
38
|
+
$allDropdowns
|
39
|
+
.each(function() {
|
40
|
+
var
|
41
|
+
$dropdown = $(this),
|
42
|
+
$item = $dropdown.find(selector.item),
|
43
|
+
$text = $dropdown.find(selector.text),
|
44
|
+
$input = $dropdown.find(selector.input),
|
45
|
+
|
46
|
+
$menu = $dropdown.children(selector.menu),
|
47
|
+
|
48
|
+
isTouchDevice = ('ontouchstart' in document.documentElement),
|
49
|
+
|
50
|
+
element = this,
|
51
|
+
instance = $dropdown.data(dropdownNamespace),
|
52
|
+
dropdown
|
53
|
+
;
|
54
|
+
|
55
|
+
dropdown = {
|
56
|
+
|
57
|
+
initialize: function() {
|
58
|
+
dropdown.debug('Initializing dropdown', settings);
|
59
|
+
if(isTouchDevice) {
|
60
|
+
$dropdown
|
61
|
+
.on('touchstart' + eventNamespace, dropdown.event.test.toggle)
|
62
|
+
;
|
63
|
+
}
|
64
|
+
else if(settings.on == 'click') {
|
65
|
+
$dropdown
|
66
|
+
.on('click' + eventNamespace, dropdown.event.test.toggle)
|
67
|
+
;
|
68
|
+
}
|
69
|
+
else if(settings.on == 'hover') {
|
70
|
+
$dropdown
|
71
|
+
.on('mouseenter' + eventNamespace, dropdown.delay.show)
|
72
|
+
.on('mouseleave' + eventNamespace, dropdown.delay.hide)
|
73
|
+
;
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
$dropdown
|
77
|
+
.on(settings.on + eventNamespace, dropdown.toggle)
|
78
|
+
;
|
79
|
+
}
|
80
|
+
if(settings.action == 'form') {
|
81
|
+
dropdown.set.selected();
|
82
|
+
}
|
83
|
+
$item
|
84
|
+
.on('mouseenter' + eventNamespace, dropdown.event.item.mouseenter)
|
85
|
+
.on('mouseleave' + eventNamespace, dropdown.event.item.mouseleave)
|
86
|
+
.on(dropdown.get.selectEvent() + eventNamespace, dropdown.event.item.click)
|
87
|
+
;
|
88
|
+
dropdown.instantiate();
|
89
|
+
},
|
90
|
+
|
91
|
+
instantiate: function() {
|
92
|
+
dropdown.verbose('Storing instance of dropdown', dropdown);
|
93
|
+
$dropdown
|
94
|
+
.data(dropdownNamespace, dropdown)
|
95
|
+
;
|
96
|
+
},
|
97
|
+
|
98
|
+
destroy: function() {
|
99
|
+
dropdown.verbose('Destroying previous dropdown for', $dropdown);
|
100
|
+
$item
|
101
|
+
.off(eventNamespace)
|
102
|
+
;
|
103
|
+
$dropdown
|
104
|
+
.off(eventNamespace)
|
105
|
+
.removeData(dropdownNamespace)
|
106
|
+
;
|
107
|
+
},
|
108
|
+
|
109
|
+
event: {
|
110
|
+
|
111
|
+
stopPropagation: function(event) {
|
112
|
+
event.stopPropagation();
|
113
|
+
},
|
114
|
+
|
115
|
+
test: {
|
116
|
+
toggle: function(event) {
|
117
|
+
dropdown.determine.intent(event, dropdown.toggle);
|
118
|
+
event.stopImmediatePropagation();
|
119
|
+
},
|
120
|
+
hide: function(event) {
|
121
|
+
dropdown.determine.intent(event, dropdown.hide);
|
122
|
+
event.stopPropagation();
|
123
|
+
}
|
124
|
+
},
|
125
|
+
|
126
|
+
item: {
|
127
|
+
|
128
|
+
mouseenter: function(event) {
|
129
|
+
var
|
130
|
+
$currentMenu = $(this).find(selector.menu),
|
131
|
+
$otherMenus = $(this).siblings(selector.item).children(selector.menu)
|
132
|
+
;
|
133
|
+
if( $currentMenu.size() > 0 ) {
|
134
|
+
clearTimeout(dropdown.itemTimer);
|
135
|
+
dropdown.itemTimer = setTimeout(function() {
|
136
|
+
dropdown.animate.hide(false, $otherMenus);
|
137
|
+
dropdown.verbose('Showing sub-menu', $currentMenu);
|
138
|
+
dropdown.animate.show(false, $currentMenu);
|
139
|
+
}, settings.delay.show * 2);
|
140
|
+
}
|
141
|
+
},
|
142
|
+
|
143
|
+
mouseleave: function(event) {
|
144
|
+
var
|
145
|
+
$currentMenu = $(this).find(selector.menu)
|
146
|
+
;
|
147
|
+
if($currentMenu.size() > 0) {
|
148
|
+
clearTimeout(dropdown.itemTimer);
|
149
|
+
dropdown.itemTimer = setTimeout(function() {
|
150
|
+
dropdown.verbose('Hiding sub-menu', $currentMenu);
|
151
|
+
dropdown.animate.hide(false, $currentMenu);
|
152
|
+
}, settings.delay.hide);
|
153
|
+
}
|
154
|
+
},
|
155
|
+
|
156
|
+
click: function (event) {
|
157
|
+
var
|
158
|
+
$choice = $(this),
|
159
|
+
text = $choice.data(metadata.text) || $choice.text(),
|
160
|
+
value = $choice.data(metadata.value) || text
|
161
|
+
;
|
162
|
+
if( $choice.find(selector.menu).size() === 0 ) {
|
163
|
+
dropdown.verbose('Adding active state to selected item');
|
164
|
+
$item
|
165
|
+
.removeClass(className.active)
|
166
|
+
;
|
167
|
+
$choice
|
168
|
+
.addClass(className.active)
|
169
|
+
;
|
170
|
+
dropdown.determine.selectAction(text, value);
|
171
|
+
$.proxy(settings.onChange, element)(value, text);
|
172
|
+
event.stopPropagation();
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
},
|
177
|
+
|
178
|
+
resetStyle: function() {
|
179
|
+
$(this).removeAttr('style');
|
180
|
+
}
|
181
|
+
|
182
|
+
},
|
183
|
+
|
184
|
+
determine: {
|
185
|
+
selectAction: function(text, value) {
|
186
|
+
dropdown.verbose('Determining action', settings.action);
|
187
|
+
if( $.isFunction( dropdown[settings.action] ) ) {
|
188
|
+
dropdown.verbose('Triggering preset action', settings.action);
|
189
|
+
dropdown[ settings.action ](text, value);
|
190
|
+
}
|
191
|
+
else if( $.isFunction(settings.action) ) {
|
192
|
+
dropdown.verbose('Triggering user action', settings.action);
|
193
|
+
settings.action(text, value);
|
194
|
+
}
|
195
|
+
else {
|
196
|
+
dropdown.error(error.action);
|
197
|
+
}
|
198
|
+
},
|
199
|
+
intent: function(event, callback) {
|
200
|
+
dropdown.debug('Determining whether event occurred in dropdown', event.target);
|
201
|
+
callback = callback || function(){};
|
202
|
+
if( $(event.target).closest($menu).size() === 0 ) {
|
203
|
+
dropdown.verbose('Triggering event', callback);
|
204
|
+
callback();
|
205
|
+
}
|
206
|
+
else {
|
207
|
+
dropdown.verbose('Event occurred in dropdown, canceling callback');
|
208
|
+
}
|
209
|
+
}
|
210
|
+
},
|
211
|
+
|
212
|
+
bind: {
|
213
|
+
intent: function() {
|
214
|
+
dropdown.verbose('Binding hide intent event to document');
|
215
|
+
$document
|
216
|
+
.on(dropdown.get.selectEvent(), dropdown.event.test.hide)
|
217
|
+
;
|
218
|
+
}
|
219
|
+
},
|
220
|
+
|
221
|
+
unbind: {
|
222
|
+
intent: function() {
|
223
|
+
dropdown.verbose('Removing hide intent event from document');
|
224
|
+
$document
|
225
|
+
.off(dropdown.get.selectEvent())
|
226
|
+
;
|
227
|
+
}
|
228
|
+
},
|
229
|
+
|
230
|
+
nothing: function() {},
|
231
|
+
|
232
|
+
changeText: function(text, value) {
|
233
|
+
dropdown.set.text(text);
|
234
|
+
dropdown.hide();
|
235
|
+
},
|
236
|
+
|
237
|
+
updateForm: function(text, value) {
|
238
|
+
dropdown.set.text(text);
|
239
|
+
dropdown.set.value(value);
|
240
|
+
dropdown.hide();
|
241
|
+
},
|
242
|
+
|
243
|
+
get: {
|
244
|
+
selectEvent: function() {
|
245
|
+
return (isTouchDevice)
|
246
|
+
? 'touchstart'
|
247
|
+
: 'click'
|
248
|
+
;
|
249
|
+
},
|
250
|
+
text: function() {
|
251
|
+
return $text.text();
|
252
|
+
},
|
253
|
+
value: function() {
|
254
|
+
return $input.val();
|
255
|
+
},
|
256
|
+
item: function(value) {
|
257
|
+
var
|
258
|
+
$selectedItem
|
259
|
+
;
|
260
|
+
value = value || $input.val();
|
261
|
+
$item
|
262
|
+
.each(function() {
|
263
|
+
if( $(this).data(metadata.value) == value ) {
|
264
|
+
$selectedItem = $(this);
|
265
|
+
}
|
266
|
+
})
|
267
|
+
;
|
268
|
+
return $selectedItem || false;
|
269
|
+
}
|
270
|
+
},
|
271
|
+
|
272
|
+
set: {
|
273
|
+
text: function(text) {
|
274
|
+
dropdown.debug('Changing text', text, $text);
|
275
|
+
$text.removeClass(className.placeholder);
|
276
|
+
$text.text(text);
|
277
|
+
},
|
278
|
+
value: function(value) {
|
279
|
+
dropdown.debug('Adding selected value to hidden input', value, $input);
|
280
|
+
$input.val(value);
|
281
|
+
},
|
282
|
+
active: function() {
|
283
|
+
$dropdown.addClass(className.active);
|
284
|
+
},
|
285
|
+
visible: function() {
|
286
|
+
$dropdown.addClass(className.visible);
|
287
|
+
},
|
288
|
+
selected: function(value) {
|
289
|
+
var
|
290
|
+
$selectedItem = dropdown.get.item(value),
|
291
|
+
selectedText
|
292
|
+
;
|
293
|
+
if($selectedItem) {
|
294
|
+
dropdown.debug('Setting selected menu item to', $selectedItem);
|
295
|
+
selectedText = $selectedItem.data(metadata.text) || $selectedItem.text();
|
296
|
+
$item
|
297
|
+
.removeClass(className.active)
|
298
|
+
;
|
299
|
+
$selectedItem
|
300
|
+
.addClass(className.active)
|
301
|
+
;
|
302
|
+
dropdown.set.text(selectedText);
|
303
|
+
}
|
304
|
+
}
|
305
|
+
},
|
306
|
+
|
307
|
+
remove: {
|
308
|
+
active: function() {
|
309
|
+
$dropdown.removeClass(className.active);
|
310
|
+
},
|
311
|
+
visible: function() {
|
312
|
+
$dropdown.removeClass(className.visible);
|
313
|
+
}
|
314
|
+
},
|
315
|
+
|
316
|
+
is: {
|
317
|
+
visible: function($subMenu) {
|
318
|
+
return ($subMenu)
|
319
|
+
? $subMenu.is(':visible')
|
320
|
+
: $menu.is(':visible')
|
321
|
+
;
|
322
|
+
},
|
323
|
+
hidden: function($subMenu) {
|
324
|
+
return ($subMenu)
|
325
|
+
? $subMenu.is(':not(:visible)')
|
326
|
+
: $menu.is(':not(:visible)')
|
327
|
+
;
|
328
|
+
}
|
329
|
+
},
|
330
|
+
|
331
|
+
can: {
|
332
|
+
click: function() {
|
333
|
+
return (isTouchDevice || settings.on == 'click');
|
334
|
+
},
|
335
|
+
show: function() {
|
336
|
+
return !$dropdown.hasClass(className.disabled);
|
337
|
+
}
|
338
|
+
},
|
339
|
+
|
340
|
+
animate: {
|
341
|
+
show: function(callback, $subMenu) {
|
342
|
+
var
|
343
|
+
$currentMenu = $subMenu || $menu
|
344
|
+
;
|
345
|
+
callback = callback || function(){};
|
346
|
+
if( dropdown.is.hidden($currentMenu) ) {
|
347
|
+
dropdown.verbose('Doing menu show animation', $currentMenu);
|
348
|
+
if(settings.transition == 'none') {
|
349
|
+
callback();
|
350
|
+
}
|
351
|
+
else if($.fn.transition !== undefined) {
|
352
|
+
$currentMenu.transition(settings.transition + ' in', settings.duration, callback);
|
353
|
+
}
|
354
|
+
else if(settings.transition == 'slide down') {
|
355
|
+
$currentMenu
|
356
|
+
.hide()
|
357
|
+
.clearQueue()
|
358
|
+
.children()
|
359
|
+
.clearQueue()
|
360
|
+
.css('opacity', 0)
|
361
|
+
.delay(50)
|
362
|
+
.animate({
|
363
|
+
opacity : 1
|
364
|
+
}, settings.duration, 'easeOutQuad', dropdown.event.resetStyle)
|
365
|
+
.end()
|
366
|
+
.slideDown(100, 'easeOutQuad', function() {
|
367
|
+
$.proxy(dropdown.event.resetStyle, this)();
|
368
|
+
callback();
|
369
|
+
})
|
370
|
+
;
|
371
|
+
}
|
372
|
+
else if(settings.transition == 'fade') {
|
373
|
+
$currentMenu
|
374
|
+
.hide()
|
375
|
+
.clearQueue()
|
376
|
+
.fadeIn(settings.duration, function() {
|
377
|
+
$.proxy(dropdown.event.resetStyle, this)();
|
378
|
+
callback();
|
379
|
+
})
|
380
|
+
;
|
381
|
+
}
|
382
|
+
else {
|
383
|
+
dropdown.error(error.transition);
|
384
|
+
}
|
385
|
+
}
|
386
|
+
},
|
387
|
+
hide: function(callback, $subMenu) {
|
388
|
+
var
|
389
|
+
$currentMenu = $subMenu || $menu
|
390
|
+
;
|
391
|
+
callback = callback || function(){};
|
392
|
+
if(dropdown.is.visible($currentMenu) ) {
|
393
|
+
dropdown.verbose('Doing menu hide animation', $currentMenu);
|
394
|
+
if($.fn.transition !== undefined) {
|
395
|
+
$currentMenu.transition(settings.transition + ' out', settings.duration, callback);
|
396
|
+
}
|
397
|
+
else if(settings.transition == 'none') {
|
398
|
+
callback();
|
399
|
+
}
|
400
|
+
else if(settings.transition == 'slide down') {
|
401
|
+
$currentMenu
|
402
|
+
.show()
|
403
|
+
.clearQueue()
|
404
|
+
.children()
|
405
|
+
.clearQueue()
|
406
|
+
.css('opacity', 1)
|
407
|
+
.animate({
|
408
|
+
opacity : 0
|
409
|
+
}, 100, 'easeOutQuad', dropdown.event.resetStyle)
|
410
|
+
.end()
|
411
|
+
.delay(50)
|
412
|
+
.slideUp(100, 'easeOutQuad', function() {
|
413
|
+
$.proxy(dropdown.event.resetStyle, this)();
|
414
|
+
callback();
|
415
|
+
})
|
416
|
+
;
|
417
|
+
}
|
418
|
+
else if(settings.transition == 'fade') {
|
419
|
+
$currentMenu
|
420
|
+
.show()
|
421
|
+
.clearQueue()
|
422
|
+
.fadeOut(150, function() {
|
423
|
+
$.proxy(dropdown.event.resetStyle, this)();
|
424
|
+
callback();
|
425
|
+
})
|
426
|
+
;
|
427
|
+
}
|
428
|
+
else {
|
429
|
+
dropdown.error(error.transition);
|
430
|
+
}
|
431
|
+
}
|
432
|
+
}
|
433
|
+
},
|
434
|
+
|
435
|
+
show: function() {
|
436
|
+
dropdown.debug('Checking if dropdown can show');
|
437
|
+
if( !dropdown.is.visible() ) {
|
438
|
+
dropdown.hideOthers();
|
439
|
+
dropdown.set.active();
|
440
|
+
dropdown.animate.show(dropdown.set.visible);
|
441
|
+
if( dropdown.can.click() ) {
|
442
|
+
dropdown.bind.intent();
|
443
|
+
}
|
444
|
+
$.proxy(settings.onShow, element)();
|
445
|
+
}
|
446
|
+
},
|
447
|
+
|
448
|
+
hide: function() {
|
449
|
+
if( !dropdown.is.hidden() ) {
|
450
|
+
dropdown.debug('Hiding dropdown');
|
451
|
+
if( dropdown.can.click() ) {
|
452
|
+
dropdown.unbind.intent();
|
453
|
+
}
|
454
|
+
dropdown.remove.active();
|
455
|
+
dropdown.animate.hide(dropdown.remove.visible);
|
456
|
+
$.proxy(settings.onHide, element)();
|
457
|
+
}
|
458
|
+
},
|
459
|
+
|
460
|
+
delay: {
|
461
|
+
show: function() {
|
462
|
+
dropdown.verbose('Delaying show event to ensure user intent');
|
463
|
+
clearTimeout(dropdown.timer);
|
464
|
+
dropdown.timer = setTimeout(dropdown.show, settings.delay.show);
|
465
|
+
},
|
466
|
+
hide: function() {
|
467
|
+
dropdown.verbose('Delaying hide event to ensure user intent');
|
468
|
+
clearTimeout(dropdown.timer);
|
469
|
+
dropdown.timer = setTimeout(dropdown.hide, settings.delay.hide);
|
470
|
+
}
|
471
|
+
},
|
472
|
+
|
473
|
+
hideOthers: function() {
|
474
|
+
dropdown.verbose('Finding other dropdowns to hide');
|
475
|
+
$allDropdowns
|
476
|
+
.not($dropdown)
|
477
|
+
.has(selector.menu + ':visible')
|
478
|
+
.dropdown('hide')
|
479
|
+
;
|
480
|
+
},
|
481
|
+
|
482
|
+
toggle: function() {
|
483
|
+
dropdown.verbose('Toggling menu visibility');
|
484
|
+
if( dropdown.is.hidden() ) {
|
485
|
+
dropdown.show();
|
486
|
+
}
|
487
|
+
else {
|
488
|
+
dropdown.hide();
|
489
|
+
}
|
490
|
+
},
|
491
|
+
|
492
|
+
setting: function(name, value) {
|
493
|
+
if(value !== undefined) {
|
494
|
+
if( $.isPlainObject(name) ) {
|
495
|
+
$.extend(true, settings, name);
|
496
|
+
}
|
497
|
+
else {
|
498
|
+
settings[name] = value;
|
499
|
+
}
|
500
|
+
}
|
501
|
+
else {
|
502
|
+
return settings[name];
|
503
|
+
}
|
504
|
+
},
|
505
|
+
internal: function(name, value) {
|
506
|
+
if(value !== undefined) {
|
507
|
+
if( $.isPlainObject(name) ) {
|
508
|
+
$.extend(true, dropdown, name);
|
509
|
+
}
|
510
|
+
else {
|
511
|
+
dropdown[name] = value;
|
512
|
+
}
|
513
|
+
}
|
514
|
+
else {
|
515
|
+
return dropdown[name];
|
516
|
+
}
|
517
|
+
},
|
518
|
+
debug: function() {
|
519
|
+
if(settings.debug) {
|
520
|
+
if(settings.performance) {
|
521
|
+
dropdown.performance.log(arguments);
|
522
|
+
}
|
523
|
+
else {
|
524
|
+
dropdown.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
|
525
|
+
dropdown.debug.apply(console, arguments);
|
526
|
+
}
|
527
|
+
}
|
528
|
+
},
|
529
|
+
verbose: function() {
|
530
|
+
if(settings.verbose && settings.debug) {
|
531
|
+
if(settings.performance) {
|
532
|
+
dropdown.performance.log(arguments);
|
533
|
+
}
|
534
|
+
else {
|
535
|
+
dropdown.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
|
536
|
+
dropdown.verbose.apply(console, arguments);
|
537
|
+
}
|
538
|
+
}
|
539
|
+
},
|
540
|
+
error: function() {
|
541
|
+
dropdown.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
|
542
|
+
dropdown.error.apply(console, arguments);
|
543
|
+
},
|
544
|
+
performance: {
|
545
|
+
log: function(message) {
|
546
|
+
var
|
547
|
+
currentTime,
|
548
|
+
executionTime,
|
549
|
+
previousTime
|
550
|
+
;
|
551
|
+
if(settings.performance) {
|
552
|
+
currentTime = new Date().getTime();
|
553
|
+
previousTime = time || currentTime;
|
554
|
+
executionTime = currentTime - previousTime;
|
555
|
+
time = currentTime;
|
556
|
+
performance.push({
|
557
|
+
'Element' : element,
|
558
|
+
'Name' : message[0],
|
559
|
+
'Arguments' : [].slice.call(message, 1) || '',
|
560
|
+
'Execution Time' : executionTime
|
561
|
+
});
|
562
|
+
}
|
563
|
+
clearTimeout(dropdown.performance.timer);
|
564
|
+
dropdown.performance.timer = setTimeout(dropdown.performance.display, 100);
|
565
|
+
},
|
566
|
+
display: function() {
|
567
|
+
var
|
568
|
+
title = settings.name + ':',
|
569
|
+
totalTime = 0
|
570
|
+
;
|
571
|
+
time = false;
|
572
|
+
clearTimeout(dropdown.performance.timer);
|
573
|
+
$.each(performance, function(index, data) {
|
574
|
+
totalTime += data['Execution Time'];
|
575
|
+
});
|
576
|
+
title += ' ' + totalTime + 'ms';
|
577
|
+
if(dropdownSelector) {
|
578
|
+
title += ' \'' + dropdownSelector + '\'';
|
579
|
+
}
|
580
|
+
title += ' ' + '(' + $allDropdowns.size() + ')';
|
581
|
+
if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
|
582
|
+
console.groupCollapsed(title);
|
583
|
+
if(console.table) {
|
584
|
+
console.table(performance);
|
585
|
+
}
|
586
|
+
else {
|
587
|
+
$.each(performance, function(index, data) {
|
588
|
+
console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
|
589
|
+
});
|
590
|
+
}
|
591
|
+
console.groupEnd();
|
592
|
+
}
|
593
|
+
performance = [];
|
594
|
+
}
|
595
|
+
},
|
596
|
+
invoke: function(query, passedArguments, context) {
|
597
|
+
var
|
598
|
+
maxDepth,
|
599
|
+
found
|
600
|
+
;
|
601
|
+
passedArguments = passedArguments || queryArguments;
|
602
|
+
context = element || context;
|
603
|
+
if(typeof query == 'string' && instance !== undefined) {
|
604
|
+
query = query.split(/[\. ]/);
|
605
|
+
maxDepth = query.length - 1;
|
606
|
+
$.each(query, function(depth, value) {
|
607
|
+
if( $.isPlainObject( instance[value] ) && (depth != maxDepth) ) {
|
608
|
+
instance = instance[value];
|
609
|
+
}
|
610
|
+
else if( instance[value] !== undefined ) {
|
611
|
+
found = instance[value];
|
612
|
+
}
|
613
|
+
else {
|
614
|
+
dropdown.error(error.method);
|
615
|
+
}
|
616
|
+
});
|
617
|
+
}
|
618
|
+
if ( $.isFunction( found ) ) {
|
619
|
+
return found.apply(context, passedArguments);
|
620
|
+
}
|
621
|
+
return found || false;
|
622
|
+
}
|
623
|
+
};
|
624
|
+
|
625
|
+
if(methodInvoked) {
|
626
|
+
if(instance === undefined) {
|
627
|
+
dropdown.initialize();
|
628
|
+
}
|
629
|
+
invokedResponse = dropdown.invoke(query);
|
630
|
+
}
|
631
|
+
else {
|
632
|
+
if(instance !== undefined) {
|
633
|
+
dropdown.destroy();
|
634
|
+
}
|
635
|
+
dropdown.initialize();
|
636
|
+
}
|
637
|
+
})
|
638
|
+
;
|
639
|
+
|
640
|
+
return (invokedResponse)
|
641
|
+
? invokedResponse
|
642
|
+
: this
|
643
|
+
;
|
644
|
+
};
|
645
|
+
|
646
|
+
$.fn.dropdown.settings = {
|
647
|
+
|
648
|
+
name : 'Dropdown',
|
649
|
+
namespace : 'dropdown',
|
650
|
+
|
651
|
+
verbose : true,
|
652
|
+
debug : true,
|
653
|
+
performance : true,
|
654
|
+
|
655
|
+
on : 'click',
|
656
|
+
action : 'hide',
|
657
|
+
|
658
|
+
delay: {
|
659
|
+
show: 200,
|
660
|
+
hide: 300
|
661
|
+
},
|
662
|
+
|
663
|
+
transition : 'slide down',
|
664
|
+
duration : 250,
|
665
|
+
|
666
|
+
onChange : function(){},
|
667
|
+
onShow : function(){},
|
668
|
+
onHide : function(){},
|
669
|
+
|
670
|
+
error : {
|
671
|
+
action : 'You called a dropdown action that was not defined',
|
672
|
+
method : 'The method you called is not defined.',
|
673
|
+
transition : 'The requested transition was not found'
|
674
|
+
},
|
675
|
+
|
676
|
+
metadata: {
|
677
|
+
text : 'text',
|
678
|
+
value : 'value'
|
679
|
+
},
|
680
|
+
|
681
|
+
selector : {
|
682
|
+
menu : '.menu',
|
683
|
+
item : '.menu > .item',
|
684
|
+
text : '> .text',
|
685
|
+
input : '> input[type="hidden"]'
|
686
|
+
},
|
687
|
+
|
688
|
+
className : {
|
689
|
+
active : 'active',
|
690
|
+
placeholder : 'default',
|
691
|
+
disabled : 'disabled',
|
692
|
+
visible : 'visible'
|
693
|
+
}
|
694
|
+
|
695
|
+
};
|
696
|
+
|
697
|
+
})( jQuery, window , document );
|