compass-jquery-plugin 0.3.3.0 → 0.3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. data/README.md +4 -4
  2. data/VERSION.yml +1 -1
  3. data/lib/handle_js_files.rb +1 -1
  4. data/lib/jquery/gridify/grid_column.rb +4 -0
  5. data/lib/jquery/gridify/grid_options.rb +5 -1
  6. data/lib/jquery/gridify/grid_view.rb +8 -3
  7. data/templates/dynatree/jquery.dynatree.js +184 -73
  8. data/templates/dynatree/jquery.dynatree.min.js +78 -76
  9. data/templates/emulators/emulators/galaxy.tab.7.7.landscape.png +0 -0
  10. data/templates/emulators/emulators/{palm.pre.2.landscape.scss → galaxy.tab.7.7.landscape.scss} +7 -7
  11. data/templates/emulators/emulators/galaxy.tab.7.7.portrait.png +0 -0
  12. data/templates/emulators/emulators/{palm.pre.2.portrait.scss → galaxy.tab.7.7.portrait.scss} +7 -7
  13. data/templates/emulators/manifest.rb +4 -4
  14. data/templates/graphics/config/initializers/graphics.rb +1 -1
  15. data/templates/graphics/highcharts/dark-blue.js +257 -159
  16. data/templates/graphics/highcharts/dark-blue.min.js +4 -2
  17. data/templates/graphics/highcharts/dark-green.js +257 -159
  18. data/templates/graphics/highcharts/dark-green.min.js +4 -2
  19. data/templates/graphics/highcharts/gray.js +252 -154
  20. data/templates/graphics/highcharts/gray.min.js +4 -2
  21. data/templates/graphics/highcharts/grid.js +84 -84
  22. data/templates/graphics/highcharts/highslide-full.min.js +3 -3
  23. data/templates/graphics/highcharts/highslide.js +3391 -0
  24. data/templates/graphics/highcharts/highslide.min.js +132 -0
  25. data/templates/graphics/jquery.ganttView.min.js +4 -4
  26. data/templates/graphics/jquery.highcharts.js +15379 -1071
  27. data/templates/graphics/jquery.highcharts.min.js +384 -167
  28. data/templates/graphics/jquery.sparkline.min.js +2 -2
  29. data/templates/graphics/manifest.rb +2 -0
  30. data/templates/ical/jquery.ical.min.js +46 -47
  31. data/templates/jqgrid/i18n/jqgrid/locale-bg.min.js +2 -2
  32. data/templates/jqgrid/i18n/jqgrid/locale-bg1251.min.js +2 -2
  33. data/templates/jqgrid/i18n/jqgrid/locale-fi.js +20 -19
  34. data/templates/jqgrid/i18n/jqgrid/locale-fi.min.js +7 -6
  35. data/templates/jqgrid/i18n/jqgrid/locale-is.js +28 -28
  36. data/templates/jqgrid/i18n/jqgrid/locale-is.min.js +6 -6
  37. data/templates/jqgrid/i18n/jqgrid/locale-th.js +134 -0
  38. data/templates/jqgrid/i18n/jqgrid/locale-th.min.js +6 -0
  39. data/templates/jqgrid/jquery.jqGrid.js +674 -598
  40. data/templates/jqgrid/jquery.jqGrid.min.js +444 -441
  41. data/templates/jqgrid/jquery/jqGrid.scss +0 -3
  42. data/templates/jqgrid/manifest.rb +2 -0
  43. data/templates/jqtouch/jquery.jqtouch.js +201 -156
  44. data/templates/jqtouch/jquery.jqtouch.min.js +1 -1
  45. data/templates/jqtouch/jquery/touch/apple.scss +2 -2
  46. data/templates/jqtouch/jquery/touch/default.scss +2 -2
  47. data/templates/jquery/amplify.store.js +111 -78
  48. data/templates/jquery/amplify.store.min.js +6 -6
  49. data/templates/jquery/history.js +3 -3
  50. data/templates/jquery/i18n/jquery.ui/datepicker-nl.js +1 -1
  51. data/templates/jquery/i18n/jquery.ui/datepicker-nl.min.js +1 -1
  52. data/templates/jquery/jquery-ui.js +1286 -1042
  53. data/templates/jquery/jquery-ui.min.js +320 -316
  54. data/templates/jquery/jquery.contextMenu.js +2 -2
  55. data/templates/jquery/jquery.easing.js +152 -152
  56. data/templates/jquery/jquery.easing.min.js +7 -7
  57. data/templates/jquery/jquery.farbtastic.min.js +2 -2
  58. data/templates/jquery/jquery.form.js +30 -30
  59. data/templates/jquery/jquery.haml.min.js +5 -5
  60. data/templates/jquery/jquery.hotkeys.min.js +1 -1
  61. data/templates/jquery/jquery.js +419 -311
  62. data/templates/jquery/jquery.layout.js +59 -40
  63. data/templates/jquery/jquery.min.js +176 -176
  64. data/templates/jquery/jquery.themeswitchertool.js +37 -37
  65. data/templates/jquery/jquery.tmpl.js +4 -4
  66. data/templates/jquery/jquery.tmpl.min.js +9 -9
  67. data/templates/jquery/jquery.tmplPlus.min.js +3 -3
  68. data/templates/jquery/jquery.tokeninput.js +613 -490
  69. data/templates/jquery/jquery.tokeninput.min.js +17 -14
  70. data/templates/jquery/jquery/ui/_theme.scss +39 -63
  71. data/templates/jquery/json.js +31 -15
  72. data/templates/jstree/jquery.jstree.js +415 -410
  73. data/templates/jstree/jquery.jstree.min.js +134 -133
  74. data/templates/markitup/jquery.markitup.js +567 -560
  75. data/templates/markitup/jquery.markitup.min.js +1 -1
  76. data/templates/markitup/jquery/markitup/sets/default.scss +7 -3
  77. data/templates/markitup/jquery/markitup/sets/default/list-bullet.png +0 -0
  78. data/templates/markitup/jquery/markitup/sets/default/list-numeric.png +0 -0
  79. data/templates/markitup/jquery/markitup/skins/markitup.scss +3 -10
  80. data/templates/markitup/jquery/markitup/skins/markitup/bg-container.png +0 -0
  81. data/templates/markitup/jquery/markitup/skins/markitup/menu.png +0 -0
  82. data/templates/markitup/jquery/markitup/skins/simple.scss +2 -3
  83. data/templates/markitup/jquery/markitup/skins/simple/menu.png +0 -0
  84. data/templates/markitup/manifest.rb +2 -0
  85. data/templates/markitup/markitup/jquery.markitup.set.default.js +21 -21
  86. data/templates/markitup/markitup/jquery.markitup.set.default.min.js +3 -2
  87. data/templates/mobile/jquery.mobile.js +5230 -2846
  88. data/templates/mobile/jquery.mobile.min.js +192 -46
  89. data/templates/mobile/jquery/mobile/_base.scss +141 -18
  90. data/templates/mobile/jquery/mobile/default.scss +263 -66
  91. data/templates/mobile/jquery/mobile/default/icons-18-black.png +0 -0
  92. data/templates/mobile/jquery/mobile/default/icons-18-white.png +0 -0
  93. data/templates/mobile/jquery/mobile/default/icons-36-black.png +0 -0
  94. data/templates/mobile/jquery/mobile/default/icons-36-white.png +0 -0
  95. data/templates/mobile/jquery/mobile/valencia.scss +242 -53
  96. data/templates/mobile/jquery/mobile/valencia/icons-18-black.png +0 -0
  97. data/templates/mobile/jquery/mobile/valencia/icons-18-white.png +0 -0
  98. data/templates/mobile/jquery/mobile/valencia/icons-36-black.png +0 -0
  99. data/templates/mobile/jquery/mobile/valencia/icons-36-white.png +0 -0
  100. data/templates/tiny_mce/manifest.rb +2 -0
  101. data/templates/tiny_mce/tiny_mce/langs/de.js +1 -1
  102. data/templates/tiny_mce/tiny_mce/plugins/advhr/rule.htm +1 -1
  103. data/templates/tiny_mce/tiny_mce/plugins/advimage/editor_plugin.js +1 -1
  104. data/templates/tiny_mce/tiny_mce/plugins/advimage/editor_plugin_src.js +1 -1
  105. data/templates/tiny_mce/tiny_mce/plugins/advimage/image.htm +1 -1
  106. data/templates/tiny_mce/tiny_mce/plugins/advimage/js/image.js +1 -1
  107. data/templates/tiny_mce/tiny_mce/plugins/advlink/link.htm +1 -1
  108. data/templates/tiny_mce/tiny_mce/plugins/advlist/editor_plugin.js +1 -1
  109. data/templates/tiny_mce/tiny_mce/plugins/advlist/editor_plugin_src.js +1 -1
  110. data/templates/tiny_mce/tiny_mce/plugins/autolink/editor_plugin.js +1 -1
  111. data/templates/tiny_mce/tiny_mce/plugins/autolink/editor_plugin_src.js +1 -1
  112. data/templates/tiny_mce/tiny_mce/plugins/autoresize/editor_plugin.js +1 -1
  113. data/templates/tiny_mce/tiny_mce/plugins/autoresize/editor_plugin_src.js +1 -1
  114. data/templates/tiny_mce/tiny_mce/plugins/autosave/editor_plugin.js +1 -1
  115. data/templates/tiny_mce/tiny_mce/plugins/autosave/editor_plugin_src.js +1 -1
  116. data/templates/tiny_mce/tiny_mce/plugins/contextmenu/editor_plugin.js +1 -1
  117. data/templates/tiny_mce/tiny_mce/plugins/contextmenu/editor_plugin_src.js +1 -1
  118. data/templates/tiny_mce/tiny_mce/plugins/emotions/emotions.htm +1 -1
  119. data/templates/tiny_mce/tiny_mce/plugins/emotions/img/smiley-foot-in-mouth.gif +0 -0
  120. data/templates/tiny_mce/tiny_mce/plugins/emotions/img/smiley-laughing.gif +0 -0
  121. data/templates/tiny_mce/tiny_mce/plugins/emotions/img/smiley-sealed.gif +0 -0
  122. data/templates/tiny_mce/tiny_mce/plugins/emotions/img/smiley-smile.gif +0 -0
  123. data/templates/tiny_mce/tiny_mce/plugins/emotions/img/smiley-surprised.gif +0 -0
  124. data/templates/tiny_mce/tiny_mce/plugins/emotions/img/smiley-wink.gif +0 -0
  125. data/templates/tiny_mce/tiny_mce/plugins/example/dialog.htm +1 -1
  126. data/templates/tiny_mce/tiny_mce/plugins/example_dependency/editor_plugin.js +1 -0
  127. data/templates/tiny_mce/tiny_mce/plugins/example_dependency/editor_plugin_src.js +1 -0
  128. data/templates/tiny_mce/tiny_mce/plugins/fullpage/editor_plugin.js +1 -1
  129. data/templates/tiny_mce/tiny_mce/plugins/fullpage/editor_plugin_src.js +1 -1
  130. data/templates/tiny_mce/tiny_mce/plugins/fullpage/fullpage.htm +1 -1
  131. data/templates/tiny_mce/tiny_mce/plugins/inlinepopups/editor_plugin.js +1 -1
  132. data/templates/tiny_mce/tiny_mce/plugins/inlinepopups/editor_plugin_src.js +1 -1
  133. data/templates/tiny_mce/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/alert.gif +0 -0
  134. data/templates/tiny_mce/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/button.gif +0 -0
  135. data/templates/tiny_mce/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/confirm.gif +0 -0
  136. data/templates/tiny_mce/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/corners.gif +0 -0
  137. data/templates/tiny_mce/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/vertical.gif +0 -0
  138. data/templates/tiny_mce/tiny_mce/plugins/inlinepopups/skins/clearlooks2/window.css +1 -1
  139. data/templates/tiny_mce/tiny_mce/plugins/inlinepopups/template.htm +1 -1
  140. data/templates/tiny_mce/tiny_mce/plugins/lists/editor_plugin.js +1 -1
  141. data/templates/tiny_mce/tiny_mce/plugins/lists/editor_plugin_src.js +1 -1
  142. data/templates/tiny_mce/tiny_mce/plugins/media/editor_plugin.js +1 -1
  143. data/templates/tiny_mce/tiny_mce/plugins/media/editor_plugin_src.js +1 -1
  144. data/templates/tiny_mce/tiny_mce/plugins/media/js/media.js +1 -1
  145. data/templates/tiny_mce/tiny_mce/plugins/media/langs/en_dlg.js +1 -1
  146. data/templates/tiny_mce/tiny_mce/plugins/media/media.htm +1 -1
  147. data/templates/tiny_mce/tiny_mce/plugins/noneditable/editor_plugin.js +1 -1
  148. data/templates/tiny_mce/tiny_mce/plugins/noneditable/editor_plugin_src.js +1 -1
  149. data/templates/tiny_mce/tiny_mce/plugins/paste/editor_plugin.js +1 -1
  150. data/templates/tiny_mce/tiny_mce/plugins/paste/editor_plugin_src.js +1 -1
  151. data/templates/tiny_mce/tiny_mce/plugins/paste/pastetext.htm +1 -1
  152. data/templates/tiny_mce/tiny_mce/plugins/paste/pasteword.htm +1 -1
  153. data/templates/tiny_mce/tiny_mce/plugins/preview/example.html +16 -17
  154. data/templates/tiny_mce/tiny_mce/plugins/preview/preview.html +9 -10
  155. data/templates/tiny_mce/tiny_mce/plugins/searchreplace/searchreplace.htm +1 -1
  156. data/templates/tiny_mce/tiny_mce/plugins/spellchecker/editor_plugin.js +1 -1
  157. data/templates/tiny_mce/tiny_mce/plugins/spellchecker/editor_plugin_src.js +1 -1
  158. data/templates/tiny_mce/tiny_mce/plugins/style/js/props.js +1 -1
  159. data/templates/tiny_mce/tiny_mce/plugins/style/props.htm +1 -1
  160. data/templates/tiny_mce/tiny_mce/plugins/tabfocus/editor_plugin.js +1 -1
  161. data/templates/tiny_mce/tiny_mce/plugins/tabfocus/editor_plugin_src.js +1 -1
  162. data/templates/tiny_mce/tiny_mce/plugins/table/cell.htm +1 -1
  163. data/templates/tiny_mce/tiny_mce/plugins/table/editor_plugin.js +1 -1
  164. data/templates/tiny_mce/tiny_mce/plugins/table/editor_plugin_src.js +1 -1
  165. data/templates/tiny_mce/tiny_mce/plugins/table/js/cell.js +1 -1
  166. data/templates/tiny_mce/tiny_mce/plugins/table/js/row.js +1 -1
  167. data/templates/tiny_mce/tiny_mce/plugins/table/langs/de_dlg.js +1 -1
  168. data/templates/tiny_mce/tiny_mce/plugins/table/langs/en_dlg.js +1 -1
  169. data/templates/tiny_mce/tiny_mce/plugins/table/merge_cells.htm +1 -1
  170. data/templates/tiny_mce/tiny_mce/plugins/table/row.htm +1 -1
  171. data/templates/tiny_mce/tiny_mce/plugins/table/table.htm +1 -1
  172. data/templates/tiny_mce/tiny_mce/plugins/template/blank.htm +1 -1
  173. data/templates/tiny_mce/tiny_mce/plugins/template/template.htm +1 -1
  174. data/templates/tiny_mce/tiny_mce/plugins/wordcount/editor_plugin.js +1 -1
  175. data/templates/tiny_mce/tiny_mce/plugins/wordcount/editor_plugin_src.js +1 -1
  176. data/templates/tiny_mce/tiny_mce/plugins/xhtmlxtras/abbr.htm +1 -1
  177. data/templates/tiny_mce/tiny_mce/plugins/xhtmlxtras/acronym.htm +1 -1
  178. data/templates/tiny_mce/tiny_mce/plugins/xhtmlxtras/attributes.htm +1 -1
  179. data/templates/tiny_mce/tiny_mce/plugins/xhtmlxtras/cite.htm +1 -1
  180. data/templates/tiny_mce/tiny_mce/plugins/xhtmlxtras/del.htm +1 -1
  181. data/templates/tiny_mce/tiny_mce/plugins/xhtmlxtras/ins.htm +1 -1
  182. data/templates/tiny_mce/tiny_mce/themes/advanced/about.htm +1 -1
  183. data/templates/tiny_mce/tiny_mce/themes/advanced/anchor.htm +1 -1
  184. data/templates/tiny_mce/tiny_mce/themes/advanced/color_picker.htm +1 -1
  185. data/templates/tiny_mce/tiny_mce/themes/advanced/editor_template.js +1 -1
  186. data/templates/tiny_mce/tiny_mce/themes/advanced/editor_template_src.js +1 -1
  187. data/templates/tiny_mce/tiny_mce/themes/advanced/image.htm +1 -1
  188. data/templates/tiny_mce/tiny_mce/themes/advanced/img/colorpicker.jpg +0 -0
  189. data/templates/tiny_mce/tiny_mce/themes/advanced/img/flash.gif +0 -0
  190. data/templates/tiny_mce/tiny_mce/themes/advanced/img/icons.gif +0 -0
  191. data/templates/tiny_mce/tiny_mce/themes/advanced/img/quicktime.gif +0 -0
  192. data/templates/tiny_mce/tiny_mce/themes/advanced/img/shockwave.gif +0 -0
  193. data/templates/tiny_mce/tiny_mce/themes/advanced/js/image.js +1 -1
  194. data/templates/tiny_mce/tiny_mce/themes/advanced/langs/de.js +1 -1
  195. data/templates/tiny_mce/tiny_mce/themes/advanced/link.htm +1 -1
  196. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/default/content.css +1 -1
  197. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/default/dialog.css +1 -1
  198. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/default/img/buttons.png +0 -0
  199. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/default/img/items.gif +0 -0
  200. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/default/img/tabs.gif +0 -0
  201. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/default/ui.css +1 -1
  202. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/highcontrast/dialog.css +1 -1
  203. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/highcontrast/ui.css +1 -1
  204. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/o2k7/content.css +1 -1
  205. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/o2k7/dialog.css +1 -1
  206. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/o2k7/img/button_bg.png +0 -0
  207. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/o2k7/img/button_bg_black.png +0 -0
  208. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/o2k7/img/button_bg_silver.png +0 -0
  209. data/templates/tiny_mce/tiny_mce/themes/advanced/skins/o2k7/ui.css +1 -1
  210. data/templates/tiny_mce/tiny_mce/themes/advanced/source_editor.htm +1 -1
  211. data/templates/tiny_mce/tiny_mce/themes/simple/img/icons.gif +0 -0
  212. data/templates/tiny_mce/tiny_mce/themes/simple/skins/default/ui.css +1 -1
  213. data/templates/tiny_mce/tiny_mce/themes/simple/skins/o2k7/ui.css +1 -1
  214. data/templates/tiny_mce/tiny_mce/tiny_mce.js +1 -1
  215. data/templates/tools/flowplayer.min.js +1 -1
  216. data/templates/tools/jquery.tools.js +17 -17
  217. data/templates/tools/jquery.tools.min.js +22 -22
  218. metadata +17 -9
  219. data/templates/emulators/emulators/palm.pre.2.landscape.png +0 -0
  220. data/templates/emulators/emulators/palm.pre.2.portrait.png +0 -0
