flatui3-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +102 -0
  5. data/Rakefile +1 -0
  6. data/app/assets/fonts/Flat-UI-Icons.dev.svg +140 -0
  7. data/app/assets/fonts/Flat-UI-Icons.eot +0 -0
  8. data/app/assets/fonts/Flat-UI-Icons.svg +140 -0
  9. data/app/assets/fonts/Flat-UI-Icons.ttf +0 -0
  10. data/app/assets/fonts/Flat-UI-Icons.woff +0 -0
  11. data/app/assets/fonts/icomoon-session.json +1 -0
  12. data/app/assets/fonts/lato/lato-black-webfont.eot +0 -0
  13. data/app/assets/fonts/lato/lato-black-webfont.svg +4691 -0
  14. data/app/assets/fonts/lato/lato-black-webfont.ttf +0 -0
  15. data/app/assets/fonts/lato/lato-black-webfont.woff +0 -0
  16. data/app/assets/fonts/lato/lato-bold-webfont.eot +0 -0
  17. data/app/assets/fonts/lato/lato-bold-webfont.svg +5085 -0
  18. data/app/assets/fonts/lato/lato-bold-webfont.ttf +0 -0
  19. data/app/assets/fonts/lato/lato-bold-webfont.woff +0 -0
  20. data/app/assets/fonts/lato/lato-bolditalic-webfont.eot +0 -0
  21. data/app/assets/fonts/lato/lato-bolditalic-webfont.svg +4514 -0
  22. data/app/assets/fonts/lato/lato-bolditalic-webfont.ttf +0 -0
  23. data/app/assets/fonts/lato/lato-bolditalic-webfont.woff +0 -0
  24. data/app/assets/fonts/lato/lato-italic-webfont.eot +0 -0
  25. data/app/assets/fonts/lato/lato-italic-webfont.svg +4514 -0
  26. data/app/assets/fonts/lato/lato-italic-webfont.ttf +0 -0
  27. data/app/assets/fonts/lato/lato-italic-webfont.woff +0 -0
  28. data/app/assets/fonts/lato/lato-light-webfont.eot +0 -0
  29. data/app/assets/fonts/lato/lato-light-webfont.svg +4691 -0
  30. data/app/assets/fonts/lato/lato-light-webfont.ttf +0 -0
  31. data/app/assets/fonts/lato/lato-light-webfont.woff +0 -0
  32. data/app/assets/fonts/lato/lato-regular-webfont.eot +0 -0
  33. data/app/assets/fonts/lato/lato-regular-webfont.svg +4691 -0
  34. data/app/assets/fonts/lato/lato-regular-webfont.ttf +0 -0
  35. data/app/assets/fonts/lato/lato-regular-webfont.woff +0 -0
  36. data/app/assets/images/demo/browser-2x.png +0 -0
  37. data/app/assets/images/demo/browser-author.jpg +0 -0
  38. data/app/assets/images/demo/browser-pic-1.jpg +0 -0
  39. data/app/assets/images/demo/browser-pic-2.jpg +0 -0
  40. data/app/assets/images/demo/browser-pic-3.jpg +0 -0
  41. data/app/assets/images/demo/browser-pic-4.jpg +0 -0
  42. data/app/assets/images/demo/browser-pic-5.jpg +0 -0
  43. data/app/assets/images/demo/browser-pic-6.jpg +0 -0
  44. data/app/assets/images/demo/browser.png +0 -0
  45. data/app/assets/images/demo/html-icon.png +0 -0
  46. data/app/assets/images/demo/logo-mask-2x.png +0 -0
  47. data/app/assets/images/demo/logo-mask.png +0 -0
  48. data/app/assets/images/demo/video.jpg +0 -0
  49. data/app/assets/images/exaple-image.jpg +0 -0
  50. data/app/assets/images/favicon.ico +0 -0
  51. data/app/assets/images/footer/logo.png +0 -0
  52. data/app/assets/images/icons/png/Book.png +0 -0
  53. data/app/assets/images/icons/png/Calendar.png +0 -0
  54. data/app/assets/images/icons/png/Chat.png +0 -0
  55. data/app/assets/images/icons/png/Clipboard.png +0 -0
  56. data/app/assets/images/icons/png/Compas.png +0 -0
  57. data/app/assets/images/icons/png/Gift-Box.png +0 -0
  58. data/app/assets/images/icons/png/Infinity-Loop.png +0 -0
  59. data/app/assets/images/icons/png/Mail.png +0 -0
  60. data/app/assets/images/icons/png/Map.png +0 -0
  61. data/app/assets/images/icons/png/Pensils.png +0 -0
  62. data/app/assets/images/icons/png/Pocket.png +0 -0
  63. data/app/assets/images/icons/png/Retina-Ready.png +0 -0
  64. data/app/assets/images/icons/png/Toilet-Paper.png +0 -0
  65. data/app/assets/images/icons/png/Watches.png +0 -0
  66. data/app/assets/images/icons/svg/book.svg +1 -0
  67. data/app/assets/images/icons/svg/calendar.svg +1 -0
  68. data/app/assets/images/icons/svg/chat.svg +1 -0
  69. data/app/assets/images/icons/svg/clipboard.svg +1 -0
  70. data/app/assets/images/icons/svg/clocks.svg +9 -0
  71. data/app/assets/images/icons/svg/compas.svg +1 -0
  72. data/app/assets/images/icons/svg/gift-box.svg +1 -0
  73. data/app/assets/images/icons/svg/loop.svg +5 -0
  74. data/app/assets/images/icons/svg/mail.svg +1 -0
  75. data/app/assets/images/icons/svg/map.svg +1 -0
  76. data/app/assets/images/icons/svg/paper-bag.svg +1 -0
  77. data/app/assets/images/icons/svg/pencils.svg +1 -0
  78. data/app/assets/images/icons/svg/retina.svg +1 -0
  79. data/app/assets/images/icons/svg/toilet-paper.svg +1 -0
  80. data/app/assets/images/login/icon.png +0 -0
  81. data/app/assets/images/login/imac-2x.png +0 -0
  82. data/app/assets/images/login/imac.png +0 -0
  83. data/app/assets/images/switch/mask-square.png +0 -0
  84. data/app/assets/images/switch/mask.png +0 -0
  85. data/app/assets/images/tile/ribbon-2x.png +0 -0
  86. data/app/assets/images/tile/ribbon.png +0 -0
  87. data/app/assets/images/todo/done-2x.png +0 -0
  88. data/app/assets/images/todo/done.png +0 -0
  89. data/app/assets/images/todo/search-2x.png +0 -0
  90. data/app/assets/images/todo/search.png +0 -0
  91. data/app/assets/images/todo/todo-2x.png +0 -0
  92. data/app/assets/images/todo/todo.png +0 -0
  93. data/app/assets/images/video/fullscreen-2x.png +0 -0
  94. data/app/assets/images/video/fullscreen.png +0 -0
  95. data/app/assets/images/video/pause-2x.png +0 -0
  96. data/app/assets/images/video/pause.png +0 -0
  97. data/app/assets/images/video/play-2x.png +0 -0
  98. data/app/assets/images/video/play.png +0 -0
  99. data/app/assets/images/video/poster.jpg +0 -0
  100. data/app/assets/images/video/volume-full-2x.png +0 -0
  101. data/app/assets/images/video/volume-full.png +0 -0
  102. data/app/assets/images/video/volume-off-2x.png +0 -0
  103. data/app/assets/images/video/volume-off.png +0 -0
  104. data/app/assets/javascripts/bootstrap-select.js +412 -0
  105. data/app/assets/javascripts/bootstrap-switch.js +251 -0
  106. data/app/assets/javascripts/bootstrap-typeahead.js +335 -0
  107. data/app/assets/javascripts/flatui-checkbox.js +112 -0
  108. data/app/assets/javascripts/flatui-radio.js +141 -0
  109. data/app/assets/javascripts/flatui.js +9 -0
  110. data/app/assets/javascripts/html5shiv.js +8 -0
  111. data/app/assets/javascripts/icon-font-ie7.js +57 -0
  112. data/app/assets/javascripts/jquery-ui-1.10.3.min.js +6 -0
  113. data/app/assets/javascripts/jquery.placeholder.js +157 -0
  114. data/app/assets/javascripts/jquery.stacktable.js +54 -0
  115. data/app/assets/javascripts/jquery.tagsinput.js +355 -0
  116. data/app/assets/javascripts/jquery.ui.touch-punch.min.js +11 -0
  117. data/app/assets/stylesheets/flatui.less +45 -0
  118. data/flatui3-rails.gemspec +25 -0
  119. data/lib/flatui3-rails.rb +1 -0
  120. data/lib/flatui3/rails.rb +7 -0
  121. data/lib/flatui3/rails/engine.rb +13 -0
  122. data/lib/flatui3/rails/version.rb +5 -0
  123. data/lib/generators/flatui3/override/override_generator.rb +15 -0
  124. data/lib/generators/flatui3/override/templates/flatui_and_overrides.less +49 -0
  125. data/vendor/toolkit/flat-ui/flat-ui.less +45 -0
  126. data/vendor/toolkit/flat-ui/fonts.less +65 -0
  127. data/vendor/toolkit/flat-ui/icon-font.less +128 -0
  128. data/vendor/toolkit/flat-ui/mixins.less +365 -0
  129. data/vendor/toolkit/flat-ui/modules/buttons.less +231 -0
  130. data/vendor/toolkit/flat-ui/modules/caret.less +31 -0
  131. data/vendor/toolkit/flat-ui/modules/checkbox-and-radio.less +104 -0
  132. data/vendor/toolkit/flat-ui/modules/dropdown.less +225 -0
  133. data/vendor/toolkit/flat-ui/modules/footer.less +75 -0
  134. data/vendor/toolkit/flat-ui/modules/forms.less +127 -0
  135. data/vendor/toolkit/flat-ui/modules/input-icons.less +71 -0
  136. data/vendor/toolkit/flat-ui/modules/login.less +111 -0
  137. data/vendor/toolkit/flat-ui/modules/navbar.less +487 -0
  138. data/vendor/toolkit/flat-ui/modules/pager.less +49 -0
  139. data/vendor/toolkit/flat-ui/modules/pagination.less +153 -0
  140. data/vendor/toolkit/flat-ui/modules/palette.less +64 -0
  141. data/vendor/toolkit/flat-ui/modules/progress-bars.less +36 -0
  142. data/vendor/toolkit/flat-ui/modules/select.less +143 -0
  143. data/vendor/toolkit/flat-ui/modules/share.less +41 -0
  144. data/vendor/toolkit/flat-ui/modules/switch.less +150 -0
  145. data/vendor/toolkit/flat-ui/modules/tagsinput.less +117 -0
  146. data/vendor/toolkit/flat-ui/modules/tile.less +54 -0
  147. data/vendor/toolkit/flat-ui/modules/todo.less +107 -0
  148. data/vendor/toolkit/flat-ui/modules/tooltip.less +55 -0
  149. data/vendor/toolkit/flat-ui/modules/type.less +126 -0
  150. data/vendor/toolkit/flat-ui/modules/ui-slider.less +62 -0
  151. data/vendor/toolkit/flat-ui/modules/video.less +458 -0
  152. data/vendor/toolkit/flat-ui/scaffolding.less +46 -0
  153. data/vendor/toolkit/flat-ui/spaces.less +172 -0
  154. data/vendor/toolkit/flat-ui/variables.less +167 -0
  155. metadata +248 -0
