quantum 0.0.2
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/.project +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +82 -0
- data/Rakefile +1 -0
- data/lib/quantum.rb +8 -0
- data/lib/quantum/version.rb +3 -0
- data/quantum.gemspec +23 -0
- data/vendor/assets/.keep +0 -0
- data/vendor/assets/javascripts/alert.js +99 -0
- data/vendor/assets/javascripts/chart.js +1424 -0
- data/vendor/assets/javascripts/collapse.js +167 -0
- data/vendor/assets/javascripts/date_picker.js +474 -0
- data/vendor/assets/javascripts/dropdown.js +169 -0
- data/vendor/assets/javascripts/file_input.js +100 -0
- data/vendor/assets/javascripts/input_mask.js +355 -0
- data/vendor/assets/javascripts/map.js +1982 -0
- data/vendor/assets/javascripts/modal.js +247 -0
- data/vendor/assets/javascripts/popover.js +114 -0
- data/vendor/assets/javascripts/qrcode.js +89 -0
- data/vendor/assets/javascripts/qrcoder.js +1237 -0
- data/vendor/assets/javascripts/tab.js +144 -0
- data/vendor/assets/javascripts/time_picker.js +888 -0
- data/vendor/assets/javascripts/tooltip.js +361 -0
- data/vendor/assets/javascripts/transitions.js +60 -0
- data/vendor/assets/javascripts/typeahead.js +335 -0
- data/vendor/assets/javascripts/wizard.js +114 -0
- data/vendor/assets/stylesheets/alert.css.scss +42 -0
- data/vendor/assets/stylesheets/breadcrumb.css.scss +24 -0
- data/vendor/assets/stylesheets/button.css.scss +252 -0
- data/vendor/assets/stylesheets/chart.css.scss +10 -0
- data/vendor/assets/stylesheets/code.css.scss +47 -0
- data/vendor/assets/stylesheets/collapse.css.scss +16 -0
- data/vendor/assets/stylesheets/datepicker.css.scss +111 -0
- data/vendor/assets/stylesheets/dropdown.css.scss +98 -0
- data/vendor/assets/stylesheets/file_input.css.scss +7 -0
- data/vendor/assets/stylesheets/footer.css.scss +99 -0
- data/vendor/assets/stylesheets/form.css.scss +190 -0
- data/vendor/assets/stylesheets/grid.css.scss +334 -0
- data/vendor/assets/stylesheets/header.css.scss +162 -0
- data/vendor/assets/stylesheets/icon.css.scss +533 -0
- data/vendor/assets/stylesheets/image.css.scss +48 -0
- data/vendor/assets/stylesheets/label_and_badge.css.scss +60 -0
- data/vendor/assets/stylesheets/link.css.scss +22 -0
- data/vendor/assets/stylesheets/map.css.scss +13 -0
- data/vendor/assets/stylesheets/modal.css.scss +100 -0
- data/vendor/assets/stylesheets/pagination.css.scss +65 -0
- data/vendor/assets/stylesheets/popover.css.scss +110 -0
- data/vendor/assets/stylesheets/progress.css.scss +81 -0
- data/vendor/assets/stylesheets/qrcode.css.scss +7 -0
- data/vendor/assets/stylesheets/reset.css.scss +75 -0
- data/vendor/assets/stylesheets/tab.css.scss +202 -0
- data/vendor/assets/stylesheets/table.css.scss +71 -0
- data/vendor/assets/stylesheets/timepicker.css.scss +74 -0
- data/vendor/assets/stylesheets/tooltip.css.scss +83 -0
- data/vendor/assets/stylesheets/transitions.css.scss +14 -0
- data/vendor/assets/stylesheets/trunk.css.scss +80 -0
- data/vendor/assets/stylesheets/typeahead.css.scss +7 -0
- data/vendor/assets/stylesheets/typography.css.scss +130 -0
- data/vendor/assets/stylesheets/wizard.css.scss +27 -0
- metadata +134 -0
@@ -0,0 +1,361 @@
|
|
1
|
+
/* ===========================================================
|
2
|
+
* bootstrap-tooltip.js v2.3.2
|
3
|
+
* http://twitter.github.com/bootstrap/javascript.html#tooltips
|
4
|
+
* Inspired by the original jQuery.tipsy by Jason Frame
|
5
|
+
* ===========================================================
|
6
|
+
* Copyright 2012 Twitter, Inc.
|
7
|
+
*
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
* you may not use this file except in compliance with the License.
|
10
|
+
* You may obtain a copy of the License at
|
11
|
+
*
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
*
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
* See the License for the specific language governing permissions and
|
18
|
+
* limitations under the License.
|
19
|
+
* ========================================================== */
|
20
|
+
|
21
|
+
|
22
|
+
!function ($) {
|
23
|
+
|
24
|
+
"use strict"; // jshint ;_;
|
25
|
+
|
26
|
+
|
27
|
+
/* TOOLTIP PUBLIC CLASS DEFINITION
|
28
|
+
* =============================== */
|
29
|
+
|
30
|
+
var Tooltip = function (element, options) {
|
31
|
+
this.init('tooltip', element, options)
|
32
|
+
}
|
33
|
+
|
34
|
+
Tooltip.prototype = {
|
35
|
+
|
36
|
+
constructor: Tooltip
|
37
|
+
|
38
|
+
, init: function (type, element, options) {
|
39
|
+
var eventIn
|
40
|
+
, eventOut
|
41
|
+
, triggers
|
42
|
+
, trigger
|
43
|
+
, i
|
44
|
+
|
45
|
+
this.type = type
|
46
|
+
this.$element = $(element)
|
47
|
+
this.options = this.getOptions(options)
|
48
|
+
this.enabled = true
|
49
|
+
|
50
|
+
triggers = this.options.trigger.split(' ')
|
51
|
+
|
52
|
+
for (i = triggers.length; i--;) {
|
53
|
+
trigger = triggers[i]
|
54
|
+
if (trigger == 'click') {
|
55
|
+
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
|
56
|
+
} else if (trigger != 'manual') {
|
57
|
+
eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
|
58
|
+
eventOut = trigger == 'hover' ? 'mouseleave' : 'blur'
|
59
|
+
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
|
60
|
+
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
this.options.selector ?
|
65
|
+
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
|
66
|
+
this.fixTitle()
|
67
|
+
}
|
68
|
+
|
69
|
+
, getOptions: function (options) {
|
70
|
+
options = $.extend({}, $.fn[this.type].defaults, this.$element.data(), options)
|
71
|
+
|
72
|
+
if (options.delay && typeof options.delay == 'number') {
|
73
|
+
options.delay = {
|
74
|
+
show: options.delay
|
75
|
+
, hide: options.delay
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
return options
|
80
|
+
}
|
81
|
+
|
82
|
+
, enter: function (e) {
|
83
|
+
var defaults = $.fn[this.type].defaults
|
84
|
+
, options = {}
|
85
|
+
, self
|
86
|
+
|
87
|
+
this._options && $.each(this._options, function (key, value) {
|
88
|
+
if (defaults[key] != value) options[key] = value
|
89
|
+
}, this)
|
90
|
+
|
91
|
+
self = $(e.currentTarget)[this.type](options).data(this.type)
|
92
|
+
|
93
|
+
if (!self.options.delay || !self.options.delay.show) return self.show()
|
94
|
+
|
95
|
+
clearTimeout(this.timeout)
|
96
|
+
self.hoverState = 'in'
|
97
|
+
this.timeout = setTimeout(function() {
|
98
|
+
if (self.hoverState == 'in') self.show()
|
99
|
+
}, self.options.delay.show)
|
100
|
+
}
|
101
|
+
|
102
|
+
, leave: function (e) {
|
103
|
+
var self = $(e.currentTarget)[this.type](this._options).data(this.type)
|
104
|
+
|
105
|
+
if (this.timeout) clearTimeout(this.timeout)
|
106
|
+
if (!self.options.delay || !self.options.delay.hide) return self.hide()
|
107
|
+
|
108
|
+
self.hoverState = 'out'
|
109
|
+
this.timeout = setTimeout(function() {
|
110
|
+
if (self.hoverState == 'out') self.hide()
|
111
|
+
}, self.options.delay.hide)
|
112
|
+
}
|
113
|
+
|
114
|
+
, show: function () {
|
115
|
+
var $tip
|
116
|
+
, pos
|
117
|
+
, actualWidth
|
118
|
+
, actualHeight
|
119
|
+
, placement
|
120
|
+
, tp
|
121
|
+
, e = $.Event('show')
|
122
|
+
|
123
|
+
if (this.hasContent() && this.enabled) {
|
124
|
+
this.$element.trigger(e)
|
125
|
+
if (e.isDefaultPrevented()) return
|
126
|
+
$tip = this.tip()
|
127
|
+
this.setContent()
|
128
|
+
|
129
|
+
if (this.options.animation) {
|
130
|
+
$tip.addClass('fade')
|
131
|
+
}
|
132
|
+
|
133
|
+
placement = typeof this.options.placement == 'function' ?
|
134
|
+
this.options.placement.call(this, $tip[0], this.$element[0]) :
|
135
|
+
this.options.placement
|
136
|
+
|
137
|
+
$tip
|
138
|
+
.detach()
|
139
|
+
.css({ top: 0, left: 0, display: 'block' })
|
140
|
+
|
141
|
+
this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
|
142
|
+
|
143
|
+
pos = this.getPosition()
|
144
|
+
|
145
|
+
actualWidth = $tip[0].offsetWidth
|
146
|
+
actualHeight = $tip[0].offsetHeight
|
147
|
+
|
148
|
+
switch (placement) {
|
149
|
+
case 'bottom':
|
150
|
+
tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
|
151
|
+
break
|
152
|
+
case 'top':
|
153
|
+
tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
|
154
|
+
break
|
155
|
+
case 'left':
|
156
|
+
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
|
157
|
+
break
|
158
|
+
case 'right':
|
159
|
+
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
|
160
|
+
break
|
161
|
+
}
|
162
|
+
|
163
|
+
this.applyPlacement(tp, placement)
|
164
|
+
this.$element.trigger('shown')
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
, applyPlacement: function(offset, placement){
|
169
|
+
var $tip = this.tip()
|
170
|
+
, width = $tip[0].offsetWidth
|
171
|
+
, height = $tip[0].offsetHeight
|
172
|
+
, actualWidth
|
173
|
+
, actualHeight
|
174
|
+
, delta
|
175
|
+
, replace
|
176
|
+
|
177
|
+
$tip
|
178
|
+
.offset(offset)
|
179
|
+
.addClass(placement)
|
180
|
+
.addClass('in')
|
181
|
+
|
182
|
+
actualWidth = $tip[0].offsetWidth
|
183
|
+
actualHeight = $tip[0].offsetHeight
|
184
|
+
|
185
|
+
if (placement == 'top' && actualHeight != height) {
|
186
|
+
offset.top = offset.top + height - actualHeight
|
187
|
+
replace = true
|
188
|
+
}
|
189
|
+
|
190
|
+
if (placement == 'bottom' || placement == 'top') {
|
191
|
+
delta = 0
|
192
|
+
|
193
|
+
if (offset.left < 0){
|
194
|
+
delta = offset.left * -2
|
195
|
+
offset.left = 0
|
196
|
+
$tip.offset(offset)
|
197
|
+
actualWidth = $tip[0].offsetWidth
|
198
|
+
actualHeight = $tip[0].offsetHeight
|
199
|
+
}
|
200
|
+
|
201
|
+
this.replaceArrow(delta - width + actualWidth, actualWidth, 'left')
|
202
|
+
} else {
|
203
|
+
this.replaceArrow(actualHeight - height, actualHeight, 'top')
|
204
|
+
}
|
205
|
+
|
206
|
+
if (replace) $tip.offset(offset)
|
207
|
+
}
|
208
|
+
|
209
|
+
, replaceArrow: function(delta, dimension, position){
|
210
|
+
this
|
211
|
+
.arrow()
|
212
|
+
.css(position, delta ? (50 * (1 - delta / dimension) + "%") : '')
|
213
|
+
}
|
214
|
+
|
215
|
+
, setContent: function () {
|
216
|
+
var $tip = this.tip()
|
217
|
+
, title = this.getTitle()
|
218
|
+
|
219
|
+
$tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
|
220
|
+
$tip.removeClass('fade in top bottom left right')
|
221
|
+
}
|
222
|
+
|
223
|
+
, hide: function () {
|
224
|
+
var that = this
|
225
|
+
, $tip = this.tip()
|
226
|
+
, e = $.Event('hide')
|
227
|
+
|
228
|
+
this.$element.trigger(e)
|
229
|
+
if (e.isDefaultPrevented()) return
|
230
|
+
|
231
|
+
$tip.removeClass('in')
|
232
|
+
|
233
|
+
function removeWithAnimation() {
|
234
|
+
var timeout = setTimeout(function () {
|
235
|
+
$tip.off($.support.transition.end).detach()
|
236
|
+
}, 500)
|
237
|
+
|
238
|
+
$tip.one($.support.transition.end, function () {
|
239
|
+
clearTimeout(timeout)
|
240
|
+
$tip.detach()
|
241
|
+
})
|
242
|
+
}
|
243
|
+
|
244
|
+
$.support.transition && this.$tip.hasClass('fade') ?
|
245
|
+
removeWithAnimation() :
|
246
|
+
$tip.detach()
|
247
|
+
|
248
|
+
this.$element.trigger('hidden')
|
249
|
+
|
250
|
+
return this
|
251
|
+
}
|
252
|
+
|
253
|
+
, fixTitle: function () {
|
254
|
+
var $e = this.$element
|
255
|
+
if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
|
256
|
+
$e.attr('data-original-title', $e.attr('title') || '').attr('title', '')
|
257
|
+
}
|
258
|
+
}
|
259
|
+
|
260
|
+
, hasContent: function () {
|
261
|
+
return this.getTitle()
|
262
|
+
}
|
263
|
+
|
264
|
+
, getPosition: function () {
|
265
|
+
var el = this.$element[0]
|
266
|
+
return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : {
|
267
|
+
width: el.offsetWidth
|
268
|
+
, height: el.offsetHeight
|
269
|
+
}, this.$element.offset())
|
270
|
+
}
|
271
|
+
|
272
|
+
, getTitle: function () {
|
273
|
+
var title
|
274
|
+
, $e = this.$element
|
275
|
+
, o = this.options
|
276
|
+
|
277
|
+
title = $e.attr('data-original-title')
|
278
|
+
|| (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
|
279
|
+
|
280
|
+
return title
|
281
|
+
}
|
282
|
+
|
283
|
+
, tip: function () {
|
284
|
+
return this.$tip = this.$tip || $(this.options.template)
|
285
|
+
}
|
286
|
+
|
287
|
+
, arrow: function(){
|
288
|
+
return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow")
|
289
|
+
}
|
290
|
+
|
291
|
+
, validate: function () {
|
292
|
+
if (!this.$element[0].parentNode) {
|
293
|
+
this.hide()
|
294
|
+
this.$element = null
|
295
|
+
this.options = null
|
296
|
+
}
|
297
|
+
}
|
298
|
+
|
299
|
+
, enable: function () {
|
300
|
+
this.enabled = true
|
301
|
+
}
|
302
|
+
|
303
|
+
, disable: function () {
|
304
|
+
this.enabled = false
|
305
|
+
}
|
306
|
+
|
307
|
+
, toggleEnabled: function () {
|
308
|
+
this.enabled = !this.enabled
|
309
|
+
}
|
310
|
+
|
311
|
+
, toggle: function (e) {
|
312
|
+
var self = e ? $(e.currentTarget)[this.type](this._options).data(this.type) : this
|
313
|
+
self.tip().hasClass('in') ? self.hide() : self.show()
|
314
|
+
}
|
315
|
+
|
316
|
+
, destroy: function () {
|
317
|
+
this.hide().$element.off('.' + this.type).removeData(this.type)
|
318
|
+
}
|
319
|
+
|
320
|
+
}
|
321
|
+
|
322
|
+
|
323
|
+
/* TOOLTIP PLUGIN DEFINITION
|
324
|
+
* ========================= */
|
325
|
+
|
326
|
+
var old = $.fn.tooltip
|
327
|
+
|
328
|
+
$.fn.tooltip = function ( option ) {
|
329
|
+
return this.each(function () {
|
330
|
+
var $this = $(this)
|
331
|
+
, data = $this.data('tooltip')
|
332
|
+
, options = typeof option == 'object' && option
|
333
|
+
if (!data) $this.data('tooltip', (data = new Tooltip(this, options)))
|
334
|
+
if (typeof option == 'string') data[option]()
|
335
|
+
})
|
336
|
+
}
|
337
|
+
|
338
|
+
$.fn.tooltip.Constructor = Tooltip
|
339
|
+
|
340
|
+
$.fn.tooltip.defaults = {
|
341
|
+
animation: true
|
342
|
+
, placement: 'top'
|
343
|
+
, selector: false
|
344
|
+
, template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
|
345
|
+
, trigger: 'hover focus'
|
346
|
+
, title: ''
|
347
|
+
, delay: 0
|
348
|
+
, html: false
|
349
|
+
, container: false
|
350
|
+
}
|
351
|
+
|
352
|
+
|
353
|
+
/* TOOLTIP NO CONFLICT
|
354
|
+
* =================== */
|
355
|
+
|
356
|
+
$.fn.tooltip.noConflict = function () {
|
357
|
+
$.fn.tooltip = old
|
358
|
+
return this
|
359
|
+
}
|
360
|
+
|
361
|
+
}(window.jQuery);
|
@@ -0,0 +1,60 @@
|
|
1
|
+
/* ===================================================
|
2
|
+
* bootstrap-transition.js v2.3.2
|
3
|
+
* http://twitter.github.com/bootstrap/javascript.html#transitions
|
4
|
+
* ===================================================
|
5
|
+
* Copyright 2012 Twitter, Inc.
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
* ========================================================== */
|
19
|
+
|
20
|
+
|
21
|
+
!function ($) {
|
22
|
+
|
23
|
+
"use strict"; // jshint ;_;
|
24
|
+
|
25
|
+
|
26
|
+
/* CSS TRANSITION SUPPORT (http://www.modernizr.com/)
|
27
|
+
* ======================================================= */
|
28
|
+
|
29
|
+
$(function () {
|
30
|
+
|
31
|
+
$.support.transition = (function () {
|
32
|
+
|
33
|
+
var transitionEnd = (function () {
|
34
|
+
|
35
|
+
var el = document.createElement('bootstrap')
|
36
|
+
, transEndEventNames = {
|
37
|
+
'WebkitTransition' : 'webkitTransitionEnd'
|
38
|
+
, 'MozTransition' : 'transitionend'
|
39
|
+
, 'OTransition' : 'oTransitionEnd otransitionend'
|
40
|
+
, 'transition' : 'transitionend'
|
41
|
+
}
|
42
|
+
, name
|
43
|
+
|
44
|
+
for (name in transEndEventNames){
|
45
|
+
if (el.style[name] !== undefined) {
|
46
|
+
return transEndEventNames[name]
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
}())
|
51
|
+
|
52
|
+
return transitionEnd && {
|
53
|
+
end: transitionEnd
|
54
|
+
}
|
55
|
+
|
56
|
+
})()
|
57
|
+
|
58
|
+
})
|
59
|
+
|
60
|
+
}(window.jQuery);
|
@@ -0,0 +1,335 @@
|
|
1
|
+
/* =============================================================
|
2
|
+
* bootstrap-typeahead.js v2.3.2
|
3
|
+
* http://twitter.github.com/bootstrap/javascript.html#typeahead
|
4
|
+
* =============================================================
|
5
|
+
* Copyright 2012 Twitter, Inc.
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
* ============================================================ */
|
19
|
+
|
20
|
+
|
21
|
+
!function($){
|
22
|
+
|
23
|
+
"use strict"; // jshint ;_;
|
24
|
+
|
25
|
+
|
26
|
+
/* TYPEAHEAD PUBLIC CLASS DEFINITION
|
27
|
+
* ================================= */
|
28
|
+
|
29
|
+
var Typeahead = function (element, options) {
|
30
|
+
this.$element = $(element)
|
31
|
+
this.options = $.extend({}, $.fn.typeahead.defaults, options)
|
32
|
+
this.matcher = this.options.matcher || this.matcher
|
33
|
+
this.sorter = this.options.sorter || this.sorter
|
34
|
+
this.highlighter = this.options.highlighter || this.highlighter
|
35
|
+
this.updater = this.options.updater || this.updater
|
36
|
+
this.source = this.options.source
|
37
|
+
this.$menu = $(this.options.menu)
|
38
|
+
this.shown = false
|
39
|
+
this.listen()
|
40
|
+
}
|
41
|
+
|
42
|
+
Typeahead.prototype = {
|
43
|
+
|
44
|
+
constructor: Typeahead
|
45
|
+
|
46
|
+
, select: function () {
|
47
|
+
var val = this.$menu.find('.active').attr('data-value')
|
48
|
+
this.$element
|
49
|
+
.val(this.updater(val))
|
50
|
+
.change()
|
51
|
+
return this.hide()
|
52
|
+
}
|
53
|
+
|
54
|
+
, updater: function (item) {
|
55
|
+
return item
|
56
|
+
}
|
57
|
+
|
58
|
+
, show: function () {
|
59
|
+
var pos = $.extend({}, this.$element.position(), {
|
60
|
+
height: this.$element[0].offsetHeight
|
61
|
+
})
|
62
|
+
|
63
|
+
this.$menu
|
64
|
+
.insertAfter(this.$element)
|
65
|
+
.css({
|
66
|
+
top: pos.top + pos.height
|
67
|
+
, left: pos.left
|
68
|
+
})
|
69
|
+
.show()
|
70
|
+
|
71
|
+
this.shown = true
|
72
|
+
return this
|
73
|
+
}
|
74
|
+
|
75
|
+
, hide: function () {
|
76
|
+
this.$menu.hide()
|
77
|
+
this.shown = false
|
78
|
+
return this
|
79
|
+
}
|
80
|
+
|
81
|
+
, lookup: function (event) {
|
82
|
+
var items
|
83
|
+
|
84
|
+
this.query = this.$element.val()
|
85
|
+
|
86
|
+
if (!this.query || this.query.length < this.options.minLength) {
|
87
|
+
return this.shown ? this.hide() : this
|
88
|
+
}
|
89
|
+
|
90
|
+
items = $.isFunction(this.source) ? this.source(this.query, $.proxy(this.process, this)) : this.source
|
91
|
+
|
92
|
+
return items ? this.process(items) : this
|
93
|
+
}
|
94
|
+
|
95
|
+
, process: function (items) {
|
96
|
+
var that = this
|
97
|
+
|
98
|
+
items = $.grep(items, function (item) {
|
99
|
+
return that.matcher(item)
|
100
|
+
})
|
101
|
+
|
102
|
+
items = this.sorter(items)
|
103
|
+
|
104
|
+
if (!items.length) {
|
105
|
+
return this.shown ? this.hide() : this
|
106
|
+
}
|
107
|
+
|
108
|
+
return this.render(items.slice(0, this.options.items)).show()
|
109
|
+
}
|
110
|
+
|
111
|
+
, matcher: function (item) {
|
112
|
+
return ~item.toLowerCase().indexOf(this.query.toLowerCase())
|
113
|
+
}
|
114
|
+
|
115
|
+
, sorter: function (items) {
|
116
|
+
var beginswith = []
|
117
|
+
, caseSensitive = []
|
118
|
+
, caseInsensitive = []
|
119
|
+
, item
|
120
|
+
|
121
|
+
while (item = items.shift()) {
|
122
|
+
if (!item.toLowerCase().indexOf(this.query.toLowerCase())) beginswith.push(item)
|
123
|
+
else if (~item.indexOf(this.query)) caseSensitive.push(item)
|
124
|
+
else caseInsensitive.push(item)
|
125
|
+
}
|
126
|
+
|
127
|
+
return beginswith.concat(caseSensitive, caseInsensitive)
|
128
|
+
}
|
129
|
+
|
130
|
+
, highlighter: function (item) {
|
131
|
+
var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&')
|
132
|
+
return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
|
133
|
+
return '<strong>' + match + '</strong>'
|
134
|
+
})
|
135
|
+
}
|
136
|
+
|
137
|
+
, render: function (items) {
|
138
|
+
var that = this
|
139
|
+
|
140
|
+
items = $(items).map(function (i, item) {
|
141
|
+
i = $(that.options.item).attr('data-value', item)
|
142
|
+
i.find('a').html(that.highlighter(item))
|
143
|
+
return i[0]
|
144
|
+
})
|
145
|
+
|
146
|
+
items.first().addClass('active')
|
147
|
+
this.$menu.html(items)
|
148
|
+
return this
|
149
|
+
}
|
150
|
+
|
151
|
+
, next: function (event) {
|
152
|
+
var active = this.$menu.find('.active').removeClass('active')
|
153
|
+
, next = active.next()
|
154
|
+
|
155
|
+
if (!next.length) {
|
156
|
+
next = $(this.$menu.find('li')[0])
|
157
|
+
}
|
158
|
+
|
159
|
+
next.addClass('active')
|
160
|
+
}
|
161
|
+
|
162
|
+
, prev: function (event) {
|
163
|
+
var active = this.$menu.find('.active').removeClass('active')
|
164
|
+
, prev = active.prev()
|
165
|
+
|
166
|
+
if (!prev.length) {
|
167
|
+
prev = this.$menu.find('li').last()
|
168
|
+
}
|
169
|
+
|
170
|
+
prev.addClass('active')
|
171
|
+
}
|
172
|
+
|
173
|
+
, listen: function () {
|
174
|
+
this.$element
|
175
|
+
.on('focus', $.proxy(this.focus, this))
|
176
|
+
.on('blur', $.proxy(this.blur, this))
|
177
|
+
.on('keypress', $.proxy(this.keypress, this))
|
178
|
+
.on('keyup', $.proxy(this.keyup, this))
|
179
|
+
|
180
|
+
if (this.eventSupported('keydown')) {
|
181
|
+
this.$element.on('keydown', $.proxy(this.keydown, this))
|
182
|
+
}
|
183
|
+
|
184
|
+
this.$menu
|
185
|
+
.on('click', $.proxy(this.click, this))
|
186
|
+
.on('mouseenter', 'li', $.proxy(this.mouseenter, this))
|
187
|
+
.on('mouseleave', 'li', $.proxy(this.mouseleave, this))
|
188
|
+
}
|
189
|
+
|
190
|
+
, eventSupported: function(eventName) {
|
191
|
+
var isSupported = eventName in this.$element
|
192
|
+
if (!isSupported) {
|
193
|
+
this.$element.setAttribute(eventName, 'return;')
|
194
|
+
isSupported = typeof this.$element[eventName] === 'function'
|
195
|
+
}
|
196
|
+
return isSupported
|
197
|
+
}
|
198
|
+
|
199
|
+
, move: function (e) {
|
200
|
+
if (!this.shown) return
|
201
|
+
|
202
|
+
switch(e.keyCode) {
|
203
|
+
case 9: // tab
|
204
|
+
case 13: // enter
|
205
|
+
case 27: // escape
|
206
|
+
e.preventDefault()
|
207
|
+
break
|
208
|
+
|
209
|
+
case 38: // up arrow
|
210
|
+
e.preventDefault()
|
211
|
+
this.prev()
|
212
|
+
break
|
213
|
+
|
214
|
+
case 40: // down arrow
|
215
|
+
e.preventDefault()
|
216
|
+
this.next()
|
217
|
+
break
|
218
|
+
}
|
219
|
+
|
220
|
+
e.stopPropagation()
|
221
|
+
}
|
222
|
+
|
223
|
+
, keydown: function (e) {
|
224
|
+
this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27])
|
225
|
+
this.move(e)
|
226
|
+
}
|
227
|
+
|
228
|
+
, keypress: function (e) {
|
229
|
+
if (this.suppressKeyPressRepeat) return
|
230
|
+
this.move(e)
|
231
|
+
}
|
232
|
+
|
233
|
+
, keyup: function (e) {
|
234
|
+
switch(e.keyCode) {
|
235
|
+
case 40: // down arrow
|
236
|
+
case 38: // up arrow
|
237
|
+
case 16: // shift
|
238
|
+
case 17: // ctrl
|
239
|
+
case 18: // alt
|
240
|
+
break
|
241
|
+
|
242
|
+
case 9: // tab
|
243
|
+
case 13: // enter
|
244
|
+
if (!this.shown) return
|
245
|
+
this.select()
|
246
|
+
break
|
247
|
+
|
248
|
+
case 27: // escape
|
249
|
+
if (!this.shown) return
|
250
|
+
this.hide()
|
251
|
+
break
|
252
|
+
|
253
|
+
default:
|
254
|
+
this.lookup()
|
255
|
+
}
|
256
|
+
|
257
|
+
e.stopPropagation()
|
258
|
+
e.preventDefault()
|
259
|
+
}
|
260
|
+
|
261
|
+
, focus: function (e) {
|
262
|
+
this.focused = true
|
263
|
+
}
|
264
|
+
|
265
|
+
, blur: function (e) {
|
266
|
+
this.focused = false
|
267
|
+
if (!this.mousedover && this.shown) this.hide()
|
268
|
+
}
|
269
|
+
|
270
|
+
, click: function (e) {
|
271
|
+
e.stopPropagation()
|
272
|
+
e.preventDefault()
|
273
|
+
this.select()
|
274
|
+
this.$element.focus()
|
275
|
+
}
|
276
|
+
|
277
|
+
, mouseenter: function (e) {
|
278
|
+
this.mousedover = true
|
279
|
+
this.$menu.find('.active').removeClass('active')
|
280
|
+
$(e.currentTarget).addClass('active')
|
281
|
+
}
|
282
|
+
|
283
|
+
, mouseleave: function (e) {
|
284
|
+
this.mousedover = false
|
285
|
+
if (!this.focused && this.shown) this.hide()
|
286
|
+
}
|
287
|
+
|
288
|
+
}
|
289
|
+
|
290
|
+
|
291
|
+
/* TYPEAHEAD PLUGIN DEFINITION
|
292
|
+
* =========================== */
|
293
|
+
|
294
|
+
var old = $.fn.typeahead
|
295
|
+
|
296
|
+
$.fn.typeahead = function (option) {
|
297
|
+
return this.each(function () {
|
298
|
+
var $this = $(this)
|
299
|
+
, data = $this.data('typeahead')
|
300
|
+
, options = typeof option == 'object' && option
|
301
|
+
if (!data) $this.data('typeahead', (data = new Typeahead(this, options)))
|
302
|
+
if (typeof option == 'string') data[option]()
|
303
|
+
})
|
304
|
+
}
|
305
|
+
|
306
|
+
$.fn.typeahead.defaults = {
|
307
|
+
source: []
|
308
|
+
, items: 8
|
309
|
+
, menu: '<ul class="typeahead dropdown-menu"></ul>'
|
310
|
+
, item: '<li><a href="#"></a></li>'
|
311
|
+
, minLength: 1
|
312
|
+
}
|
313
|
+
|
314
|
+
$.fn.typeahead.Constructor = Typeahead
|
315
|
+
|
316
|
+
|
317
|
+
/* TYPEAHEAD NO CONFLICT
|
318
|
+
* =================== */
|
319
|
+
|
320
|
+
$.fn.typeahead.noConflict = function () {
|
321
|
+
$.fn.typeahead = old
|
322
|
+
return this
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
/* TYPEAHEAD DATA-API
|
327
|
+
* ================== */
|
328
|
+
|
329
|
+
$(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) {
|
330
|
+
var $this = $(this)
|
331
|
+
if ($this.data('typeahead')) return
|
332
|
+
$this.typeahead($this.data())
|
333
|
+
})
|
334
|
+
|
335
|
+
}(window.jQuery);
|