@@ -32,7 +32,7 @@ $.fn.themeswitcher = function(settings) {
32
32
  }
33
33
  return false;
34
34
  }
35
- );
35
+ );
36
36
 
37
37
  //menu events (mouseout didn't work...)
38
38
  switcherpane.hover(
@@ -43,7 +43,7 @@ $.fn.themeswitcher = function(settings) {
43
43
  $(this).spHide();
44
44
  }
45
45
  }
46
- );
46
+ );
47
47
 
48
48
  //show/hide panel functions
49
49
  $.fn.spShow = function() {
@@ -130,13 +130,13 @@ $.fn.themeswitcher = function(settings) {
130
130
  $(this).css(button_default);
131
131
  }
132
132
  }
133
- )
133
+ )
134
134
  .find('.jquery-ui-themeswitcher-icon').css({
135
- 'float': 'right',
136
- width: '16px',
137
- height: '16px',
138
- background: 'image_url("jquery/ui/themeSwitcher/icon_color_arrow.gif") 50% 50% no-repeat'
139
- });
135
+ 'float': 'right',
136
+ width: '16px',
137
+ height: '16px',
138
+ background: 'image_url("jquery/ui/themeSwitcher/icon_color_arrow.gif") 50% 50% no-repeat'
139
+ });
140
140
  //pane css
141
141
  switcherpane.css({
142
142
  position: 'absolute',
@@ -156,12 +156,12 @@ $.fn.themeswitcher = function(settings) {
156
156
  width: options.width - 6//minus must match left and right padding
157
157
  })
158
158
  .find('ul').css({
159
- listStyle: 'none',
160
- margin: '0',
161
- padding: '0',
162
- overflow: 'auto',
163
- height: options.height
164
- }).end()
159
+ listStyle: 'none',
160
+ margin: '0',
161
+ padding: '0',
162
+ overflow: 'auto',
163
+ height: options.height
164
+ }).end()
165
165
  .find('li').hover(
166
166
  function() {
167
167
  $(this).css({
@@ -177,32 +177,32 @@ $.fn.themeswitcher = function(settings) {
177
177
  cursor: 'auto'
178
178
  });
179
179
  }
180
- ).css({
181
- width: options.width - 30,
182
- height: '',
183
- padding: '2px',
184
- margin: '1px',
185
- border: '1px solid #111',
186
- '-moz-border-radius': '4px',
187
- clear: 'left',
188
- 'float': 'left'
189
- }).end()
180
+ ).css({
181
+ width: options.width - 30,
182
+ height: '',
183
+ padding: '2px',
184
+ margin: '1px',
185
+ border: '1px solid #111',
186
+ '-moz-border-radius': '4px',
187
+ clear: 'left',
188
+ 'float': 'left'
189
+ }).end()
190
190
  .find('a').css({
191
- color: '#aaa',
192
- textDecoration: 'none',
193
- 'float': 'left',
194
- width: '100%',
195
- outline: '0'
196
- }).end()
191
+ color: '#aaa',
192
+ textDecoration: 'none',
193
+ 'float': 'left',
194
+ width: '100%',
195
+ outline: '0'
196
+ }).end()
197
197
  .find('img').css({
198
- 'float': 'left',
199
- border: '1px solid #333',
200
- margin: '0 2px'
201
- }).end()
198
+ 'float': 'left',
199
+ border: '1px solid #333',
200
+ margin: '0 2px'
201
+ }).end()
202
202
  .find('.themeName').css({
203
- 'float': 'left',
204
- margin: '3px 0'
205
- }).end();
203
+ 'float': 'left',
204
+ margin: '3px 0'
205
+ }).end();
206
206
 