@@ -0,0 +1,251 @@
1
+ /* ============================================================
2
+ * bootstrapSwitch v1.3 by Larentis Mattia @spiritualGuru
3
+ * http://www.larentis.eu/switch/
4
+ * ============================================================
5
+ * Licensed under the Apache License, Version 2.0
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ * ============================================================ */
8
+
9
+ !function ($) {
10
+ "use strict";
11
+
12
+ $.fn['bootstrapSwitch'] = function (method) {
13
+ var methods = {
14
+ init: function () {
15
+ return this.each(function () {
16
+ var $element = $(this)
17
+ , $div
18
+ , $switchLeft
19
+ , $switchRight
20
+ , $label
21
+ , myClasses = ""
22
+ , classes = $element.attr('class')
23
+ , color
24
+ , moving
25
+ , onLabel = "ON"
26
+ , offLabel = "OFF"
27
+ , icon = false;
28
+
29
+ $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
30
+ if (classes.indexOf(el) >= 0)
31
+ myClasses = el;
32
+ });
33
+
34
+ $element.addClass('has-switch');
35
+
36
+ if ($element.data('on') !== undefined)
37
+ color = "switch-" + $element.data('on');
38
+
39
+ if ($element.data('on-label') !== undefined)
40
+ onLabel = $element.data('on-label');
41
+
42
+ if ($element.data('off-label') !== undefined)
43
+ offLabel = $element.data('off-label');
44
+
45
+ if ($element.data('icon') !== undefined)
46
+ icon = $element.data('icon');
47
+
48
+ $switchLeft = $('<span>')
49
+ .addClass("switch-left")
50
+ .addClass(myClasses)
51
+ .addClass(color)
52
+ .html(onLabel);
53
+
54
+ color = '';
55
+ if ($element.data('off') !== undefined)
56
+ color = "switch-" + $element.data('off');
57
+
58
+ $switchRight = $('<span>')
59
+ .addClass("switch-right")
60
+ .addClass(myClasses)
61
+ .addClass(color)
62
+ .html(offLabel);
63
+
64
+ $label = $('<label>')
65
+ .html("&nbsp;")
66
+ .addClass(myClasses)
67
+ .attr('for', $element.find('input').attr('id'));
68
+
69
+ if (icon) {
70
+ $label.html('<i class="' + icon + '"></i>');
71
+ }
72
+
73
+ $div = $element.find(':checkbox').wrap($('<div>')).parent().data('animated', false);
74
+
75
+ if ($element.data('animated') !== false)
76
+ $div.addClass('switch-animate').data('animated', true);
77
+
78
+ $div
79
+ .append($switchLeft)
80
+ .append($label)
81
+ .append($switchRight);
82
+
83
+ $element.find('>div').addClass(
84
+ $element.find('input').is(':checked') ? 'switch-on' : 'switch-off'
85
+ );
86
+
87
+ if ($element.find('input').is(':disabled'))
88
+ $(this).addClass('deactivate');
89
+
90
+ var changeStatus = function ($this) {
91
+ $this.siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
92
+ };
93
+
94
+ $element.on('keydown', function (e) {
95
+ if (e.keyCode === 32) {
96
+ e.stopImmediatePropagation();
97
+ e.preventDefault();
98
+ changeStatus($(e.target).find('span:first'));
99
+ }
100
+ });
101
+
102
+ $switchLeft.on('click', function (e) {
103
+ changeStatus($(this));
104
+ });
105
+
106
+ $switchRight.on('click', function (e) {
107
+ changeStatus($(this));
108
+ });
109
+
110
+ $element.find('input').on('change', function (e) {
111
+ var $this = $(this)
112
+ , $element = $this.parent()
113
+ , thisState = $this.is(':checked')
114
+ , state = $element.is('.switch-off');
115
+
116
+ e.preventDefault();
117
+
118
+ $element.css('left', '');
119
+
120
+ if (state === thisState) {
121
+
122
+ if (thisState)
123
+ $element.removeClass('switch-off').addClass('switch-on');
124
+ else $element.removeClass('switch-on').addClass('switch-off');
125
+
126
+ if ($element.data('animated') !== false)
127
+ $element.addClass("switch-animate");
128
+
129
+ $element.parent().trigger('switch-change', {'el': $this, 'value': thisState})
130
+ }
131
+ });
132
+
133
+ $element.find('label').on('mousedown touchstart', function (e) {
134
+ var $this = $(this);
135
+ moving = false;
136
+
137
+ e.preventDefault();
138
+ e.stopImmediatePropagation();
139
+
140
+ $this.closest('div').removeClass('switch-animate');
141
+
142
+ if ($this.closest('.has-switch').is('.deactivate'))
143
+ $this.unbind('click');
144
+ else {
145
+ $this.on('mousemove touchmove', function (e) {
146
+ var $element = $(this).closest('.switch')
147
+ , relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $element.offset().left
148
+ , percent = (relativeX / $element.width()) * 100
149
+ , left = 25
150
+ , right = 75;
151
+
152
+ moving = true;
153
+
154
+ if (percent < left)
155
+ percent = left;
156
+ else if (percent > right)
157
+ percent = right;
158
+
159
+ $element.find('>div').css('left', (percent - right) + "%")
160
+ });
161
+
162
+ $this.on('click touchend', function (e) {
163
+ var $this = $(this)
164
+ , $target = $(e.target)
165
+ , $myCheckBox = $target.siblings('input');
166
+
167
+ e.stopImmediatePropagation();
168
+ e.preventDefault();
169
+
170
+ $this.unbind('mouseleave');
171
+
172
+ if (moving)
173
+ $myCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25));
174
+ else $myCheckBox.prop("checked", !$myCheckBox.is(":checked"));
175
+
176
+ moving = false;
177
+ $myCheckBox.trigger('change');
178
+ });
179
+
180
+ $this.on('mouseleave', function (e) {
181
+ var $this = $(this)
182
+ , $myCheckBox = $this.siblings('input');
183
+
184
+ e.preventDefault();
185
+ e.stopImmediatePropagation();
186
+
187
+ $this.unbind('mouseleave');
188
+ $this.trigger('mouseup');
189
+
190
+ $myCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25)).trigger('change');
191
+ });
192
+
193
+ $this.on('mouseup', function (e) {
194
+ e.stopImmediatePropagation();
195
+ e.preventDefault();
196
+
197
+ $(this).unbind('mousemove');
198
+ });
199
+ }
200
+ });
201
+ }
202
+ );
203
+ },
204
+ toggleActivation: function () {
205
+ $(this).toggleClass('deactivate');
206
+ },
207
+ isActive: function () {
208
+ return !$(this).hasClass('deactivate');
209
+ },
210
+ setActive: function (active) {
211
+ if (active)
212
+ $(this).removeClass('deactivate');
213
+ else $(this).addClass('deactivate');
214
+ },
215
+ toggleState: function (skipOnChange) {
216
+ var $input = $(this).find('input:checkbox');
217
+ $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
218
+ },
219
+ setState: function (value, skipOnChange) {
220
+ $(this).find('input:checkbox').prop('checked', value).trigger('change', skipOnChange);
221
+ },
222
+ status: function () {
223
+ return $(this).find('input:checkbox').is(':checked');
224
+ },
225
+ destroy: function () {
226
+ var $div = $(this).find('div')
227
+ , $checkbox;
228
+
229
+ $div.find(':not(input:checkbox)').remove();
230
+
231
+ $checkbox = $div.children();
232
+ $checkbox.unwrap().unwrap();
233
+
234
+ $checkbox.unbind('change');
235
+
236
+ return $checkbox;
237
+ }
238
+ };
239
+
240
+ if (methods[method])
241
+ return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
242
+ else if (typeof method === 'object' || !method)
243
+ return methods.init.apply(this, arguments);
244
+ else
245
+ $.error('Method ' + method + ' does not exist!');
246
+ };
247
+ }(jQuery);
248
+
249
+ $(function () {
250
+ $('.switch')['bootstrapSwitch']();
251
+ });
@@ -0,0 +1,335 @@
1
+ /* =============================================================
2
+ * bootstrap-typeahead.js v2.3.2
3
+ * http://getbootstrap.com/2.3.2/javascript.html#typeahead
4
+ * =============================================================
5
+ * Copyright 2013 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);