207
207
  $(this).append(button);
208
208
  $('body').append(switcherpane);
@@ -317,7 +317,7 @@
317
317
  // Generate a reusable function that will serve to render a template against data
318
318
  function buildTmplFn(markup) {
319
319
  return new Function("jQuery", "$item",
320
- // Use the variable __ to hold a string array while building the compiled template. (See https://github.com/jquery/jquery-tmpl/issues#issue/10).
320
+ // Use the variable __ to hold a string array while building the compiled template. (See https://github.com/jquery/jquery-tmpl/issues#issue/10).
321
321
  "var $=jQuery,call,__=[],$data=$item.data;" +
322
322
 
323
323
  // Introduce the data as local variables using with(){}
@@ -359,15 +359,15 @@
359
359
  "__.push('";
360
360
  }) +
361
361
  "');}return __;"
362
- );
362
+ );
363
363
  }
364
364
 
365
365
  function updateWrapped(options, wrapped) {
366
366
  // Build the wrapped content.
367
367
  options._wrap = build(options, true,
368
- // Suport imperative scenario in which options.wrapped can be set to a selector or an HTML string.
368
+ // Suport imperative scenario in which options.wrapped can be set to a selector or an HTML string.
369
369
  jQuery.isArray(wrapped) ? wrapped : [htmlExpr.test(wrapped) ? wrapped : jQuery(wrapped).html()]
370
- ).join("");
370
+ ).join("");
371
371
  }
372
372
 
373
373
  function unescape(args) {
@@ -1,12 +1,12 @@
1
- (function(d){function m(a,b,e,c){c={data:c||c===0||c===!1?c:b?b.data:{},_wrap:b?b._wrap:null,tmpl:null,parent:b||null,nodes:[],calls:B,nest:C,wrap:D,html:E,update:F};a&&d.extend(c,a,{nodes:[],parent:b});if(e)c.tmpl=e,c._ctnt=c._ctnt||c.tmpl(d,c),c.key=++n,(t.length?o:j)[n]=c;return c}function p(a,b,e){var c,e=e?d.map(e,function(b){return typeof b==="string"?a.key?b.replace(/(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g,"$1 "+l+'="'+a.key+'" $2'):b:p(b,a,b._ctnt)}):a;if(b)return e;e=e.join("");e.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,
1
+ (function(d){function n(a,b,e,c){c={data:c||c===0||c===!1?c:b?b.data:{},_wrap:b?b._wrap:null,tmpl:null,parent:b||null,nodes:[],calls:B,nest:C,wrap:D,html:E,update:F};a&&d.extend(c,a,{nodes:[],parent:b});if(e)c.tmpl=e,c._ctnt=c._ctnt||c.tmpl(d,c),c.key=++o,(t.length?p:j)[o]=c;return c}function q(a,b,e){var c,e=e?d.map(e,function(b){return typeof b==="string"?a.key?b.replace(/(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g,"$1 "+m+'="'+a.key+'" $2'):b:q(b,a,b._ctnt)}):a;if(b)return e;e=e.join("");e.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,
2
2
  function(b,a,e,i){c=d(e).get();v(c);a&&(c=u(a).concat(c));i&&(c=c.concat(u(i)))});return c?c:u(e)}function u(a){var b=document.createElement("div");b.innerHTML=a;return d.makeArray(b.childNodes)}function w(a){return new Function("jQuery","$item","var $=jQuery,call,__=[],$data=$item.data;with($data){__.push('"+d.trim(a).replace(/([\\'])/g,"\\$1").replace(/[\r\t\n]/g," ").replace(/\$\{([^\}]*)\}/g,"{{= $1}}").replace(/\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,
3
- function(a,e,c,g,h,f,i){a=d.tmpl.tag[c];if(!a)throw"Unknown template tag: "+c;c=a._default||[];f&&!/\w$/.test(h)&&(h+=f,f="");h?(h=q(h),i=i?","+q(i)+")":f?")":"",i=f?h.indexOf(".")>-1?h+q(f):"("+h+").call($item"+i:h,f=f?i:"(typeof("+h+")==='function'?("+h+").call($item):("+h+"))"):f=i=c.$1||"null";g=q(g);return"');"+a[e?"close":"open"].split("$notnull_1").join(h?"typeof("+h+")!=='undefined' && ("+h+")!=null":"true").split("$1a").join(f).split("$1").join(i).split("$2").join(g||c.$2||"")+"__.push('"})+
4
- "');}return __;")}function x(a,b){a._wrap=p(a,!0,d.isArray(b)?b:[y.test(b)?b:d(b).html()]).join("")}function q(a){return a?a.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null}function v(a){function b(a){function b(a){var G;a+=e;G=h[a]=h[a]||m(f,j[f.parent.key+e]||f.parent),f=G}var c,g=a,f,i;if(i=a.getAttribute(l)){for(;g.parentNode&&(g=g.parentNode).nodeType===1&&!(c=g.getAttribute(l)););if(c!==i){g=g.parentNode?g.nodeType===11?0:g.getAttribute(l)||0:0;if(!(f=j[i]))f=o[i],f=m(f,j[g]||o[g]),f.key=++n,
5
- j[n]=f;k&&b(i)}a.removeAttribute(l)}else if(k&&(f=d.data(a,"tmplItem")))b(f.key),j[f.key]=f,g=(g=d.data(a.parentNode,"tmplItem"))?g.key:0;if(f){for(c=f;c&&c.key!=g;)c.nodes.push(a),c=c.parent;delete f._ctnt;delete f._wrap;d.data(a,"tmplItem",f)}}var e="_"+k,c,g,h={},f,i,r;f=0;for(i=a.length;f<i;f++)if((c=a[f]).nodeType===1){g=c.getElementsByTagName("*");for(r=g.length-1;r>=0;r--)b(g[r]);b(c)}}function B(a,b,d,c){if(!a)return t.pop();t.push({_:a,tmpl:b,item:this,data:d,options:c})}function C(a,b,e){return d.tmpl(d.template(a),
6
- b,e,this)}function D(a,b){var e=a.options||{};e.wrapped=b;return d.tmpl(d.template(a.tmpl),a.data,e,a.item)}function E(a,b){var e=this._wrap;return d.map(d(d.isArray(e)?e.join(""):e).filter(a||"*"),function(a){if(b)a=a.innerText||a.textContent;else{var d;if(!(d=a.outerHTML))d=document.createElement("div"),d.appendChild(a.cloneNode(!0)),d=d.innerHTML;a=d}return a})}function F(){var a=this.nodes;d.tmpl(null,null,null,this).insertBefore(a[0]);d(a).remove()}var z=d.fn.domManip,l="_tmplitem",y=/^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,
7
- j={},o={},s,A={key:0,data:{}},n=0,k=0,t=[];d.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){d.fn[a]=function(e){var c=[],e=d(e),g,h,f;g=this.length===1&&this[0].parentNode;s=j||{};if(g&&g.nodeType===11&&g.childNodes.length===1&&e.length===1)e[b](this[0]),c=this;else{h=0;for(f=e.length;h<f;h++)k=h,g=(h>0?this.clone(!0):this).get(),d(e[h])[b](g),c=c.concat(g);k=0;c=this.pushStack(c,a,e.selector)}e=s;s=null;d.tmpl.complete(e);
8
- return c}});d.fn.extend({tmpl:function(a,b,e){return d.tmpl(this[0],a,b,e)},tmplItem:function(){return d.tmplItem(this[0])},template:function(a){return d.template(a,this[0])},domManip:function(a,b,e){if(a[0]&&d.isArray(a[0])){for(var c=d.makeArray(arguments),g=a[0],h=g.length,f=0,i;f<h&&!(i=d.data(g[f++],"tmplItem")););i&&k&&(c[2]=function(a){d.tmpl.afterManip(this,a,e)});z.apply(this,c)}else z.apply(this,arguments);k=0;s||d.tmpl.complete(j);return this}});d.extend({tmpl:function(a,b,e,c){var g=!c;
9
- if(g)c=A,a=d.template[a]||d.template(null,a),o={};else if(!a)return a=c.tmpl,j[c.key]=c,c.nodes=[],c.wrapped&&x(c,c.wrapped),d(p(c,null,c.tmpl(d,c)));if(!a)return[];typeof b==="function"&&(b=b.call(c||{}));e&&e.wrapped&&x(e,e.wrapped);b=d.isArray(b)?d.map(b,function(b){return b?m(e,c,a,b):null}):[m(e,c,a,b)];return g?d(p(c,null,b)):b},tmplItem:function(a){var b;for(a instanceof d&&(a=a[0]);a&&a.nodeType===1&&!(b=d.data(a,"tmplItem"))&&(a=a.parentNode););return b||A},template:function(a,b){if(b)return typeof b===
10
- "string"?b=w(b):b instanceof d&&(b=b[0]||{}),b.nodeType&&(b=d.data(b,"tmpl")||d.data(b,"tmpl",w(b.innerHTML))),typeof a==="string"?d.template[a]=b:b;return a?typeof a!=="string"?d.template(null,a):d.template[a]||d.template(null,y.test(a)?a:d(a)):null},encode:function(a){return(""+a).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;")}});d.extend(d.tmpl,{tag:{tmpl:{_default:{$2:"null"},open:"if($notnull_1){__=__.concat($item.nest($1,$2));}"},wrap:{_default:{$2:"null"},
3
+ function(a,e,c,g,h,f,i){a=d.tmpl.tag[c];if(!a)throw"Unknown template tag: "+c;c=a._default||[];f&&!/\w$/.test(h)&&(h+=f,f="");h?(h=r(h),i=i?","+r(i)+")":f?")":"",i=f?h.indexOf(".")>-1?h+r(f):"("+h+").call($item"+i:h,f=f?i:"(typeof("+h+")==='function'?("+h+").call($item):("+h+"))"):f=i=c.$1||"null";g=r(g);return"');"+a[e?"close":"open"].split("$notnull_1").join(h?"typeof("+h+")!=='undefined' && ("+h+")!=null":"true").split("$1a").join(f).split("$1").join(i).split("$2").join(g||c.$2||"")+"__.push('"})+
4
+ "');}return __;")}function x(a,b){a._wrap=q(a,!0,d.isArray(b)?b:[y.test(b)?b:d(b).html()]).join("")}function r(a){return a?a.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null}function v(a){function b(a){function b(a){var G;a+=e;G=h[a]=h[a]||n(f,j[f.parent.key+e]||f.parent),f=G}var c,g=a,f,i;if(i=a.getAttribute(m)){for(;g.parentNode&&(g=g.parentNode).nodeType===1&&!(c=g.getAttribute(m)););if(c!==i){g=g.parentNode?g.nodeType===11?0:g.getAttribute(m)||0:0;if(!(f=j[i]))f=p[i],f=n(f,j[g]||p[g]),f.key=++o,
5
+ j[o]=f;k&&b(i)}a.removeAttribute(m)}else if(k&&(f=d.data(a,"tmplItem")))b(f.key),j[f.key]=f,g=(g=d.data(a.parentNode,"tmplItem"))?g.key:0;if(f){for(c=f;c&&c.key!=g;)c.nodes.push(a),c=c.parent;delete f._ctnt;delete f._wrap;d.data(a,"tmplItem",f)}}var e="_"+k,c,g,h={},f,i,l;f=0;for(i=a.length;f<i;f++)if((c=a[f]).nodeType===1){g=c.getElementsByTagName("*");for(l=g.length-1;l>=0;l--)b(g[l]);b(c)}}function B(a,b,d,c){if(!a)return t.pop();t.push({_:a,tmpl:b,item:this,data:d,options:c})}function C(a,b,e){return d.tmpl(d.template(a),
6
+ b,e,this)}function D(a,b){var e=a.options||{};e.wrapped=b;return d.tmpl(d.template(a.tmpl),a.data,e,a.item)}function E(a,b){var e=this._wrap;return d.map(d(d.isArray(e)?e.join(""):e).filter(a||"*"),function(a){if(b)a=a.innerText||a.textContent;else{var d;if(!(d=a.outerHTML))d=document.createElement("div"),d.appendChild(a.cloneNode(!0)),d=d.innerHTML;a=d}return a})}function F(){var a=this.nodes;d.tmpl(null,null,null,this).insertBefore(a[0]);d(a).remove()}var z=d.fn.domManip,m="_tmplitem",y=/^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,
7
+ j={},p={},s,A={key:0,data:{}},o=0,k=0,t=[];d.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){d.fn[a]=function(e){var c=[],e=d(e),g,h,f;g=this.length===1&&this[0].parentNode;s=j||{};if(g&&g.nodeType===11&&g.childNodes.length===1&&e.length===1)e[b](this[0]),c=this;else{h=0;for(f=e.length;h<f;h++)k=h,g=(h>0?this.clone(!0):this).get(),d(e[h])[b](g),c=c.concat(g);k=0;c=this.pushStack(c,a,e.selector)}e=s;s=null;d.tmpl.complete(e);
8
+ return c}});d.fn.extend({tmpl:function(a,b,e){return d.tmpl(this[0],a,b,e)},tmplItem:function(){return d.tmplItem(this[0])},template:function(a){return d.template(a,this[0])},domManip:function(a,b,e,c){if(a[0]&&d.isArray(a[0])){for(var g=d.makeArray(arguments),h=a[0],f=h.length,i=0,l;i<f&&!(l=d.data(h[i++],"tmplItem")););l&&k&&(g[2]=function(a){d.tmpl.afterManip(this,a,e)});z.apply(this,g)}else z.apply(this,arguments);k=0;s||d.tmpl.complete(j);return this}});d.extend({tmpl:function(a,b,e,c){var g=
9
+ !c;if(g)c=A,a=d.template[a]||d.template(null,a),p={};else if(!a)return a=c.tmpl,j[c.key]=c,c.nodes=[],c.wrapped&&x(c,c.wrapped),d(q(c,null,c.tmpl(d,c)));if(!a)return[];typeof b==="function"&&(b=b.call(c||{}));e&&e.wrapped&&x(e,e.wrapped);b=d.isArray(b)?d.map(b,function(b){return b?n(e,c,a,b):null}):[n(e,c,a,b)];return g?d(q(c,null,b)):b},tmplItem:function(a){var b;for(a instanceof d&&(a=a[0]);a&&a.nodeType===1&&!(b=d.data(a,"tmplItem"))&&(a=a.parentNode););return b||A},template:function(a,b){return b?
10
+ (typeof b==="string"?b=w(b):b instanceof d&&(b=b[0]||{}),b.nodeType&&(b=d.data(b,"tmpl")||d.data(b,"tmpl",w(b.innerHTML))),typeof a==="string"?d.template[a]=b:b):a?typeof a!=="string"?d.template(null,a):d.template[a]||d.template(null,y.test(a)?a:d(a)):null},encode:function(a){return(""+a).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;")}});d.extend(d.tmpl,{tag:{tmpl:{_default:{$2:"null"},open:"if($notnull_1){__=__.concat($item.nest($1,$2));}"},wrap:{_default:{$2:"null"},
11
11
  open:"$item.calls(__,$1,$2);__=[];",close:"call=$item.calls();__=call._.concat($item.wrap(call,__));"},each:{_default:{$2:"$index, $value"},open:"if($notnull_1){$.each($1a,function($2){with(this){",close:"}});}"},"if":{open:"if(($notnull_1) && $1a){",close:"}"},"else":{_default:{$1:"true"},open:"}else if(($notnull_1) && $1a){"},html:{open:"if($notnull_1){__.push($1a);}"},"=":{_default:{$1:"$data"},open:"if($notnull_1){__.push($.encode($1a));}"},"!":{open:""}},complete:function(){j={}},afterManip:function(a,
12
12
  b,e){var c=b.nodeType===11?d.makeArray(b.childNodes):b.nodeType===1?[b]:[];e.call(a,b);v(c);k++}})})(jQuery);
@@ -1,3 +1,3 @@
1
- (function(b){var i=b.tmpl.complete,h=b.fn.domManip;b.tmpl.complete=function(c){var a;i(c);for(a in c)a=c[a],a.addedTmplItems&&b.inArray(a,a.addedTmplItems)===-1&&a.addedTmplItems.push(a);for(a in c)a=c[a],a.rendered&&a.rendered(a)};b.extend({tmplCmd:function(c,a,e){function d(a,b){for(var c=[],e,f,d=b.length,g,h=0,i=a.length;h<i;){g=a[h++];for(f=0;f<d;)e=b[f++],e.data===g&&c.push(e)}return c}var g=[],f,a=b.isArray(a)?a:[a];switch(c){case "find":return d(a,e);case "replace":a.reverse()}b.each(e?d(a,
2
- e):a,function(a,d){coll=d.nodes;switch(c){case "update":d.update();break;case "remove":b(coll).remove();e&&e.splice(b.inArray(d,e),1);break;case "replace":f=f?b(coll).insertBefore(f)[0]:b(coll).appendTo(coll[0].parentNode)[0],g.unshift(d)}});return g}});b.fn.extend({domManip:function(c,a,e){var d=c[1],g=c[0],f;if(c.length>=2&&typeof d==="object"&&!d.nodeType&&!(d instanceof b))return f=b.makeArray(arguments),f[0]=[b.tmpl(b.template(g),d,c[2],c[3])],f[2]=function(a){b.tmpl.afterManip(this,a,e)},h.apply(this,
3
- f);return h.apply(this,arguments)}})})(jQuery);
1
+ (function(b){var j=b.tmpl.complete,h=b.fn.domManip;b.tmpl.complete=function(c){var a;j(c);for(a in c)a=c[a],a.addedTmplItems&&b.inArray(a,a.addedTmplItems)===-1&&a.addedTmplItems.push(a);for(a in c)a=c[a],a.rendered&&a.rendered(a)};b.extend({tmplCmd:function(c,a,d){function e(a,b){for(var c=[],d,f,g=b.length,e,h=0,j=a.length;h<j;){e=a[h++];for(f=0;f<g;)d=b[f++],d.data===e&&c.push(d)}return c}var f=[],g,a=b.isArray(a)?a:[a];switch(c){case "find":return e(a,d);case "replace":a.reverse()}b.each(d?e(a,
2
+ d):a,function(a,e){coll=e.nodes;switch(c){case "update":e.update();break;case "remove":b(coll).remove();d&&d.splice(b.inArray(e,d),1);break;case "replace":g=g?b(coll).insertBefore(g)[0]:b(coll).appendTo(coll[0].parentNode)[0],f.unshift(e)}});return f}});b.fn.extend({domManip:function(c,a,d,e){var f=c[1],g=c[0],i;return c.length>=2&&typeof f==="object"&&!f.nodeType&&!(f instanceof b)?(i=b.makeArray(arguments),i[0]=[b.tmpl(b.template(g),f,c[2],c[3])],i[2]=function(a){b.tmpl.afterManip(this,a,d)},h.apply(this,
3
+ i)):h.apply(this,arguments)}})})(jQuery);
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * jQuery Plugin: Tokenizing Autocomplete Text Entry
3
- * Version 1.4.2
3
+ * Version 1.6.0
4
4
  *
5
5
  * Copyright (c) 2009 James Smith (http://loopj.com)
6
6
  * Licensed jointly under the GPL and MIT licenses,
@@ -10,29 +10,48 @@
10
10
 
11
11
  (function ($) {
12
12
  // Default settings
13
- var DEFAULT_SETTINGS = {
13
+ var DEFAULT_SETTINGS = {
14
+ // Search settings
15
+ method: "GET",
16
+ queryParam: "q",
17
+ searchDelay: 300,
18
+ minChars: 1,
19
+ propertyToSearch: "name",
20
+ jsonContainer: null,
21
+ contentType: "json",
22
+
23
+ // Prepopulation settings
24
+ prePopulate: null,
25
+ processPrePopulate: false,
26
+
27
+ // Display settings
14
28
  hintText: "Type in a search term",
15
29
  noResultsText: "No results",
16
30
  searchingText: "Searching...",
17
31
  deleteText: "&times;",
18
- searchDelay: 300,
19
- minChars: 1,
32
+ animateDropdown: true,
33
+ theme: null,
34
+ resultsFormatter: function(item){ return "<li>" + item[this.propertyToSearch]+ "</li>" },
35
+ tokenFormatter: function(item) { return "<li><p>" + item[this.propertyToSearch] + "</p></li>" },
36
+
37
+ // Tokenization settings
20
38
  tokenLimit: null,
21
- jsonContainer: null,
22
- method: "GET",
23
- contentType: "json",
24
- queryParam: "q",
25
39
  tokenDelimiter: ",",
26
40
  preventDuplicates: false,
27
- prePopulate: null,
28
- animateDropdown: true,
41
+ tokenValue: "id",
42
+
43
+ // Callbacks
29
44
  onResult: null,
30
45
  onAdd: null,
31
- onDelete: null
32
- };
46
+ onDelete: null,
47
+ onReady: null,
48
+
49
+ // Other settings
50
+ idPrefix: "token-input-"
51
+ };
33
52
 
34
53
  // Default classes to use when theming
35
- var DEFAULT_CLASSES = {
54
+ var DEFAULT_CLASSES = {
36
55
  tokenList: "token-input-list",
37
56
  token: "token-input-token",
38
57
  tokenDelete: "token-input-delete-token",
@@ -43,17 +62,17 @@
43
62
  dropdownItem2: "token-input-dropdown-item2",
44
63
  selectedDropdownItem: "token-input-selected-dropdown-item",
45
64
  inputToken: "token-input-input-token"
46
- };
65
+ };
47
66
 
48
67
  // Input box position "enum"
49
- var POSITION = {
68
+ var POSITION = {
50
69
  BEFORE: 0,
51
70
  AFTER: 1,
52
71
  END: 2
53
- };
72
+ };
54
73
 
55
74
  // Keys "enum"
56
- var KEY = {
75
+ var KEY = {
57
76
  BACKSPACE: 8,
58
77
  TAB: 9,
59
78
  ENTER: 13,
@@ -69,55 +88,83 @@
69
88
  DOWN: 40,
70
89
  NUMPAD_ENTER: 108,
71
90
  COMMA: 188
72
- };
91
+ };
73
92
 
93
+ // Additional public (exposed) methods
94
+ var methods = {
95
+ init: function(url_or_data_or_function, options) {
96
+ var settings = $.extend({}, DEFAULT_SETTINGS, options || {});
74
97
 
75
- // Expose the .tokenInput function to jQuery as a plugin
76
- $.fn.tokenInput = function (url_or_data, options) {
77
- var settings = $.extend({}, DEFAULT_SETTINGS, options || {});
78
-
79
- return this.each(function () {
80
- new $.TokenList(this, url_or_data, settings);
81
- });
82
- };
98
+ return this.each(function () {
99
+ $(this).data("tokenInputObject", new $.TokenList(this, url_or_data_or_function, settings));
100
+ });
101
+ },
102
+ clear: function() {
103
+ this.data("tokenInputObject").clear();
104
+ return this;
105
+ },
106
+ add: function(item) {
107
+ this.data("tokenInputObject").add(item);
108
+ return this;
109
+ },
110
+ remove: function(item) {
111
+ this.data("tokenInputObject").remove(item);
112
+ return this;
113
+ },
114
+ get: function() {
115
+ return this.data("tokenInputObject").getTokens();
116
+ }
117
+ }
83
118
 
119
+ // Expose the .tokenInput function to jQuery as a plugin
120
+ $.fn.tokenInput = function (method) {
121
+ // Method calling and initialization logic
122
+ if(methods[method]) {
123
+ return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
124
+ } else {
125
+ return methods.init.apply(this, arguments);
126
+ }
127
+ };
84
128
 
85
129
  // TokenList class for each input
86
- $.TokenList = function (input, url_or_data, settings) {
130
+ $.TokenList = function (input, url_or_data, settings) {
87
131
  //
88
132
  // Initialization
89
133
  //
90
134
 
91
135
  // Configure the data source
92
- if (typeof(url_or_data) === "string") {
93
- // Set the url to query against
94
- settings.url = url_or_data;
95
-
96
- // Make a smart guess about cross-domain if it wasn't explicitly specified
97
- if (settings.crossDomain === undefined) {
98
- if (settings.url.indexOf("://") === -1) {
99
- settings.crossDomain = false;
100
- } else {
101
- settings.crossDomain = (location.href.split(/\/+/g)[1] !== settings.url.split(/\/+/g)[1]);
136
+ if($.type(url_or_data) === "string" || $.type(url_or_data) === "function") {
137
+ // Set the url to query against
138
+ settings.url = url_or_data;
139
+
140
+ // If the URL is a function, evaluate it here to do our initalization work
141
+ var url = computeURL();
142
+
143
+ // Make a smart guess about cross-domain if it wasn't explicitly specified
144
+ if(settings.crossDomain === undefined) {
145
+ if(url.indexOf("://") === -1) {
146
+ settings.crossDomain = false;
147
+ } else {
148
+ settings.crossDomain = (location.href.split(/\/+/g)[1] !== url.split(/\/+/g)[1]);
149
+ }
102
150
  }
103
- }
104
- } else if (typeof(url_or_data) === "object") {
105
- // Set the local data to search through
106
- settings.local_data = url_or_data;
151
+ } else if(typeof(url_or_data) === "object") {
152
+ // Set the local data to search through
153
+ settings.local_data = url_or_data;
107
154
  }
108
155
 
109
156
  // Build class names
110
- if (settings.classes) {
111
- // Use custom class names
112
- settings.classes = $.extend({}, DEFAULT_CLASSES, settings.classes);
113
- } else if (settings.theme) {
114
- // Use theme-suffixed default class names
115
- settings.classes = {};
116
- $.each(DEFAULT_CLASSES, function(key, value) {
117
- settings.classes[key] = value + "-" + settings.theme;
118
- });
157
+ if(settings.classes) {
158
+ // Use custom class names
159
+ settings.classes = $.extend({}, DEFAULT_CLASSES, settings.classes);
160
+ } else if(settings.theme) {
161
+ // Use theme-suffixed default class names
162
+ settings.classes = {};
163
+ $.each(DEFAULT_CLASSES, function(key, value) {
164
+ settings.classes[key] = value + "-" + settings.theme;
165
+ });
119
166
  } else {
120
- settings.classes = DEFAULT_CLASSES;
167
+ settings.classes = DEFAULT_CLASSES;
121
168
  }
122
169
 
123
170
 
@@ -136,117 +183,117 @@
136
183
 
137
184
  // Create a new text input an attach keyup events
138
185
  var input_box = $("<input type=\"text\" autocomplete=\"off\">")
139
- .css({
140
- outline: "none"
141
- })
142
- .focus(function () {
143
- if (settings.tokenLimit === null || settings.tokenLimit !== token_count) {
144
- show_dropdown_hint();
145
- }
146
- })
147
- .blur(function () {
148
- hide_dropdown();
149
- })
150
- .bind("keyup keydown blur update", resize_input)
151
- .keydown(function (event) {
152
- var previous_token;
153
- var next_token;
154
-
155
- switch (event.keyCode) {
156
- case KEY.LEFT:
157
- case KEY.RIGHT:
158
- case KEY.UP:
159
- case KEY.DOWN:
160
- if (!$(this).val()) {
161
- previous_token = input_token.prev();
162
- next_token = input_token.next();
163
-
164
- if ((previous_token.length && previous_token.get(0) === selected_token) || (next_token.length && next_token.get(0) === selected_token)) {
165
- // Check if there is a previous/next token and it is selected
166
- if (event.keyCode === KEY.LEFT || event.keyCode === KEY.UP) {
167
- deselect_token($(selected_token), POSITION.BEFORE);
168
- } else {
169
- deselect_token($(selected_token), POSITION.AFTER);
170
- }
171
- } else if ((event.keyCode === KEY.LEFT || event.keyCode === KEY.UP) && previous_token.length) {
172
- // We are moving left, select the previous token if it exists
173
- select_token($(previous_token.get(0)));
174
- } else if ((event.keyCode === KEY.RIGHT || event.keyCode === KEY.DOWN) && next_token.length) {
175
- // We are moving right, select the next token if it exists
176
- select_token($(next_token.get(0)));
177
- }
178
- } else {
179
- var dropdown_item = null;
180
-
181
- if (event.keyCode === KEY.DOWN || event.keyCode === KEY.RIGHT) {
182
- dropdown_item = $(selected_dropdown_item).next();
183
- } else {
184
- dropdown_item = $(selected_dropdown_item).prev();
185
- }
186
-
187
- if (dropdown_item.length) {
188
- select_dropdown_item(dropdown_item);
189
- }
190
- return false;
191
- }
192
- break;
193
-
194
- case KEY.BACKSPACE:
195
- previous_token = input_token.prev();
196
-
197
- if (!$(this).val().length) {
198
- if (selected_token) {
199
- delete_token($(selected_token));
200
- } else if (previous_token.length) {
201
- select_token($(previous_token.get(0)));
186
+ .css({
187
+ outline: "none"
188
+ })
189
+ .attr("id", settings.idPrefix + input.id)
190
+ .focus(function () {
191
+ if (settings.tokenLimit === null || settings.tokenLimit !== token_count) {
192
+ show_dropdown_hint();
202
193
  }
203
-
204
- return false;
205
- } else if ($(this).val().length === 1) {
194
+ })
195
+ .blur(function () {
206
196
  hide_dropdown();
207
- } else {
208
- // set a timeout just long enough to let this function finish.
209
- setTimeout(function() {
210
- do_search();
211
- }, 5);
212
- }
213
- break;
214
-
215
- case KEY.TAB:
216
- case KEY.ENTER:
217
- case KEY.NUMPAD_ENTER:
218
- case KEY.COMMA:
219
- if (selected_dropdown_item) {
220
- add_token($(selected_dropdown_item));
221
- return false;
222
- }
223
- break;
224
-
225
- case KEY.ESCAPE:
226
- hide_dropdown();
227
- return true;
228
-
229
- default:
230
- if (String.fromCharCode(event.which)) {
231
- // set a timeout just long enough to let this function finish.
232
- setTimeout(function() {
233
- do_search();
234
- }, 5);
235
- }
236
- break;
237
- }
238
- });
197
+ $(this).val("");
198
+ })
199
+ .bind("keyup keydown blur update", resize_input)
200
+ .keydown(function (event) {
201
+ var previous_token;
202
+ var next_token;
203
+
204
+ switch(event.keyCode) {
205
+ case KEY.LEFT:
206
+ case KEY.RIGHT:
207
+ case KEY.UP:
208
+ case KEY.DOWN:
209
+ if(!$(this).val()) {
210
+ previous_token = input_token.prev();
211
+ next_token = input_token.next();
212
+
213
+ if((previous_token.length && previous_token.get(0) === selected_token) || (next_token.length && next_token.get(0) === selected_token)) {
214
+ // Check if there is a previous/next token and it is selected
215
+ if(event.keyCode === KEY.LEFT || event.keyCode === KEY.UP) {
216
+ deselect_token($(selected_token), POSITION.BEFORE);
217
+ } else {
218
+ deselect_token($(selected_token), POSITION.AFTER);
219
+ }
220
+ } else if((event.keyCode === KEY.LEFT || event.keyCode === KEY.UP) && previous_token.length) {
221
+ // We are moving left, select the previous token if it exists
222
+ select_token($(previous_token.get(0)));
223
+ } else if((event.keyCode === KEY.RIGHT || event.keyCode === KEY.DOWN) && next_token.length) {
224
+ // We are moving right, select the next token if it exists
225
+ select_token($(next_token.get(0)));
226
+ }
227
+ } else {
228
+ var dropdown_item = null;
229
+
230
+ if(event.keyCode === KEY.DOWN || event.keyCode === KEY.RIGHT) {
231
+ dropdown_item = $(selected_dropdown_item).next();
232
+ } else {
233
+ dropdown_item = $(selected_dropdown_item).prev();
234
+ }
235
+
236
+ if(dropdown_item.length) {
237
+ select_dropdown_item(dropdown_item);
238
+ }
239
+ return false;
240
+ }
241
+ break;
242
+
243
+ case KEY.BACKSPACE:
244
+ previous_token = input_token.prev();
245
+
246
+ if(!$(this).val().length) {
247
+ if(selected_token) {
248
+ delete_token($(selected_token));
249
+ hidden_input.change();
250
+ } else if(previous_token.length) {
251
+ select_token($(previous_token.get(0)));
252
+ }
253
+
254
+ return false;
255
+ } else if($(this).val().length === 1) {
256
+ hide_dropdown();
257
+ } else {
258
+ // set a timeout just long enough to let this function finish.
259
+ setTimeout(function(){do_search();}, 5);
260
+ }
261
+ break;
262
+
263
+ case KEY.TAB:
264
+ case KEY.ENTER:
265
+ case KEY.NUMPAD_ENTER:
266
+ case KEY.COMMA:
267
+ if(selected_dropdown_item) {
268
+ add_token($(selected_dropdown_item).data("tokeninput"));
269
+ hidden_input.change();
270
+ return false;
271
+ }
272
+ break;
273
+
274
+ case KEY.ESCAPE:
275
+ hide_dropdown();
276
+ return true;
277
+
278
+ default:
279
+ if(String.fromCharCode(event.which)) {
280
+ // set a timeout just long enough to let this function finish.
281
+ setTimeout(function(){do_search();}, 5);
282
+ }
283
+ break;
284
+ }
285
+ });
239
286
 
240
287
  // Keep a reference to the original input box
241
288
  var hidden_input = $(input)
242
- .hide()
243
- .val("")
244
- .focus(function () {
245
- input_box.focus();
246
- })
247
- .blur(function () {
248
- input_box.blur();
249
- });
289
+ .hide()
290
+ .val("")
291
+ .focus(function () {
292
+ input_box.focus();
293
+ })
294
+ .blur(function () {
295
+ input_box.blur();
296
+ });
250
297
 
251
298
  // Keep a reference to the selected token and dropdown item
252
299
  var selected_token = null;
@@ -255,480 +302,556 @@
255
302
 
256
303
  // The list to store the token items in
257
304
  var token_list = $("<ul />")
258
- .addClass(settings.classes.tokenList)
259
- .click(function (event) {
260
- var li = $(event.target).closest("li");
261
- if (li && li.get(0) && $.data(li.get(0), "tokeninput")) {
262
- toggle_select_token(li);
263
- } else {
264
- // Deselect selected token
265
- if (selected_token) {
266
- deselect_token($(selected_token), POSITION.END);
267
- }
305
+ .addClass(settings.classes.tokenList)
306
+ .click(function (event) {
307
+ var li = $(event.target).closest("li");
308
+ if(li && li.get(0) && $.data(li.get(0), "tokeninput")) {
309
+ toggle_select_token(li);
310
+ } else {
311
+ // Deselect selected token
312
+ if(selected_token) {
313
+ deselect_token($(selected_token), POSITION.END);
314
+ }
268
315
 
269
- // Focus input box
270
- input_box.focus();
271
- }
272
- })
273
- .mouseover(function (event) {
274
- var li = $(event.target).closest("li");
275
- if (li && selected_token !== this) {
276
- li.addClass(settings.classes.highlightedToken);
277
- }
278
- })
279
- .mouseout(function (event) {
280
- var li = $(event.target).closest("li");
281
- if (li && selected_token !== this) {
282
- li.removeClass(settings.classes.highlightedToken);
283
- }
284
- })
285
- .insertBefore(hidden_input);
316
+ // Focus input box
317
+ input_box.focus();
318
+ }
319
+ })
320
+ .mouseover(function (event) {
321
+ var li = $(event.target).closest("li");
322
+ if(li && selected_token !== this) {
323
+ li.addClass(settings.classes.highlightedToken);
324
+ }
325
+ })
326
+ .mouseout(function (event) {
327
+ var li = $(event.target).closest("li");
328
+ if(li && selected_token !== this) {
329
+ li.removeClass(settings.classes.highlightedToken);
330
+ }
331
+ })
332
+ .insertBefore(hidden_input);
286
333
 
287
334
  // The token holding the input box
288
335
  var input_token = $("<li />")
289
- .addClass(settings.classes.inputToken)
290
- .appendTo(token_list)
291
- .append(input_box);
336
+ .addClass(settings.classes.inputToken)
337
+ .appendTo(token_list)
338
+ .append(input_box);
292
339
 
293
340
  // The list to store the dropdown items in
294
341
  var dropdown = $("<div>")
295
- .addClass(settings.classes.dropdown)
296
- .appendTo("body")
297
- .hide();
342
+ .addClass(settings.classes.dropdown)
343
+ .appendTo("body")
344
+ .hide();
298
345
 
299
346
  // Magic element to help us resize the text input
300
347
  var input_resizer = $("<tester/>")
301
- .insertAfter(input_box)
302
- .css({
303
- position: "absolute",
304
- top: -9999,
305
- left: -9999,
306
- width: "auto",
307
- fontSize: input_box.css("fontSize"),
308
- fontFamily: input_box.css("fontFamily"),
309
- fontWeight: input_box.css("fontWeight"),
310
- letterSpacing: input_box.css("letterSpacing"),
311
- whiteSpace: "nowrap"
312
- });
348
+ .insertAfter(input_box)
349
+ .css({
350
+ position: "absolute",
351
+ top: -9999,
352
+ left: -9999,
353
+ width: "auto",
354
+ fontSize: input_box.css("fontSize"),
355
+ fontFamily: input_box.css("fontFamily"),
356
+ fontWeight: input_box.css("fontWeight"),
357
+ letterSpacing: input_box.css("letterSpacing"),
358
+ whiteSpace: "nowrap"
359
+ });
313
360
 
314
361
  // Pre-populate list if items exist
315
362
  hidden_input.val("");
316
- li_data = settings.prePopulate || hidden_input.data("pre");
317
- if (li_data && li_data.length) {
318
- $.each(li_data, function (index, value) {
319
- insert_token(value.id, value.name);
320
- });
363
+ var li_data = settings.prePopulate || hidden_input.data("pre");
364
+ if(settings.processPrePopulate && $.isFunction(settings.onResult)) {
365
+ li_data = settings.onResult.call(hidden_input, li_data);
366
+ }
367
+ if(li_data && li_data.length) {
368
+ $.each(li_data, function (index, value) {
369
+ insert_token(value);
370
+ checkTokenLimit();
371
+ });
372
+ }
373
+
374
+ // Initialization is done
375
+ if($.isFunction(settings.onReady)) {
376
+ settings.onReady.call();
377
+ }
378
+
379
+ //
380
+ // Public functions
381
+ //
382
+
383
+ this.clear = function() {
384
+ token_list.children("li").each(function() {
385
+ if ($(this).children("input").length === 0) {
386
+ delete_token($(this));
387
+ }
388
+ });
321
389
  }
322
390
 
391
+ this.add = function(item) {
392
+ add_token(item);
393
+ }
394
+
395
+ this.remove = function(item) {
396
+ token_list.children("li").each(function() {
397
+ if ($(this).children("input").length === 0) {
398
+ var currToken = $(this).data("tokeninput");
399
+ var match = true;
400
+ for (var prop in item) {
401
+ if (item[prop] !== currToken[prop]) {
402
+ match = false;
403
+ break;
404
+ }
405
+ }
406
+ if (match) {
407
+ delete_token($(this));
408
+ }
409
+ }
410
+ });
411
+ }
412
+
413
+ this.getTokens = function() {
414
+ return saved_tokens;
415
+ }
323
416
 
324
417
  //
325
418
  // Private functions
326
419
  //
327
420
 
421
+ function checkTokenLimit() {
422
+ if(settings.tokenLimit !== null && token_count >= settings.tokenLimit) {
423
+ input_box.hide();
424
+ hide_dropdown();
425
+ return;
426
+ }
427
+ }
428
+
328
429
  function resize_input() {
329
- if (input_val === (input_val = input_box.val())) {
330
- return;
331
- }
430
+ if(input_val === (input_val = input_box.val())) {return;}
332
431
 
333
- // Enter new content into resizer and resize input accordingly
334
- var escaped = input_val.replace(/&/g, '&amp;').replace(/\s/g, ' ').replace(/</g, '&lt;').replace(/>/g, '&gt;');
335
- input_resizer.html(escaped);
336
- input_box.width(input_resizer.width() + 30);
432
+ // Enter new content into resizer and resize input accordingly
433
+ var escaped = input_val.replace(/&/g, '&amp;').replace(/\s/g,' ').replace(/</g, '&lt;').replace(/>/g, '&gt;');
434
+ input_resizer.html(escaped);
435
+ input_box.width(input_resizer.width() + 30);
337
436
  }
338
437
 
339
438
  function is_printable_character(keycode) {
340
- return ((keycode >= 48 && keycode <= 90) || // 0-1a-z
341
- (keycode >= 96 && keycode <= 111) || // numpad 0-9 + - / * .
342
- (keycode >= 186 && keycode <= 192) || // ; = , - . / ^
343
- (keycode >= 219 && keycode <= 222)); // ( \ ) '
439
+ return ((keycode >= 48 && keycode <= 90) || // 0-1a-z
440
+ (keycode >= 96 && keycode <= 111) || // numpad 0-9 + - / * .
441
+ (keycode >= 186 && keycode <= 192) || // ; = , - . / ^
442
+ (keycode >= 219 && keycode <= 222)); // ( \ ) '
344
443
  }
345
444
 
346
445
  // Inner function to a token to the list
347
- function insert_token(id, value) {
348
- var this_token = $("<li><p>" + value + "</p></li>")
349
- .addClass(settings.classes.token)
350
- .insertBefore(input_token);
446
+ function insert_token(item) {
447
+ var this_token = settings.tokenFormatter(item);
448
+ this_token = $(this_token)
449
+ .addClass(settings.classes.token)
450
+ .insertBefore(input_token);
451
+
452
+ // The 'delete token' button
453
+ $("<span>" + settings.deleteText + "</span>")
454
+ .addClass(settings.classes.tokenDelete)
455
+ .appendTo(this_token)
456
+ .click(function () {
457
+ delete_token($(this).parent());
458
+ hidden_input.change();
459
+ return false;
460
+ });
351
461
 
352
- // The 'delete token' button
353
- $("<span>" + settings.deleteText + "</span>")
354
- .addClass(settings.classes.tokenDelete)
355
- .appendTo(this_token)
356
- .click(function () {
357
- delete_token($(this).parent());
358
- return false;
359
- });
462
+ // Store data on the token
463
+ var token_data = {"id": item.id};
464
+ token_data[settings.propertyToSearch] = item[settings.propertyToSearch];
465
+ $.data(this_token.get(0), "tokeninput", item);
360
466
 
361
- // Store data on the token
362
- var token_data = {"id": id, "name": value};
363
- $.data(this_token.get(0), "tokeninput", token_data);
467
+ // Save this token for duplicate checking
468
+ saved_tokens = saved_tokens.slice(0,selected_token_index).concat([token_data]).concat(saved_tokens.slice(selected_token_index));
469
+ selected_token_index++;
364
470
 
365
- // Save this token for duplicate checking
366
- saved_tokens = saved_tokens.slice(0, selected_token_index).concat([token_data]).concat(saved_tokens.slice(selected_token_index));
367
- selected_token_index++;
471
+ // Update the hidden input
472
+ update_hidden_input(saved_tokens, hidden_input);
368
473
 
369
- // Update the hidden input
370
- var token_ids = $.map(saved_tokens, function (el) {
371
- return el.id;
372
- });
373
- hidden_input.val(token_ids.join(settings.tokenDelimiter));
474
+ token_count += 1;
374
475
 
375
- token_count += 1;
476
+ // Check the token limit
477
+ if(settings.tokenLimit !== null && token_count >= settings.tokenLimit) {
478
+ input_box.hide();
479
+ hide_dropdown();
480
+ }
376
481
 
377
- return this_token;
482
+ return this_token;
378
483
  }
379
484
 
380
485
  // Add a token to the token list based on user input
381
- function add_token(item) {
382
- var li_data = $.data(item.get(0), "tokeninput");
383
- var callback = settings.onAdd;
384
-
385
- // See if the token already exists and select it if we don't want duplicates
386
- if (token_count > 0 && settings.preventDuplicates) {
387
- var found_existing_token = null;
388
- token_list.children().each(function () {
389
- var existing_token = $(this);
390
- var existing_data = $.data(existing_token.get(0), "tokeninput");
391
- if (existing_data && existing_data.id === li_data.id) {
392
- found_existing_token = existing_token;
393
- return false;
394
- }
395
- });
486
+ function add_token (item) {
487
+ var callback = settings.onAdd;
488
+
489
+ // See if the token already exists and select it if we don't want duplicates
490
+ if(token_count > 0 && settings.preventDuplicates) {
491
+ var found_existing_token = null;
492
+ token_list.children().each(function () {
493
+ var existing_token = $(this);
494
+ var existing_data = $.data(existing_token.get(0), "tokeninput");
495
+ if(existing_data && existing_data.id === item.id) {
496
+ found_existing_token = existing_token;
497
+ return false;
498
+ }
499
+ });
396
500
 
397
- if (found_existing_token) {
398
- select_token(found_existing_token);
399
- input_token.insertAfter(found_existing_token);
400
- input_box.focus();
401
- return;
501
+ if(found_existing_token) {
502
+ select_token(found_existing_token);
503
+ input_token.insertAfter(found_existing_token);
504
+ input_box.focus();
505
+ return;
506
+ }
402
507
  }
403
- }
404
508
 
405
- // Insert the new tokens
406
- insert_token(li_data.id, li_data.name);
407
-
408
- // Check the token limit
409
- if (settings.tokenLimit !== null && token_count >= settings.tokenLimit) {
410
- input_box.hide();
411
- hide_dropdown();
412
- return;
413
- } else {
414
- input_box.focus();
415
- }
509
+ // Insert the new tokens
510
+ if(settings.tokenLimit == null || token_count < settings.tokenLimit) {
511
+ insert_token(item);
512
+ checkTokenLimit();
513
+ }
416
514
 
417
- // Clear input box
418
- input_box.val("");
515
+ // Clear input box
516
+ input_box.val("");
419
517
 
420
- // Don't show the help dropdown, they've got the idea
421
- hide_dropdown();
518
+ // Don't show the help dropdown, they've got the idea
519
+ hide_dropdown();
422
520
 
423
- // Execute the onAdd callback if defined
424
- if ($.isFunction(callback)) {
425
- callback(li_data);
426
- }
521
+ // Execute the onAdd callback if defined
522
+ if($.isFunction(callback)) {
523
+ callback.call(hidden_input,item);
524
+ }
427
525
  }
428
526
 
429
527
  // Select a token in the token list
430
- function select_token(token) {
431
- token.addClass(settings.classes.selectedToken);
432
- selected_token = token.get(0);
528
+ function select_token (token) {
529
+ token.addClass(settings.classes.selectedToken);
530
+ selected_token = token.get(0);
433
531
 
434
- // Hide input box
435
- input_box.val("");
532
+ // Hide input box
533
+ input_box.val("");
436
534
 
437
- // Hide dropdown if it is visible (eg if we clicked to select token)
438
- hide_dropdown();
535
+ // Hide dropdown if it is visible (eg if we clicked to select token)
536
+ hide_dropdown();
439
537
  }
440
538
 
441
539
  // Deselect a token in the token list
442
- function deselect_token(token, position) {
443
- token.removeClass(settings.classes.selectedToken);
444
- selected_token = null;
445
-
446
- if (position === POSITION.BEFORE) {
447
- input_token.insertBefore(token);
448
- selected_token_index--;
449
- } else if (position === POSITION.AFTER) {
450
- input_token.insertAfter(token);
451
- selected_token_index++;
452
- } else {
453
- input_token.appendTo(token_list);
454
- selected_token_index = token_count;
455
- }
540
+ function deselect_token (token, position) {
541
+ token.removeClass(settings.classes.selectedToken);
542
+ selected_token = null;
543
+
544
+ if(position === POSITION.BEFORE) {
545
+ input_token.insertBefore(token);
546
+ selected_token_index--;
547
+ } else if(position === POSITION.AFTER) {
548
+ input_token.insertAfter(token);
549
+ selected_token_index++;
550
+ } else {
551
+ input_token.appendTo(token_list);
552
+ selected_token_index = token_count;
553
+ }
456
554
 
457
- // Show the input box and give it focus again
458
- input_box.focus();
555
+ // Show the input box and give it focus again
556
+ input_box.focus();
459
557
  }
460
558
 
461
559
  // Toggle selection of a token in the token list
462
560
  function toggle_select_token(token) {
463
- var previous_selected_token = selected_token;
561
+ var previous_selected_token = selected_token;
464
562
 
465
- if (selected_token) {
466
- deselect_token($(selected_token), POSITION.END);
467
- }
563
+ if(selected_token) {
564
+ deselect_token($(selected_token), POSITION.END);
565
+ }
468
566
 
469
- if (previous_selected_token === token.get(0)) {
470
- deselect_token(token, POSITION.END);
471
- } else {
472
- select_token(token);
473
- }
567
+ if(previous_selected_token === token.get(0)) {
568
+ deselect_token(token, POSITION.END);
569
+ } else {
570
+ select_token(token);
571
+ }
474
572
  }
475
573
 
476
574
  // Delete a token from the token list
477
- function delete_token(token) {
478
- // Remove the id from the saved list
479
- var token_data = $.data(token.get(0), "tokeninput");
480
- var callback = settings.onDelete;
575
+ function delete_token (token) {
576
+ // Remove the id from the saved list
577
+ var token_data = $.data(token.get(0), "tokeninput");
578
+ var callback = settings.onDelete;
481
579
 
482
- var index = token.prevAll().length;
483
- if (index > selected_token_index) index--;
580
+ var index = token.prevAll().length;
581
+ if(index > selected_token_index) index--;
484
582
 
485
- // Delete the token
486
- token.remove();
487
- selected_token = null;
583
+ // Delete the token
584
+ token.remove();
585
+ selected_token = null;
488
586
 
489
- // Show the input box and give it focus again
490
- input_box.focus();
587
+ // Show the input box and give it focus again
588
+ input_box.focus();
491
589
 
492
- // Remove this token from the saved list
493
- saved_tokens = saved_tokens.slice(0, index).concat(saved_tokens.slice(index + 1));
494
- if (index < selected_token_index) selected_token_index--;
590
+ // Remove this token from the saved list
591
+ saved_tokens = saved_tokens.slice(0,index).concat(saved_tokens.slice(index+1));
592
+ if(index < selected_token_index) selected_token_index--;
495
593
 
496
- // Update the hidden input
497
- var token_ids = $.map(saved_tokens, function (el) {
498
- return el.id;
499
- });
500
- hidden_input.val(token_ids.join(settings.tokenDelimiter));
594
+ // Update the hidden input
595
+ update_hidden_input(saved_tokens, hidden_input);
501
596
 
502
- token_count -= 1;
597
+ token_count -= 1;
503
598
 
504
- if (settings.tokenLimit !== null) {
505
- input_box
599
+ if(settings.tokenLimit !== null) {
600
+ input_box
506
601
  .show()
507
602
  .val("")
508
603
  .focus();
509
- }
604
+ }
605
+
606
+ // Execute the onDelete callback if defined
607
+ if($.isFunction(callback)) {
608
+ callback.call(hidden_input,token_data);
609
+ }
610
+ }
611
+
612
+ // Update the hidden input box value
613
+ function update_hidden_input(saved_tokens, hidden_input) {
614
+ var token_values = $.map(saved_tokens, function (el) {
615
+ return el[settings.tokenValue];
616
+ });
617
+ hidden_input.val(token_values.join(settings.tokenDelimiter));
510
618
 
511
- // Execute the onDelete callback if defined
512
- if ($.isFunction(callback)) {
513
- callback(token_data);
514
- }
515
619
  }
516
620
 
517
621
  // Hide and clear the results dropdown
518
- function hide_dropdown() {
519
- dropdown.hide().empty();
520
- selected_dropdown_item = null;
622
+ function hide_dropdown () {
623
+ dropdown.hide().empty();
624
+ selected_dropdown_item = null;
521
625
  }
522
626
 
523
627
  function show_dropdown() {
524
- dropdown
525
- .css({
526
- position: "absolute",
527
- top: $(token_list).offset().top + $(token_list).outerHeight(),
528
- left: $(token_list).offset().left,
529
- zindex: 999
530
- })
531
- .show();
628
+ dropdown
629
+ .css({
630
+ position: "absolute",
631
+ top: $(token_list).offset().top + $(token_list).outerHeight(),
632
+ left: $(token_list).offset().left,
633
+ zindex: 999
634
+ })
635
+ .show();
532
636
  }
533
637
 
534
- function show_dropdown_searching() {
535
- if (settings.searchingText) {
536
- dropdown.html("<p>" + settings.searchingText + "</p>");
537
- show_dropdown();
538
- }
638
+ function show_dropdown_searching () {
639
+ if(settings.searchingText) {
640
+ dropdown.html("<p>"+settings.searchingText+"</p>");
641
+ show_dropdown();
642
+ }
539
643
  }
540
644
 
541
- function show_dropdown_hint() {
542
- if (settings.hintText) {
543
- dropdown.html("<p>" + settings.hintText + "</p>");
544
- show_dropdown();
545
- }
645
+ function show_dropdown_hint () {
646
+ if(settings.hintText) {
647
+ dropdown.html("<p>"+settings.hintText+"</p>");
648
+ show_dropdown();
649
+ }
546
650
  }
547
651
 
548
652
  // Highlight the query part of the search term
549
653
  function highlight_term(value, term) {
550
- return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
654
+ return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
655
+ }
656
+
657
+ function find_value_and_highlight_term(template, value, term) {
658
+ return template.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + value + ")(?![^<>]*>)(?![^&;]+;)", "g"), highlight_term(value, term));
551
659
  }
552
660
 
553
661
  // Populate the results dropdown with some results
554
- function populate_dropdown(query, results) {
555
- if (results && results.length) {
556
- dropdown.empty();
557
- var dropdown_ul = $("<ul>")
662
+ function populate_dropdown (query, results) {
663
+ if(results && results.length) {
664
+ dropdown.empty();
665
+ var dropdown_ul = $("<ul>")
558
666
  .appendTo(dropdown)
559
667
  .mouseover(function (event) {
560
- select_dropdown_item($(event.target).closest("li"));
561
- })
668
+ select_dropdown_item($(event.target).closest("li"));
669
+ })
562
670
  .mousedown(function (event) {
563
- add_token($(event.target).closest("li"));
564
- return false;
565
- })
671
+ add_token($(event.target).closest("li").data("tokeninput"));
672
+ hidden_input.change();
673
+ return false;
674
+ })
566
675
  .hide();
567
676
 
568
- $.each(results, function(index, value) {
569
- var this_li = $("<li>" + highlight_term(value.name, query) + "</li>")
570
- .appendTo(dropdown_ul);
677
+ $.each(results, function(index, value) {
678
+ var this_li = settings.resultsFormatter(value);
571
679
 
572
- if (index % 2) {
573
- this_li.addClass(settings.classes.dropdownItem);
574
- } else {
575
- this_li.addClass(settings.classes.dropdownItem2);
576
- }
680
+ this_li = find_value_and_highlight_term(this_li ,value[settings.propertyToSearch], query);
577
681
 
578
- if (index === 0) {
579
- select_dropdown_item(this_li);
580
- }
682
+ this_li = $(this_li).appendTo(dropdown_ul);
581
683
 
582
- $.data(this_li.get(0), "tokeninput", {"id": value.id, "name": value.name});
583
- });
684
+ if(index % 2) {
685
+ this_li.addClass(settings.classes.dropdownItem);
686
+ } else {
687
+ this_li.addClass(settings.classes.dropdownItem2);
688
+ }
584
689
 
585
- show_dropdown();
690
+ if(index === 0) {
691
+ select_dropdown_item(this_li);
692
+ }
693
+
694
+ $.data(this_li.get(0), "tokeninput", value);
695
+ });
586
696
 
587
- if (settings.animateDropdown) {
588
- dropdown_ul.slideDown("fast");
697
+ show_dropdown();
698
+
699
+ if(settings.animateDropdown) {
700
+ dropdown_ul.slideDown("fast");
701
+ } else {
702
+ dropdown_ul.show();
703
+ }
589
704
  } else {
590
- dropdown_ul.show();
591
- }
592
- } else {
593
- if (settings.noResultsText) {
594
- dropdown.html("<p>" + settings.noResultsText + "</p>");
595
- show_dropdown();
705
+ if(settings.noResultsText) {
706
+ dropdown.html("<p>"+settings.noResultsText+"</p>");
707
+ show_dropdown();
708
+ }
596
709
  }
597
- }
598
710
  }
599
711
 
600
712
  // Highlight an item in the results dropdown
601
- function select_dropdown_item(item) {
602
- if (item) {
603
- if (selected_dropdown_item) {
604
- deselect_dropdown_item($(selected_dropdown_item));
605
- }
713
+ function select_dropdown_item (item) {
714
+ if(item) {
715
+ if(selected_dropdown_item) {
716
+ deselect_dropdown_item($(selected_dropdown_item));
717
+ }
606
718
 
607
- item.addClass(settings.classes.selectedDropdownItem);
608
- selected_dropdown_item = item.get(0);
609
- }
719
+ item.addClass(settings.classes.selectedDropdownItem);
720
+ selected_dropdown_item = item.get(0);
721
+ }
610
722
  }
611
723
 
612
724
  // Remove highlighting from an item in the results dropdown
613
- function deselect_dropdown_item(item) {
614
- item.removeClass(settings.classes.selectedDropdownItem);
615
- selected_dropdown_item = null;
725
+ function deselect_dropdown_item (item) {
726
+ item.removeClass(settings.classes.selectedDropdownItem);
727
+ selected_dropdown_item = null;
616
728
  }
617
729
 
618
730
  // Do a search and show the "searching" dropdown if the input is longer
619
731
  // than settings.minChars
620
732
  function do_search() {
621
- var query = input_box.val().toLowerCase();
733
+ var query = input_box.val().toLowerCase();
622
734
 
623
- if (query && query.length) {
624
- if (selected_token) {
625
- deselect_token($(selected_token), POSITION.AFTER);
626
- }
735
+ if(query && query.length) {
736
+ if(selected_token) {
737
+ deselect_token($(selected_token), POSITION.AFTER);
738
+ }
627
739
 
628
- if (query.length >= settings.minChars) {
629
- show_dropdown_searching();
630
- clearTimeout(timeout);
740
+ if(query.length >= settings.minChars) {
741
+ show_dropdown_searching();
742
+ clearTimeout(timeout);
631
743
 
632
- timeout = setTimeout(function() {
633
- run_search(query);
634
- }, settings.searchDelay);
635
- } else {
636
- hide_dropdown();
744
+ timeout = setTimeout(function(){
745
+ run_search(query);
746
+ }, settings.searchDelay);
747
+ } else {
748
+ hide_dropdown();
749
+ }
637
750
  }
638
- }
639
751
  }
640
752
 
641
753
  // Do the actual search
642
754
  function run_search(query) {
643
- var cached_results = cache.get(query);
644
- if (cached_results) {
645
- populate_dropdown(query, cached_results);
646
- } else {
647
- // Are we doing an ajax search or local data search?
648
- if (settings.url) {
649
- // Extract exisiting get params
650
- var ajax_params = {};
651
- ajax_params.data = {};
652
- if (settings.url.indexOf("?") > -1) {
653
- var parts = settings.url.split("?");
654
- ajax_params.url = parts[0];
655
-
656
- var param_array = parts[1].split("&");
657
- $.each(param_array, function (index, value) {
658
- var kv = value.split("=");
659
- ajax_params.data[kv[0]] = kv[1];
660
- });
661
- } else {
662
- ajax_params.url = settings.url;
663
- }
664
-
665
- // Prepare the request
666
- ajax_params.data[settings.queryParam] = query;
667
- ajax_params.type = settings.method;
668
- ajax_params.dataType = settings.contentType;
669
- if (settings.crossDomain) {
670
- ajax_params.dataType = "jsonp";
671
- }
672
-
673
- // Attach the success callback
674
- ajax_params.success = function(results) {
675
- if ($.isFunction(settings.onResult)) {
676
- results = settings.onResult.call(this, results);
755
+ var cache_key = query + computeURL();
756
+ var cached_results = cache.get(cache_key);
757
+ if(cached_results) {
758
+ populate_dropdown(query, cached_results);
759
+ } else {
760
+ // Are we doing an ajax search or local data search?
761
+ if(settings.url) {
762
+ var url = computeURL();
763
+ // Extract exisiting get params
764
+ var ajax_params = {};
765
+ ajax_params.data = {};
766
+ if(url.indexOf("?") > -1) {
767
+ var parts = url.split("?");
768
+ ajax_params.url = parts[0];
769
+
770
+ var param_array = parts[1].split("&");
771
+ $.each(param_array, function (index, value) {
772
+ var kv = value.split("=");
773
+ ajax_params.data[kv[0]] = kv[1];
774
+ });
775
+ } else {
776
+ ajax_params.url = url;
777
+ }
778
+
779
+ // Prepare the request
780
+ ajax_params.data[settings.queryParam] = query;
781
+ ajax_params.type = settings.method;
782
+ ajax_params.dataType = settings.contentType;
783
+ if(settings.crossDomain) {
784
+ ajax_params.dataType = "jsonp";
785
+ }
786
+
787
+ // Attach the success callback
788
+ ajax_params.success = function(results) {
789
+ if($.isFunction(settings.onResult)) {
790
+ results = settings.onResult.call(hidden_input, results);
791
+ }
792
+ cache.add(cache_key, settings.jsonContainer ? results[settings.jsonContainer] : results);
793
+
794
+ // only populate the dropdown if the results are associated with the active search query
795
+ if(input_box.val().toLowerCase() === query) {
796
+ populate_dropdown(query, settings.jsonContainer ? results[settings.jsonContainer] : results);
797
+ }
798
+ };
799
+
800
+ // Make the request
801
+ $.ajax(ajax_params);
802
+ } else if(settings.local_data) {
803
+ // Do the search through local data
804
+ var results = $.grep(settings.local_data, function (row) {
805
+ return row[settings.propertyToSearch].toLowerCase().indexOf(query.toLowerCase()) > -1;
806
+ });
807
+
808
+ if($.isFunction(settings.onResult)) {
809
+ results = settings.onResult.call(hidden_input, results);
810
+ }
811
+ cache.add(cache_key, results);
812
+ populate_dropdown(query, results);
677
813
  }
678
- cache.add(query, settings.jsonContainer ? results[settings.jsonContainer] : results);
814
+ }
815
+ }
679
816
 
680
- // only populate the dropdown if the results are associated with the active search query
681
- if (input_box.val().toLowerCase() === query) {
682
- populate_dropdown(query, settings.jsonContainer ? results[settings.jsonContainer] : results);
683
- }
684
- };
685
-
686
- // Make the request
687
- $.ajax(ajax_params);
688
- } else if (settings.local_data) {
689
- // Do the search through local data
690
- var results = $.grep(settings.local_data, function (row) {
691
- return row.name.toLowerCase().indexOf(query.toLowerCase()) > -1;
692
- });
693
-
694
- if ($.isFunction(settings.onResult)) {
695
- results = settings.onResult.call(this, results);
696
- }
697
- cache.add(query, results);
698
- populate_dropdown(query, results);
817
+ // compute the dynamic URL
818
+ function computeURL() {
819
+ var url = settings.url;
820
+ if(typeof settings.url == 'function') {
821
+ url = settings.url.call();
699
822
  }
700
- }
823
+ return url;
701
824
  }
702
- };
825
+ };
703
826
 
704
827
  // Really basic cache for the results
705
- $.TokenList.Cache = function (options) {
828
+ $.TokenList.Cache = function (options) {
706
829
  var settings = $.extend({
707
- max_size: 500
830
+ max_size: 500
708
831
  }, options);
709
832
 
710
833
  var data = {};
711
834
  var size = 0;
712
835
 
713
836
  var flush = function () {
714
- data = {};
715
- size = 0;
837
+ data = {};
838
+ size = 0;
716
839
  };
717
840
 
718
841
  this.add = function (query, results) {
719
- if (size > settings.max_size) {
720
- flush();
721
- }
842
+ if(size > settings.max_size) {
843
+ flush();
844
+ }
722
845
 
723
- if (!data[query]) {
724
- size += 1;
725
- }
846
+ if(!data[query]) {
847
+ size += 1;
848
+ }
726
849
 
727
- data[query] = results;
850
+ data[query] = results;
728
851
  };
729
852
 
730
853
  this.get = function (query) {
731
- return data[query];
854
+ return data[query];
732
855
  };
733
- };
856
+ };
734
857
  }(jQuery));