fanforce-plugin-factory 0.41.0 → 1.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. data/.gitignore +1 -0
  2. data/.ruby-version +1 -0
  3. data/.yardopts +5 -0
  4. data/.yardopts.rb +1 -0
  5. data/Gemfile +9 -0
  6. data/README.md +40 -75
  7. data/Rakefile +61 -4
  8. data/fanforce-plugin-factory.gemspec +21 -21
  9. data/lib/fanforce/plugin_factory.rb +16 -58
  10. data/lib/fanforce/plugin_factory/Rakefile +51 -0
  11. data/lib/fanforce/plugin_factory/Routes.rb +33 -0
  12. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/_bootstrap.scss +2 -0
  13. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/_common.scss +1 -0
  14. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/_directives.scss +7 -0
  15. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/_font-awesome.scss +1 -0
  16. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/_ui-select.scss +3 -0
  17. data/lib/fanforce/plugin_factory/{assets/lib/common → asset_framework/plugin_factory/bootstrap}/_bootstrap-overrides.scss +2 -0
  18. data/lib/fanforce/plugin_factory/{assets/lib/vendors/bootstrap/css → asset_framework/plugin_factory/bootstrap}/bootstrap.css +2 -2
  19. data/lib/fanforce/plugin_factory/{assets/lib/vendors/bootstrap/js → asset_framework/plugin_factory/bootstrap}/bootstrap.js +0 -0
  20. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/bootstrap/bootstrap.min.css +7 -0
  21. data/lib/fanforce/plugin_factory/{assets/lib/vendors/bootstrap/js → asset_framework/plugin_factory/bootstrap}/bootstrap.min.js +0 -0
  22. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/bootstrap/glyphicons-halflings-regular.eot +0 -0
  23. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/bootstrap/glyphicons-halflings-regular.svg +229 -0
  24. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/bootstrap/glyphicons-halflings-regular.ttf +0 -0
  25. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/bootstrap/glyphicons-halflings-regular.woff +0 -0
  26. data/lib/fanforce/plugin_factory/{assets/lib → asset_framework/plugin_factory}/common/_mixins.scss +2 -1
  27. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/directives.coffee +1 -0
  28. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/directives/error/_error.scss +6 -0
  29. data/lib/fanforce/plugin_factory/{assets/lib/common/module-error → asset_framework/plugin_factory/directives/error}/arrow-left.png +0 -0
  30. data/lib/fanforce/plugin_factory/{assets/lib/common/module-error → asset_framework/plugin_factory/directives/error}/icon-error.png +0 -0
  31. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/directives/initiative-footer/_initiative-footer.coffee +16 -0
  32. data/lib/fanforce/plugin_factory/{assets/lib/common/_module-add-initiative-footer.scss → asset_framework/plugin_factory/directives/initiative-footer/_initiative-footer.scss} +4 -1
  33. data/lib/fanforce/plugin_factory/{assets/lib/common/_module-initiative-searcher.scss → asset_framework/plugin_factory/directives/initiative-searcher/_initiative-searcher.scss} +14 -13
  34. data/lib/fanforce/plugin_factory/{assets/lib/common/module-initiative-searcher → asset_framework/plugin_factory/directives/initiative-searcher}/icon-search.png +0 -0
  35. data/lib/fanforce/plugin_factory/{assets/lib/common/module-initiative-searcher → asset_framework/plugin_factory/directives/initiative-searcher}/spinner.gif +0 -0
  36. data/lib/fanforce/plugin_factory/{assets/lib/common/module-initiative-searcher → asset_framework/plugin_factory/directives/initiative-searcher}/sprite-arrows.png +0 -0
  37. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/directives/loading/_loading.coffee +4 -0
  38. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/directives/loading/_loading.scss +4 -0
  39. data/lib/fanforce/plugin_factory/{assets/js/add_source_popup.js → asset_framework/plugin_factory/directives/saving-to-server/_saving-to-server.coffee} +0 -0
  40. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/directives/saving-to-server/_saving-to-server.scss +6 -0
  41. data/lib/fanforce/plugin_factory/{assets/lib/common/module-saving-initiative → asset_framework/plugin_factory/directives/saving-to-server}/spinner.gif +0 -0
  42. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/directives/start-arrow/_start-arrow.coffee +8 -0
  43. data/lib/fanforce/plugin_factory/{assets/lib/common/_module-start-here.scss → asset_framework/plugin_factory/directives/start-arrow/_start-arrow.scss} +5 -4
  44. data/lib/fanforce/plugin_factory/{assets/lib/common/module-start-here → asset_framework/plugin_factory/directives/start-arrow}/arrow.png +0 -0
  45. data/lib/fanforce/plugin_factory/{assets/lib/common/_module-video-thumbnail.scss → asset_framework/plugin_factory/directives/video-thumbnail/_video-thumbnail.scss} +4 -4
  46. data/lib/fanforce/plugin_factory/{assets/lib/common/module-video-thumbnail → asset_framework/plugin_factory/directives/video-thumbnail}/icon-play.png +0 -0
  47. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/font-awesome.coffee +1 -0
  48. data/lib/fanforce/plugin_factory/{assets/lib/vendors/font-awesome/font → asset_framework/plugin_factory/font-awesome}/FontAwesome.otf +0 -0
  49. data/lib/fanforce/plugin_factory/{assets/lib/vendors/font-awesome/css → asset_framework/plugin_factory/font-awesome}/font-awesome.css +2 -2
  50. data/lib/fanforce/plugin_factory/{assets/lib/vendors/font-awesome/css → asset_framework/plugin_factory/font-awesome}/font-awesome.min.css +0 -0
  51. data/lib/fanforce/plugin_factory/{assets/lib/vendors/font-awesome/font → asset_framework/plugin_factory/font-awesome}/fontawesome-webfont.eot +0 -0
  52. data/lib/fanforce/plugin_factory/{assets/lib/vendors/font-awesome/font → asset_framework/plugin_factory/font-awesome}/fontawesome-webfont.svg +0 -0
  53. data/lib/fanforce/plugin_factory/{assets/lib/vendors/font-awesome/font → asset_framework/plugin_factory/font-awesome}/fontawesome-webfont.ttf +0 -0
  54. data/lib/fanforce/plugin_factory/{assets/lib/vendors/font-awesome/font → asset_framework/plugin_factory/font-awesome}/fontawesome-webfont.woff +0 -0
  55. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/lib.coffee +1 -0
  56. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/lib/ng-focus-blur.js +68 -0
  57. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/lib/ng-visible.js +7 -0
  58. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/ui-select.coffee +1 -0
  59. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/ui-select/select.css +171 -0
  60. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/ui-select/select.js +1281 -0
  61. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/ui-select/select_override.scss +1 -0
  62. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/ui-select/selectize.default.css +443 -0
  63. data/lib/fanforce/plugin_factory/cli.rb +5 -0
  64. data/lib/fanforce/plugin_factory/cli/lib/bitbucket.rb +77 -0
  65. data/lib/fanforce/plugin_factory/cli/lib/bundler.rb +21 -0
  66. data/lib/fanforce/plugin_factory/cli/lib/env.rb +96 -0
  67. data/lib/fanforce/plugin_factory/cli/lib/git.rb +59 -0
  68. data/lib/fanforce/plugin_factory/cli/lib/heroku.rb +94 -0
  69. data/lib/fanforce/plugin_factory/cli/lib/iron.rb +71 -0
  70. data/lib/fanforce/plugin_factory/cli/lib/pow.rb +46 -0
  71. data/lib/fanforce/plugin_factory/cli/lib/scaffolding.rb +74 -0
  72. data/lib/fanforce/plugin_factory/cli/lib/scaffolding_file.rb +510 -0
  73. data/lib/fanforce/plugin_factory/cli/lib/uranium.rb +77 -0
  74. data/lib/fanforce/plugin_factory/cli/lib/utils.rb +57 -0
  75. data/lib/fanforce/plugin_factory/cli/scripts/config.rb +9 -0
  76. data/lib/fanforce/plugin_factory/cli/scripts/create.rb +64 -0
  77. data/lib/fanforce/plugin_factory/cli/scripts/destroy.rb +61 -0
  78. data/lib/fanforce/plugin_factory/cli/scripts/diff.rb +156 -0
  79. data/lib/fanforce/plugin_factory/cli/scripts/push.rb +88 -0
  80. data/lib/fanforce/plugin_factory/cli/scripts/restart.rb +41 -0
  81. data/lib/fanforce/plugin_factory/cli/scripts/setup.rb +70 -0
  82. data/lib/fanforce/plugin_factory/cli/scripts/update.rb +132 -0
  83. data/lib/fanforce/plugin_factory/cli_directory_of_plugins.rb +51 -0
  84. data/lib/fanforce/plugin_factory/cli_single_plugin.rb +52 -0
  85. data/lib/fanforce/plugin_factory/controllers/base_controller.rb +15 -0
  86. data/lib/fanforce/plugin_factory/core_config.rb +94 -0
  87. data/lib/fanforce/plugin_factory/directive_views/initiative-footer.haml +8 -0
  88. data/lib/fanforce/plugin_factory/load.rb +7 -0
  89. data/lib/fanforce/plugin_factory/load_iron_worker.rb +2 -0
  90. data/lib/fanforce/plugin_factory/load_sprockets.rb +2 -0
  91. data/lib/fanforce/plugin_factory/plugin.rb +60 -0
  92. data/lib/fanforce/plugin_factory/scaffolding/._.gitignore.registry +1 -0
  93. data/lib/fanforce/plugin_factory/scaffolding/._Gemfile.registry +3 -0
  94. data/lib/fanforce/plugin_factory/scaffolding/._Rakefile.registry +3 -0
  95. data/lib/fanforce/plugin_factory/scaffolding/._config.json.registry +2 -0
  96. data/lib/fanforce/plugin_factory/scaffolding/._config.ru.registry +4 -0
  97. data/lib/fanforce/plugin_factory/scaffolding/._favicon.ico.registry +1 -0
  98. data/lib/fanforce/plugin_factory/scaffolding/._robots.txt.registry +3 -0
  99. data/lib/fanforce/plugin_factory/scaffolding/.gitignore +27 -0
  100. data/lib/fanforce/plugin_factory/scaffolding/Gemfile +9 -0
  101. data/lib/fanforce/plugin_factory/scaffolding/Rakefile +7 -0
  102. data/lib/fanforce/plugin_factory/scaffolding/Routes.rb +67 -0
  103. data/lib/fanforce/plugin_factory/scaffolding/assets/css/._fembedded.scss.registry +4 -0
  104. data/lib/fanforce/plugin_factory/scaffolding/assets/css/._promotional.scss.registry +4 -0
  105. data/lib/fanforce/plugin_factory/scaffolding/assets/css/._visitor.scss.registry +4 -0
  106. data/lib/fanforce/plugin_factory/scaffolding/assets/css/fembedded.scss +24 -0
  107. data/lib/fanforce/plugin_factory/scaffolding/assets/css/promotional.scss +33 -0
  108. data/lib/fanforce/plugin_factory/scaffolding/assets/css/visitor.scss +61 -0
  109. data/lib/fanforce/plugin_factory/scaffolding/assets/img/._icon-16.png.registry +1 -0
  110. data/lib/fanforce/plugin_factory/scaffolding/assets/img/._icon-32.png.registry +1 -0
  111. data/lib/fanforce/plugin_factory/scaffolding/assets/img/._icon-42.png.registry +1 -0
  112. data/lib/fanforce/plugin_factory/scaffolding/assets/img/._marketplace.png.registry +1 -0
  113. data/lib/fanforce/plugin_factory/{assets → scaffolding/assets}/img/icon-16.png +0 -0
  114. data/lib/fanforce/plugin_factory/{assets → scaffolding/assets}/img/icon-32.png +0 -0
  115. data/lib/fanforce/plugin_factory/{assets → scaffolding/assets}/img/icon-42.png +0 -0
  116. data/lib/fanforce/plugin_factory/scaffolding/assets/img/marketplace.png +0 -0
  117. data/lib/fanforce/plugin_factory/scaffolding/assets/img/promotional/._fanforce_bg.png.registry +1 -0
  118. data/lib/fanforce/plugin_factory/scaffolding/assets/img/promotional/._icon-42.png.registry +1 -0
  119. data/lib/fanforce/plugin_factory/scaffolding/assets/img/promotional/._icon-plus.png.registry +1 -0
  120. data/lib/fanforce/plugin_factory/{assets/lib → scaffolding/assets/img}/promotional/fanforce_bg.png +0 -0
  121. data/lib/fanforce/plugin_factory/{assets/lib → scaffolding/assets/img}/promotional/icon-42.png +0 -0
  122. data/lib/fanforce/plugin_factory/scaffolding/assets/img/promotional/icon-plus.png +0 -0
  123. data/lib/fanforce/plugin_factory/scaffolding/assets/js/._fembedded-app.coffee.registry +5 -0
  124. data/lib/fanforce/plugin_factory/scaffolding/assets/js/._fembedded.js.registry +3 -0
  125. data/lib/fanforce/plugin_factory/scaffolding/assets/js/._promotional.js.registry +3 -0
  126. data/lib/fanforce/plugin_factory/scaffolding/assets/js/fembedded-app.coffee +11 -0
  127. data/lib/fanforce/plugin_factory/scaffolding/assets/js/fembedded.js +12 -0
  128. data/lib/fanforce/plugin_factory/scaffolding/assets/js/lib/._cookie.coffee.registry +3 -0
  129. data/lib/fanforce/plugin_factory/scaffolding/assets/js/lib/._filters.coffee.registry +3 -0
  130. data/lib/fanforce/plugin_factory/scaffolding/assets/js/lib/._utils.coffee.registry +3 -0
  131. data/lib/fanforce/plugin_factory/scaffolding/assets/js/lib/cookie.coffee +24 -0
  132. data/lib/fanforce/plugin_factory/scaffolding/assets/js/lib/filters.coffee +9 -0
  133. data/lib/fanforce/plugin_factory/scaffolding/assets/js/lib/utils.coffee +40 -0
  134. data/lib/fanforce/plugin_factory/scaffolding/assets/js/promotional.js +4 -0
  135. data/lib/fanforce/plugin_factory/scaffolding/config.json +24 -0
  136. data/lib/fanforce/plugin_factory/scaffolding/config.ru +8 -0
  137. data/lib/fanforce/plugin_factory/{public → scaffolding}/favicon.ico +0 -0
  138. data/lib/fanforce/plugin_factory/scaffolding/layouts/._fembedded.haml.registry +4 -0
  139. data/lib/fanforce/plugin_factory/scaffolding/layouts/._promotional.haml.registry +2 -0
  140. data/lib/fanforce/plugin_factory/scaffolding/layouts/._visitor.haml.registry +6 -0
  141. data/lib/fanforce/plugin_factory/scaffolding/layouts/fembedded.haml +26 -0
  142. data/lib/fanforce/plugin_factory/{layouts → scaffolding/layouts}/promotional.haml +6 -6
  143. data/lib/fanforce/plugin_factory/{layouts/engage.haml → scaffolding/layouts/visitor.haml} +10 -7
  144. data/lib/fanforce/plugin_factory/scaffolding/robots.txt +7 -0
  145. data/lib/fanforce/plugin_factory/scaffolding/views/._index.haml.registry +3 -0
  146. data/lib/fanforce/plugin_factory/{views → scaffolding/views}/index.haml +13 -7
  147. data/lib/fanforce/plugin_factory/sinatra/_load.rb +87 -0
  148. data/lib/fanforce/plugin_factory/sinatra/error_handling.rb +48 -0
  149. data/lib/fanforce/plugin_factory/sinatra/helper_routes/com_behavior.rb +19 -0
  150. data/lib/fanforce/plugin_factory/sinatra/helper_routes/com_broadcaster.rb +7 -0
  151. data/lib/fanforce/plugin_factory/sinatra/helper_routes/com_connector.rb +11 -0
  152. data/lib/fanforce/plugin_factory/sinatra/helper_routes/com_identifier.rb +3 -0
  153. data/lib/fanforce/plugin_factory/sinatra/helper_routes/com_js_widget.rb +8 -0
  154. data/lib/fanforce/plugin_factory/sinatra/helper_routes/plugin.rb +50 -0
  155. data/lib/fanforce/plugin_factory/sinatra/helpers/assets.rb +23 -0
  156. data/lib/fanforce/plugin_factory/sinatra/helpers/css_frameworks.rb +70 -0
  157. data/lib/fanforce/plugin_factory/sinatra/helpers/fanforce.rb +18 -0
  158. data/lib/fanforce/plugin_factory/{config → sinatra}/helpers/json.rb +2 -2
  159. data/lib/fanforce/plugin_factory/sinatra/helpers/ractive.rb +45 -0
  160. data/lib/fanforce/plugin_factory/sprockets/compiler.rb +5 -11
  161. data/lib/fanforce/plugin_factory/sprockets/hacks.rb +2 -2
  162. data/lib/fanforce/plugin_factory/version.rb +2 -2
  163. metadata +201 -195
  164. data/.rbenv-gemsets +0 -1
  165. data/.rbenv-version +0 -1
  166. data/lib/fanforce/plugin_factory.rake +0 -72
  167. data/lib/fanforce/plugin_factory/_init_sinatra.rb +0 -54
  168. data/lib/fanforce/plugin_factory/assets/css/add_edit_initiative.scss +0 -1
  169. data/lib/fanforce/plugin_factory/assets/css/add_source.scss +0 -1
  170. data/lib/fanforce/plugin_factory/assets/css/convert_pending_initiative.scss +0 -1
  171. data/lib/fanforce/plugin_factory/assets/css/engage.scss +0 -1
  172. data/lib/fanforce/plugin_factory/assets/css/new_message.scss +0 -1
  173. data/lib/fanforce/plugin_factory/assets/css/promotional.scss +0 -1
  174. data/lib/fanforce/plugin_factory/assets/css/source_details.scss +0 -1
  175. data/lib/fanforce/plugin_factory/assets/js/add_edit_initiative.js +0 -1
  176. data/lib/fanforce/plugin_factory/assets/js/add_source.js +0 -1
  177. data/lib/fanforce/plugin_factory/assets/js/convert_pending_initiative.js +0 -1
  178. data/lib/fanforce/plugin_factory/assets/js/engage.js +0 -1
  179. data/lib/fanforce/plugin_factory/assets/js/new_message.js +0 -1
  180. data/lib/fanforce/plugin_factory/assets/js/promotional.js +0 -2
  181. data/lib/fanforce/plugin_factory/assets/js/source_details.js +0 -0
  182. data/lib/fanforce/plugin_factory/assets/lib/common/_module-error.scss +0 -11
  183. data/lib/fanforce/plugin_factory/assets/lib/common/_module-page-loading.scss +0 -1
  184. data/lib/fanforce/plugin_factory/assets/lib/common/_module-saving-initiative.scss +0 -6
  185. data/lib/fanforce/plugin_factory/assets/lib/common/_tags.scss +0 -1
  186. data/lib/fanforce/plugin_factory/assets/lib/common/_variables.scss +0 -27
  187. data/lib/fanforce/plugin_factory/assets/lib/common/broadcaster-divider-arrow.png +0 -0
  188. data/lib/fanforce/plugin_factory/assets/lib/common/icons/dropdown-arrow.png +0 -0
  189. data/lib/fanforce/plugin_factory/assets/lib/common/icons/initiative.png +0 -0
  190. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_add_edit_initiative.scss +0 -27
  191. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_add_source.scss +0 -18
  192. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_convert_pending_initiative.scss +0 -27
  193. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_engage.scss +0 -78
  194. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_new_message.scss +0 -24
  195. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_promotional.scss +0 -27
  196. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_source_details.scss +0 -17
  197. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/add_edit_initiative.js +0 -6
  198. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/add_source.js +0 -6
  199. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/convert_pending_initiative.js +0 -6
  200. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/engage.js +0 -0
  201. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/new_message.js +0 -5
  202. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/promotional.js +0 -1
  203. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/source_details.js +0 -5
  204. data/lib/fanforce/plugin_factory/assets/lib/promotional/icon-behavior.png +0 -0
  205. data/lib/fanforce/plugin_factory/assets/lib/promotional/icon-broadcaster.png +0 -0
  206. data/lib/fanforce/plugin_factory/assets/lib/promotional/icon-data-connector.png +0 -0
  207. data/lib/fanforce/plugin_factory/assets/lib/promotional/icon-data-processor.png +0 -0
  208. data/lib/fanforce/plugin_factory/assets/lib/promotional/icon-identifier.png +0 -0
  209. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap-datepicker/datepicker.css +0 -7
  210. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap-datepicker/datepicker.js +0 -454
  211. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap-timepicker/timepicker.css +0 -82
  212. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap-timepicker/timepicker.js +0 -803
  213. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap/css/bootstrap.min.css +0 -7
  214. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap/img/glyphicons-halflings-regular.eot +0 -0
  215. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap/img/glyphicons-halflings-regular.svg +0 -0
  216. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap/img/glyphicons-halflings-regular.ttf +0 -0
  217. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap/img/glyphicons-halflings-regular.woff +0 -0
  218. data/lib/fanforce/plugin_factory/assets/lib/vendors/chosen/_chosen_override.scss +0 -6
  219. data/lib/fanforce/plugin_factory/assets/lib/vendors/chosen/chosen-sprite.png +0 -0
  220. data/lib/fanforce/plugin_factory/assets/lib/vendors/chosen/chosen-sprite@2x.png +0 -0
  221. data/lib/fanforce/plugin_factory/assets/lib/vendors/chosen/chosen.jquery.js +0 -1166
  222. data/lib/fanforce/plugin_factory/assets/lib/vendors/chosen/chosen.scss +0 -434
  223. data/lib/fanforce/plugin_factory/assets/lib/vendors/jquery/jquery-1.10.2.js +0 -9789
  224. data/lib/fanforce/plugin_factory/assets/lib/vendors/jquery/jquery.inputHint.js +0 -154
  225. data/lib/fanforce/plugin_factory/assets/lib/vendors/jquery/jquery.tmpl.debug.js +0 -484
  226. data/lib/fanforce/plugin_factory/assets/lib/vendors/knockout/knockout.custom-handlers.coffee +0 -155
  227. data/lib/fanforce/plugin_factory/assets/lib/vendors/knockout/knockout.debug.js +0 -4469
  228. data/lib/fanforce/plugin_factory/assets/lib/vendors/knockout/knockout.min.js +0 -96
  229. data/lib/fanforce/plugin_factory/assets/lib/vendors/select2/_select2_override.scss +0 -47
  230. data/lib/fanforce/plugin_factory/assets/lib/vendors/select2/select2-spinner.gif +0 -0
  231. data/lib/fanforce/plugin_factory/assets/lib/vendors/select2/select2.png +0 -0
  232. data/lib/fanforce/plugin_factory/assets/lib/vendors/select2/select2.scss +0 -617
  233. data/lib/fanforce/plugin_factory/assets/lib/vendors/select2/select2_modified.js +0 -3225
  234. data/lib/fanforce/plugin_factory/assets/lib/vendors/select2/select2x2.png +0 -0
  235. data/lib/fanforce/plugin_factory/assets/lib/vendors/underscore/underscore.debug.js +0 -999
  236. data/lib/fanforce/plugin_factory/config/_error_handling.rb +0 -27
  237. data/lib/fanforce/plugin_factory/config/core_config.rb +0 -92
  238. data/lib/fanforce/plugin_factory/config/helpers/assets.rb +0 -72
  239. data/lib/fanforce/plugin_factory/config/helpers/fanforce.rb +0 -19
  240. data/lib/fanforce/plugin_factory/layouts/add_edit_initiative.haml +0 -19
  241. data/lib/fanforce/plugin_factory/layouts/add_source.haml +0 -19
  242. data/lib/fanforce/plugin_factory/layouts/convert_pending_initiative.haml +0 -19
  243. data/lib/fanforce/plugin_factory/layouts/new_message.haml +0 -19
  244. data/lib/fanforce/plugin_factory/layouts/source_details.haml +0 -19
  245. data/lib/fanforce/plugin_factory/public/robots.txt +0 -2
  246. data/lib/fanforce/plugin_factory/routes.rb +0 -48
  247. data/lib/fanforce/plugin_factory/routes_behavior.rb +0 -34
  248. data/lib/fanforce/plugin_factory/routes_broadcaster.rb +0 -9
  249. data/lib/fanforce/plugin_factory/routes_data_connector.rb +0 -21
  250. data/lib/fanforce/plugin_factory/routes_identifier.rb +0 -3
  251. data/lib/fanforce/plugin_factory/views/add_initiative.haml +0 -1
  252. data/lib/fanforce/plugin_factory/views/add_source.haml +0 -1
  253. data/lib/fanforce/plugin_factory/views/close_popup.haml +0 -8
  254. data/lib/fanforce/plugin_factory/views/convert_pending_initiative.haml +0 -1
  255. data/lib/fanforce/plugin_factory/views/edit_initiative.haml +0 -1
  256. data/lib/fanforce/plugin_factory/views/engage.haml +0 -1
  257. data/lib/fanforce/plugin_factory/views/new_message.haml +0 -1
  258. data/lib/fanforce/plugin_factory/views/source_details.haml +0 -1
  259. data/lib/fanforce/plugin_factory/views/widget_tmpls.haml +0 -1
  260. data/lib/fanforce/plugin_factory_workers.rb +0 -2
@@ -1,3225 +0,0 @@
1
- /*
2
- Copyright 2012 Igor Vaynberg
3
-
4
- Version: 3.4.3 Timestamp: Tue Sep 17 06:47:14 PDT 2013
5
-
6
- This software is licensed under the Apache License, Version 2.0 (the "Apache License") or the GNU
7
- General Public License version 2 (the "GPL License"). You may choose either license to govern your
8
- use of this software only upon the condition that you accept all of the terms of either the Apache
9
- License or the GPL License.
10
-
11
- You may obtain a copy of the Apache License and the GPL License at:
12
-
13
- http://www.apache.org/licenses/LICENSE-2.0
14
- http://www.gnu.org/licenses/gpl-2.0.html
15
-
16
- Unless required by applicable law or agreed to in writing, software distributed under the
17
- Apache License or the GPL Licesnse is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
18
- CONDITIONS OF ANY KIND, either express or implied. See the Apache License and the GPL License for
19
- the specific language governing permissions and limitations under the Apache License and the GPL License.
20
- */
21
- (function ($) {
22
- if(typeof $.fn.each2 == "undefined") {
23
- $.extend($.fn, {
24
- /*
25
- * 4-10 times faster .each replacement
26
- * use it carefully, as it overrides jQuery context of element on each iteration
27
- */
28
- each2 : function (c) {
29
- var j = $([0]), i = -1, l = this.length;
30
- while (
31
- ++i < l
32
- && (j.context = j[0] = this[i])
33
- && c.call(j[0], i, j) !== false //"this"=DOM, i=index, j=jQuery object
34
- );
35
- return this;
36
- }
37
- });
38
- }
39
- })(jQuery);
40
-
41
- (function ($, undefined) {
42
- "use strict";
43
- /*global document, window, jQuery, console */
44
-
45
- if (window.Select2 !== undefined) {
46
- return;
47
- }
48
-
49
- var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer,
50
- lastMousePosition={x:0,y:0}, $document, scrollBarDimensions,
51
-
52
- KEY = {
53
- TAB: 9,
54
- ENTER: 13,
55
- ESC: 27,
56
- SPACE: 32,
57
- LEFT: 37,
58
- UP: 38,
59
- RIGHT: 39,
60
- DOWN: 40,
61
- SHIFT: 16,
62
- CTRL: 17,
63
- ALT: 18,
64
- PAGE_UP: 33,
65
- PAGE_DOWN: 34,
66
- HOME: 36,
67
- END: 35,
68
- BACKSPACE: 8,
69
- DELETE: 46,
70
- isArrow: function (k) {
71
- k = k.which ? k.which : k;
72
- switch (k) {
73
- case KEY.LEFT:
74
- case KEY.RIGHT:
75
- case KEY.UP:
76
- case KEY.DOWN:
77
- return true;
78
- }
79
- return false;
80
- },
81
- isControl: function (e) {
82
- var k = e.which;
83
- switch (k) {
84
- case KEY.SHIFT:
85
- case KEY.CTRL:
86
- case KEY.ALT:
87
- return true;
88
- }
89
-
90
- if (e.metaKey) return true;
91
-
92
- return false;
93
- },
94
- isFunctionKey: function (k) {
95
- k = k.which ? k.which : k;
96
- return k >= 112 && k <= 123;
97
- }
98
- },
99
- MEASURE_SCROLLBAR_TEMPLATE = "<div class='select2-measure-scrollbar'></div>",
100
-
101
- DIACRITICS = {"\u24B6":"A","\uFF21":"A","\u00C0":"A","\u00C1":"A","\u00C2":"A","\u1EA6":"A","\u1EA4":"A","\u1EAA":"A","\u1EA8":"A","\u00C3":"A","\u0100":"A","\u0102":"A","\u1EB0":"A","\u1EAE":"A","\u1EB4":"A","\u1EB2":"A","\u0226":"A","\u01E0":"A","\u00C4":"A","\u01DE":"A","\u1EA2":"A","\u00C5":"A","\u01FA":"A","\u01CD":"A","\u0200":"A","\u0202":"A","\u1EA0":"A","\u1EAC":"A","\u1EB6":"A","\u1E00":"A","\u0104":"A","\u023A":"A","\u2C6F":"A","\uA732":"AA","\u00C6":"AE","\u01FC":"AE","\u01E2":"AE","\uA734":"AO","\uA736":"AU","\uA738":"AV","\uA73A":"AV","\uA73C":"AY","\u24B7":"B","\uFF22":"B","\u1E02":"B","\u1E04":"B","\u1E06":"B","\u0243":"B","\u0182":"B","\u0181":"B","\u24B8":"C","\uFF23":"C","\u0106":"C","\u0108":"C","\u010A":"C","\u010C":"C","\u00C7":"C","\u1E08":"C","\u0187":"C","\u023B":"C","\uA73E":"C","\u24B9":"D","\uFF24":"D","\u1E0A":"D","\u010E":"D","\u1E0C":"D","\u1E10":"D","\u1E12":"D","\u1E0E":"D","\u0110":"D","\u018B":"D","\u018A":"D","\u0189":"D","\uA779":"D","\u01F1":"DZ","\u01C4":"DZ","\u01F2":"Dz","\u01C5":"Dz","\u24BA":"E","\uFF25":"E","\u00C8":"E","\u00C9":"E","\u00CA":"E","\u1EC0":"E","\u1EBE":"E","\u1EC4":"E","\u1EC2":"E","\u1EBC":"E","\u0112":"E","\u1E14":"E","\u1E16":"E","\u0114":"E","\u0116":"E","\u00CB":"E","\u1EBA":"E","\u011A":"E","\u0204":"E","\u0206":"E","\u1EB8":"E","\u1EC6":"E","\u0228":"E","\u1E1C":"E","\u0118":"E","\u1E18":"E","\u1E1A":"E","\u0190":"E","\u018E":"E","\u24BB":"F","\uFF26":"F","\u1E1E":"F","\u0191":"F","\uA77B":"F","\u24BC":"G","\uFF27":"G","\u01F4":"G","\u011C":"G","\u1E20":"G","\u011E":"G","\u0120":"G","\u01E6":"G","\u0122":"G","\u01E4":"G","\u0193":"G","\uA7A0":"G","\uA77D":"G","\uA77E":"G","\u24BD":"H","\uFF28":"H","\u0124":"H","\u1E22":"H","\u1E26":"H","\u021E":"H","\u1E24":"H","\u1E28":"H","\u1E2A":"H","\u0126":"H","\u2C67":"H","\u2C75":"H","\uA78D":"H","\u24BE":"I","\uFF29":"I","\u00CC":"I","\u00CD":"I","\u00CE":"I","\u0128":"I","\u012A":"I","\u012C":"I","\u0130":"I","\u00CF":"I","\u1E2E":"I","\u1EC8":"I","\u01CF":"I","\u0208":"I","\u020A":"I","\u1ECA":"I","\u012E":"I","\u1E2C":"I","\u0197":"I","\u24BF":"J","\uFF2A":"J","\u0134":"J","\u0248":"J","\u24C0":"K","\uFF2B":"K","\u1E30":"K","\u01E8":"K","\u1E32":"K","\u0136":"K","\u1E34":"K","\u0198":"K","\u2C69":"K","\uA740":"K","\uA742":"K","\uA744":"K","\uA7A2":"K","\u24C1":"L","\uFF2C":"L","\u013F":"L","\u0139":"L","\u013D":"L","\u1E36":"L","\u1E38":"L","\u013B":"L","\u1E3C":"L","\u1E3A":"L","\u0141":"L","\u023D":"L","\u2C62":"L","\u2C60":"L","\uA748":"L","\uA746":"L","\uA780":"L","\u01C7":"LJ","\u01C8":"Lj","\u24C2":"M","\uFF2D":"M","\u1E3E":"M","\u1E40":"M","\u1E42":"M","\u2C6E":"M","\u019C":"M","\u24C3":"N","\uFF2E":"N","\u01F8":"N","\u0143":"N","\u00D1":"N","\u1E44":"N","\u0147":"N","\u1E46":"N","\u0145":"N","\u1E4A":"N","\u1E48":"N","\u0220":"N","\u019D":"N","\uA790":"N","\uA7A4":"N","\u01CA":"NJ","\u01CB":"Nj","\u24C4":"O","\uFF2F":"O","\u00D2":"O","\u00D3":"O","\u00D4":"O","\u1ED2":"O","\u1ED0":"O","\u1ED6":"O","\u1ED4":"O","\u00D5":"O","\u1E4C":"O","\u022C":"O","\u1E4E":"O","\u014C":"O","\u1E50":"O","\u1E52":"O","\u014E":"O","\u022E":"O","\u0230":"O","\u00D6":"O","\u022A":"O","\u1ECE":"O","\u0150":"O","\u01D1":"O","\u020C":"O","\u020E":"O","\u01A0":"O","\u1EDC":"O","\u1EDA":"O","\u1EE0":"O","\u1EDE":"O","\u1EE2":"O","\u1ECC":"O","\u1ED8":"O","\u01EA":"O","\u01EC":"O","\u00D8":"O","\u01FE":"O","\u0186":"O","\u019F":"O","\uA74A":"O","\uA74C":"O","\u01A2":"OI","\uA74E":"OO","\u0222":"OU","\u24C5":"P","\uFF30":"P","\u1E54":"P","\u1E56":"P","\u01A4":"P","\u2C63":"P","\uA750":"P","\uA752":"P","\uA754":"P","\u24C6":"Q","\uFF31":"Q","\uA756":"Q","\uA758":"Q","\u024A":"Q","\u24C7":"R","\uFF32":"R","\u0154":"R","\u1E58":"R","\u0158":"R","\u0210":"R","\u0212":"R","\u1E5A":"R","\u1E5C":"R","\u0156":"R","\u1E5E":"R","\u024C":"R","\u2C64":"R","\uA75A":"R","\uA7A6":"R","\uA782":"R","\u24C8":"S","\uFF33":"S","\u1E9E":"S","\u015A":"S","\u1E64":"S","\u015C":"S","\u1E60":"S","\u0160":"S","\u1E66":"S","\u1E62":"S","\u1E68":"S","\u0218":"S","\u015E":"S","\u2C7E":"S","\uA7A8":"S","\uA784":"S","\u24C9":"T","\uFF34":"T","\u1E6A":"T","\u0164":"T","\u1E6C":"T","\u021A":"T","\u0162":"T","\u1E70":"T","\u1E6E":"T","\u0166":"T","\u01AC":"T","\u01AE":"T","\u023E":"T","\uA786":"T","\uA728":"TZ","\u24CA":"U","\uFF35":"U","\u00D9":"U","\u00DA":"U","\u00DB":"U","\u0168":"U","\u1E78":"U","\u016A":"U","\u1E7A":"U","\u016C":"U","\u00DC":"U","\u01DB":"U","\u01D7":"U","\u01D5":"U","\u01D9":"U","\u1EE6":"U","\u016E":"U","\u0170":"U","\u01D3":"U","\u0214":"U","\u0216":"U","\u01AF":"U","\u1EEA":"U","\u1EE8":"U","\u1EEE":"U","\u1EEC":"U","\u1EF0":"U","\u1EE4":"U","\u1E72":"U","\u0172":"U","\u1E76":"U","\u1E74":"U","\u0244":"U","\u24CB":"V","\uFF36":"V","\u1E7C":"V","\u1E7E":"V","\u01B2":"V","\uA75E":"V","\u0245":"V","\uA760":"VY","\u24CC":"W","\uFF37":"W","\u1E80":"W","\u1E82":"W","\u0174":"W","\u1E86":"W","\u1E84":"W","\u1E88":"W","\u2C72":"W","\u24CD":"X","\uFF38":"X","\u1E8A":"X","\u1E8C":"X","\u24CE":"Y","\uFF39":"Y","\u1EF2":"Y","\u00DD":"Y","\u0176":"Y","\u1EF8":"Y","\u0232":"Y","\u1E8E":"Y","\u0178":"Y","\u1EF6":"Y","\u1EF4":"Y","\u01B3":"Y","\u024E":"Y","\u1EFE":"Y","\u24CF":"Z","\uFF3A":"Z","\u0179":"Z","\u1E90":"Z","\u017B":"Z","\u017D":"Z","\u1E92":"Z","\u1E94":"Z","\u01B5":"Z","\u0224":"Z","\u2C7F":"Z","\u2C6B":"Z","\uA762":"Z","\u24D0":"a","\uFF41":"a","\u1E9A":"a","\u00E0":"a","\u00E1":"a","\u00E2":"a","\u1EA7":"a","\u1EA5":"a","\u1EAB":"a","\u1EA9":"a","\u00E3":"a","\u0101":"a","\u0103":"a","\u1EB1":"a","\u1EAF":"a","\u1EB5":"a","\u1EB3":"a","\u0227":"a","\u01E1":"a","\u00E4":"a","\u01DF":"a","\u1EA3":"a","\u00E5":"a","\u01FB":"a","\u01CE":"a","\u0201":"a","\u0203":"a","\u1EA1":"a","\u1EAD":"a","\u1EB7":"a","\u1E01":"a","\u0105":"a","\u2C65":"a","\u0250":"a","\uA733":"aa","\u00E6":"ae","\u01FD":"ae","\u01E3":"ae","\uA735":"ao","\uA737":"au","\uA739":"av","\uA73B":"av","\uA73D":"ay","\u24D1":"b","\uFF42":"b","\u1E03":"b","\u1E05":"b","\u1E07":"b","\u0180":"b","\u0183":"b","\u0253":"b","\u24D2":"c","\uFF43":"c","\u0107":"c","\u0109":"c","\u010B":"c","\u010D":"c","\u00E7":"c","\u1E09":"c","\u0188":"c","\u023C":"c","\uA73F":"c","\u2184":"c","\u24D3":"d","\uFF44":"d","\u1E0B":"d","\u010F":"d","\u1E0D":"d","\u1E11":"d","\u1E13":"d","\u1E0F":"d","\u0111":"d","\u018C":"d","\u0256":"d","\u0257":"d","\uA77A":"d","\u01F3":"dz","\u01C6":"dz","\u24D4":"e","\uFF45":"e","\u00E8":"e","\u00E9":"e","\u00EA":"e","\u1EC1":"e","\u1EBF":"e","\u1EC5":"e","\u1EC3":"e","\u1EBD":"e","\u0113":"e","\u1E15":"e","\u1E17":"e","\u0115":"e","\u0117":"e","\u00EB":"e","\u1EBB":"e","\u011B":"e","\u0205":"e","\u0207":"e","\u1EB9":"e","\u1EC7":"e","\u0229":"e","\u1E1D":"e","\u0119":"e","\u1E19":"e","\u1E1B":"e","\u0247":"e","\u025B":"e","\u01DD":"e","\u24D5":"f","\uFF46":"f","\u1E1F":"f","\u0192":"f","\uA77C":"f","\u24D6":"g","\uFF47":"g","\u01F5":"g","\u011D":"g","\u1E21":"g","\u011F":"g","\u0121":"g","\u01E7":"g","\u0123":"g","\u01E5":"g","\u0260":"g","\uA7A1":"g","\u1D79":"g","\uA77F":"g","\u24D7":"h","\uFF48":"h","\u0125":"h","\u1E23":"h","\u1E27":"h","\u021F":"h","\u1E25":"h","\u1E29":"h","\u1E2B":"h","\u1E96":"h","\u0127":"h","\u2C68":"h","\u2C76":"h","\u0265":"h","\u0195":"hv","\u24D8":"i","\uFF49":"i","\u00EC":"i","\u00ED":"i","\u00EE":"i","\u0129":"i","\u012B":"i","\u012D":"i","\u00EF":"i","\u1E2F":"i","\u1EC9":"i","\u01D0":"i","\u0209":"i","\u020B":"i","\u1ECB":"i","\u012F":"i","\u1E2D":"i","\u0268":"i","\u0131":"i","\u24D9":"j","\uFF4A":"j","\u0135":"j","\u01F0":"j","\u0249":"j","\u24DA":"k","\uFF4B":"k","\u1E31":"k","\u01E9":"k","\u1E33":"k","\u0137":"k","\u1E35":"k","\u0199":"k","\u2C6A":"k","\uA741":"k","\uA743":"k","\uA745":"k","\uA7A3":"k","\u24DB":"l","\uFF4C":"l","\u0140":"l","\u013A":"l","\u013E":"l","\u1E37":"l","\u1E39":"l","\u013C":"l","\u1E3D":"l","\u1E3B":"l","\u017F":"l","\u0142":"l","\u019A":"l","\u026B":"l","\u2C61":"l","\uA749":"l","\uA781":"l","\uA747":"l","\u01C9":"lj","\u24DC":"m","\uFF4D":"m","\u1E3F":"m","\u1E41":"m","\u1E43":"m","\u0271":"m","\u026F":"m","\u24DD":"n","\uFF4E":"n","\u01F9":"n","\u0144":"n","\u00F1":"n","\u1E45":"n","\u0148":"n","\u1E47":"n","\u0146":"n","\u1E4B":"n","\u1E49":"n","\u019E":"n","\u0272":"n","\u0149":"n","\uA791":"n","\uA7A5":"n","\u01CC":"nj","\u24DE":"o","\uFF4F":"o","\u00F2":"o","\u00F3":"o","\u00F4":"o","\u1ED3":"o","\u1ED1":"o","\u1ED7":"o","\u1ED5":"o","\u00F5":"o","\u1E4D":"o","\u022D":"o","\u1E4F":"o","\u014D":"o","\u1E51":"o","\u1E53":"o","\u014F":"o","\u022F":"o","\u0231":"o","\u00F6":"o","\u022B":"o","\u1ECF":"o","\u0151":"o","\u01D2":"o","\u020D":"o","\u020F":"o","\u01A1":"o","\u1EDD":"o","\u1EDB":"o","\u1EE1":"o","\u1EDF":"o","\u1EE3":"o","\u1ECD":"o","\u1ED9":"o","\u01EB":"o","\u01ED":"o","\u00F8":"o","\u01FF":"o","\u0254":"o","\uA74B":"o","\uA74D":"o","\u0275":"o","\u01A3":"oi","\u0223":"ou","\uA74F":"oo","\u24DF":"p","\uFF50":"p","\u1E55":"p","\u1E57":"p","\u01A5":"p","\u1D7D":"p","\uA751":"p","\uA753":"p","\uA755":"p","\u24E0":"q","\uFF51":"q","\u024B":"q","\uA757":"q","\uA759":"q","\u24E1":"r","\uFF52":"r","\u0155":"r","\u1E59":"r","\u0159":"r","\u0211":"r","\u0213":"r","\u1E5B":"r","\u1E5D":"r","\u0157":"r","\u1E5F":"r","\u024D":"r","\u027D":"r","\uA75B":"r","\uA7A7":"r","\uA783":"r","\u24E2":"s","\uFF53":"s","\u00DF":"s","\u015B":"s","\u1E65":"s","\u015D":"s","\u1E61":"s","\u0161":"s","\u1E67":"s","\u1E63":"s","\u1E69":"s","\u0219":"s","\u015F":"s","\u023F":"s","\uA7A9":"s","\uA785":"s","\u1E9B":"s","\u24E3":"t","\uFF54":"t","\u1E6B":"t","\u1E97":"t","\u0165":"t","\u1E6D":"t","\u021B":"t","\u0163":"t","\u1E71":"t","\u1E6F":"t","\u0167":"t","\u01AD":"t","\u0288":"t","\u2C66":"t","\uA787":"t","\uA729":"tz","\u24E4":"u","\uFF55":"u","\u00F9":"u","\u00FA":"u","\u00FB":"u","\u0169":"u","\u1E79":"u","\u016B":"u","\u1E7B":"u","\u016D":"u","\u00FC":"u","\u01DC":"u","\u01D8":"u","\u01D6":"u","\u01DA":"u","\u1EE7":"u","\u016F":"u","\u0171":"u","\u01D4":"u","\u0215":"u","\u0217":"u","\u01B0":"u","\u1EEB":"u","\u1EE9":"u","\u1EEF":"u","\u1EED":"u","\u1EF1":"u","\u1EE5":"u","\u1E73":"u","\u0173":"u","\u1E77":"u","\u1E75":"u","\u0289":"u","\u24E5":"v","\uFF56":"v","\u1E7D":"v","\u1E7F":"v","\u028B":"v","\uA75F":"v","\u028C":"v","\uA761":"vy","\u24E6":"w","\uFF57":"w","\u1E81":"w","\u1E83":"w","\u0175":"w","\u1E87":"w","\u1E85":"w","\u1E98":"w","\u1E89":"w","\u2C73":"w","\u24E7":"x","\uFF58":"x","\u1E8B":"x","\u1E8D":"x","\u24E8":"y","\uFF59":"y","\u1EF3":"y","\u00FD":"y","\u0177":"y","\u1EF9":"y","\u0233":"y","\u1E8F":"y","\u00FF":"y","\u1EF7":"y","\u1E99":"y","\u1EF5":"y","\u01B4":"y","\u024F":"y","\u1EFF":"y","\u24E9":"z","\uFF5A":"z","\u017A":"z","\u1E91":"z","\u017C":"z","\u017E":"z","\u1E93":"z","\u1E95":"z","\u01B6":"z","\u0225":"z","\u0240":"z","\u2C6C":"z","\uA763":"z"};
102
-
103
- $document = $(document);
104
-
105
- nextUid=(function() { var counter=1; return function() { return counter++; }; }());
106
-
107
-
108
- function stripDiacritics(str) {
109
- var ret, i, l, c;
110
-
111
- if (!str || str.length < 1) return str;
112
-
113
- ret = "";
114
- for (i = 0, l = str.length; i < l; i++) {
115
- c = str.charAt(i);
116
- ret += DIACRITICS[c] || c;
117
- }
118
- return ret;
119
- }
120
-
121
- function indexOf(value, array) {
122
- var i = 0, l = array.length;
123
- for (; i < l; i = i + 1) {
124
- if (equal(value, array[i])) return i;
125
- }
126
- return -1;
127
- }
128
-
129
- function measureScrollbar () {
130
- var $template = $( MEASURE_SCROLLBAR_TEMPLATE );
131
- $template.appendTo('body');
132
-
133
- var dim = {
134
- width: $template.width() - $template[0].clientWidth,
135
- height: $template.height() - $template[0].clientHeight
136
- };
137
- $template.remove();
138
-
139
- return dim;
140
- }
141
-
142
- /**
143
- * Compares equality of a and b
144
- * @param a
145
- * @param b
146
- */
147
- function equal(a, b) {
148
- if (a === b) return true;
149
- if (a === undefined || b === undefined) return false;
150
- if (a === null || b === null) return false;
151
- // Check whether 'a' or 'b' is a string (primitive or object).
152
- // The concatenation of an empty string (+'') converts its argument to a string's primitive.
153
- if (a.constructor === String) return a+'' === b+''; // a+'' - in case 'a' is a String object
154
- if (b.constructor === String) return b+'' === a+''; // b+'' - in case 'b' is a String object
155
- return false;
156
- }
157
-
158
- /**
159
- * Splits the string into an array of values, trimming each value. An empty array is returned for nulls or empty
160
- * strings
161
- * @param string
162
- * @param separator
163
- */
164
- function splitVal(string, separator) {
165
- var val, i, l;
166
- if (string === null || string.length < 1) return [];
167
- val = string.split(separator);
168
- for (i = 0, l = val.length; i < l; i = i + 1) val[i] = $.trim(val[i]);
169
- return val;
170
- }
171
-
172
- function getSideBorderPadding(element) {
173
- return element.outerWidth(false) - element.width();
174
- }
175
-
176
- function installKeyUpChangeEvent(element) {
177
- var key="keyup-change-value";
178
- element.on("keydown", function () {
179
- if ($.data(element, key) === undefined) {
180
- $.data(element, key, element.val());
181
- }
182
- });
183
- element.on("keyup", function () {
184
- var val= $.data(element, key);
185
- if (val !== undefined && element.val() !== val) {
186
- $.removeData(element, key);
187
- element.trigger("keyup-change");
188
- }
189
- });
190
- }
191
-
192
- $document.on("mousemove", function (e) {
193
- lastMousePosition.x = e.pageX;
194
- lastMousePosition.y = e.pageY;
195
- });
196
-
197
- /**
198
- * filters mouse events so an event is fired only if the mouse moved.
199
- *
200
- * filters out mouse events that occur when mouse is stationary but
201
- * the elements under the pointer are scrolled.
202
- */
203
- function installFilteredMouseMove(element) {
204
- element.on("mousemove", function (e) {
205
- var lastpos = lastMousePosition;
206
- if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
207
- $(e.target).trigger("mousemove-filtered", e);
208
- }
209
- });
210
- }
211
-
212
- /**
213
- * Debounces a function. Returns a function that calls the original fn function only if no invocations have been made
214
- * within the last quietMillis milliseconds.
215
- *
216
- * @param quietMillis number of milliseconds to wait before invoking fn
217
- * @param fn function to be debounced
218
- * @param ctx object to be used as this reference within fn
219
- * @return debounced version of fn
220
- */
221
- function debounce(quietMillis, fn, ctx) {
222
- ctx = ctx || undefined;
223
- var timeout;
224
- return function () {
225
- var args = arguments;
226
- window.clearTimeout(timeout);
227
- timeout = window.setTimeout(function() {
228
- fn.apply(ctx, args);
229
- }, quietMillis);
230
- };
231
- }
232
-
233
- /**
234
- * A simple implementation of a thunk
235
- * @param formula function used to lazily initialize the thunk
236
- * @return {Function}
237
- */
238
- function thunk(formula) {
239
- var evaluated = false,
240
- value;
241
- return function() {
242
- if (evaluated === false) { value = formula(); evaluated = true; }
243
- return value;
244
- };
245
- };
246
-
247
- function installDebouncedScroll(threshold, element) {
248
- var notify = debounce(threshold, function (e) { element.trigger("scroll-debounced", e);});
249
- element.on("scroll", function (e) {
250
- if (indexOf(e.target, element.get()) >= 0) notify(e);
251
- });
252
- }
253
-
254
- function focus($el) {
255
- if ($el[0] === document.activeElement) return;
256
-
257
- /* set the focus in a 0 timeout - that way the focus is set after the processing
258
- of the current event has finished - which seems like the only reliable way
259
- to set focus */
260
- window.setTimeout(function() {
261
- var el=$el[0], pos=$el.val().length, range;
262
-
263
- $el.focus();
264
-
265
- /* make sure el received focus so we do not error out when trying to manipulate the caret.
266
- sometimes modals or others listeners may steal it after its set */
267
- if ($el.is(":visible") && el === document.activeElement) {
268
-
269
- /* after the focus is set move the caret to the end, necessary when we val()
270
- just before setting focus */
271
- if(el.setSelectionRange)
272
- {
273
- el.setSelectionRange(pos, pos);
274
- }
275
- else if (el.createTextRange) {
276
- range = el.createTextRange();
277
- range.collapse(false);
278
- range.select();
279
- }
280
- }
281
- }, 0);
282
- }
283
-
284
- function getCursorInfo(el) {
285
- el = $(el)[0];
286
- var offset = 0;
287
- var length = 0;
288
- if ('selectionStart' in el) {
289
- offset = el.selectionStart;
290
- length = el.selectionEnd - offset;
291
- } else if ('selection' in document) {
292
- el.focus();
293
- var sel = document.selection.createRange();
294
- length = document.selection.createRange().text.length;
295
- sel.moveStart('character', -el.value.length);
296
- offset = sel.text.length - length;
297
- }
298
- return { offset: offset, length: length };
299
- }
300
-
301
- function killEvent(event) {
302
- event.preventDefault();
303
- event.stopPropagation();
304
- }
305
- function killEventImmediately(event) {
306
- event.preventDefault();
307
- event.stopImmediatePropagation();
308
- }
309
-
310
- function measureTextWidth(e) {
311
- if (!sizer){
312
- var style = e[0].currentStyle || window.getComputedStyle(e[0], null);
313
- sizer = $(document.createElement("div")).css({
314
- position: "absolute",
315
- left: "-10000px",
316
- top: "-10000px",
317
- display: "none",
318
- fontSize: style.fontSize,
319
- fontFamily: style.fontFamily,
320
- fontStyle: style.fontStyle,
321
- fontWeight: style.fontWeight,
322
- letterSpacing: style.letterSpacing,
323
- textTransform: style.textTransform,
324
- whiteSpace: "nowrap"
325
- });
326
- sizer.attr("class","select2-sizer");
327
- $("body").append(sizer);
328
- }
329
- sizer.text(e.val());
330
- return sizer.width();
331
- }
332
-
333
- function syncCssClasses(dest, src, adapter) {
334
- var classes, replacements = [], adapted;
335
-
336
- classes = dest.attr("class");
337
- if (classes) {
338
- classes = '' + classes; // for IE which returns object
339
- $(classes.split(" ")).each2(function() {
340
- if (this.indexOf("select2-") === 0) {
341
- replacements.push(this);
342
- }
343
- });
344
- }
345
- classes = src.attr("class");
346
- if (classes) {
347
- classes = '' + classes; // for IE which returns object
348
- $(classes.split(" ")).each2(function() {
349
- if (this.indexOf("select2-") !== 0) {
350
- adapted = adapter(this);
351
- if (adapted) {
352
- replacements.push(this);
353
- }
354
- }
355
- });
356
- }
357
- dest.attr("class", replacements.join(" "));
358
- }
359
-
360
-
361
- function markMatch(text, term, markup, escapeMarkup) {
362
- var match=stripDiacritics(text.toUpperCase()).indexOf(stripDiacritics(term.toUpperCase())),
363
- tl=term.length;
364
-
365
- if (match<0) {
366
- markup.push(escapeMarkup(text));
367
- return;
368
- }
369
-
370
- markup.push(escapeMarkup(text.substring(0, match)));
371
- markup.push("<span class='select2-match'>");
372
- markup.push(escapeMarkup(text.substring(match, match + tl)));
373
- markup.push("</span>");
374
- markup.push(escapeMarkup(text.substring(match + tl, text.length)));
375
- }
376
-
377
- function defaultEscapeMarkup(markup) {
378
- var replace_map = {
379
- '\\': '&#92;',
380
- '&': '&amp;',
381
- '<': '&lt;',
382
- '>': '&gt;',
383
- '"': '&quot;',
384
- "'": '&#39;',
385
- "/": '&#47;'
386
- };
387
-
388
- return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
389
- return replace_map[match];
390
- });
391
- }
392
-
393
- /**
394
- * Produces an ajax-based query function
395
- *
396
- * @param options object containing configuration paramters
397
- * @param options.params parameter map for the transport ajax call, can contain such options as cache, jsonpCallback, etc. see $.ajax
398
- * @param options.transport function that will be used to execute the ajax request. must be compatible with parameters supported by $.ajax
399
- * @param options.url url for the data
400
- * @param options.data a function(searchTerm, pageNumber, context) that should return an object containing query string parameters for the above url.
401
- * @param options.dataType request data type: ajax, jsonp, other datatatypes supported by jQuery's $.ajax function or the transport function if specified
402
- * @param options.quietMillis (optional) milliseconds to wait before making the ajaxRequest, helps debounce the ajax function if invoked too often
403
- * @param options.results a function(remoteData, pageNumber) that converts data returned form the remote request to the format expected by Select2.
404
- * The expected format is an object containing the following keys:
405
- * results array of objects that will be used as choices
406
- * more (optional) boolean indicating whether there are more results available
407
- * Example: {results:[{id:1, text:'Red'},{id:2, text:'Blue'}], more:true}
408
- */
409
- function ajax(options) {
410
- var timeout, // current scheduled but not yet executed request
411
- handler = null,
412
- quietMillis = options.quietMillis || 100,
413
- ajaxUrl = options.url,
414
- self = this;
415
-
416
- return function (query) {
417
- window.clearTimeout(timeout);
418
- timeout = window.setTimeout(function () {
419
- var data = options.data, // ajax data function
420
- url = ajaxUrl, // ajax url string or function
421
- transport = options.transport || $.fn.select2.ajaxDefaults.transport,
422
- // deprecated - to be removed in 4.0 - use params instead
423
- deprecated = {
424
- type: options.type || 'GET', // set type of request (GET or POST)
425
- cache: options.cache || false,
426
- jsonpCallback: options.jsonpCallback||undefined,
427
- dataType: options.dataType||"json"
428
- },
429
- params = $.extend({}, $.fn.select2.ajaxDefaults.params, deprecated);
430
-
431
- data = data ? data.call(self, query.term, query.page, query.context) : null;
432
- url = (typeof url === 'function') ? url.call(self, query.term, query.page, query.context) : url;
433
-
434
- if (handler) { handler.abort(); }
435
-
436
- if (options.params) {
437
- if ($.isFunction(options.params)) {
438
- $.extend(params, options.params.call(self));
439
- } else {
440
- $.extend(params, options.params);
441
- }
442
- }
443
-
444
- $.extend(params, {
445
- url: url,
446
- dataType: options.dataType,
447
- data: data,
448
- success: function (data) {
449
- // TODO - replace query.page with query so users have access to term, page, etc.
450
- var results = options.results(data, query.page);
451
- query.callback(results);
452
- }
453
- });
454
- handler = transport.call(self, params);
455
- }, quietMillis);
456
- };
457
- }
458
-
459
- /**
460
- * Produces a query function that works with a local array
461
- *
462
- * @param options object containing configuration parameters. The options parameter can either be an array or an
463
- * object.
464
- *
465
- * If the array form is used it is assumed that it contains objects with 'id' and 'text' keys.
466
- *
467
- * If the object form is used ti is assumed that it contains 'data' and 'text' keys. The 'data' key should contain
468
- * an array of objects that will be used as choices. These objects must contain at least an 'id' key. The 'text'
469
- * key can either be a String in which case it is expected that each element in the 'data' array has a key with the
470
- * value of 'text' which will be used to match choices. Alternatively, text can be a function(item) that can extract
471
- * the text.
472
- */
473
- function local(options) {
474
- var data = options, // data elements
475
- dataText,
476
- tmp,
477
- text = function (item) { return ""+item.text; }; // function used to retrieve the text portion of a data item that is matched against the search
478
-
479
- if ($.isArray(data)) {
480
- tmp = data;
481
- data = { results: tmp };
482
- }
483
-
484
- if ($.isFunction(data) === false) {
485
- tmp = data;
486
- data = function() { return tmp; };
487
- }
488
-
489
- var dataItem = data();
490
- if (dataItem.text) {
491
- text = dataItem.text;
492
- // if text is not a function we assume it to be a key name
493
- if (!$.isFunction(text)) {
494
- dataText = dataItem.text; // we need to store this in a separate variable because in the next step data gets reset and data.text is no longer available
495
- text = function (item) { return item[dataText]; };
496
- }
497
- }
498
-
499
- return function (query) {
500
- var t = query.term, filtered = { results: [] }, process;
501
- if (t === "") {
502
- query.callback(data());
503
- return;
504
- }
505
-
506
- process = function(datum, collection) {
507
- var group, attr;
508
- datum = datum[0];
509
- if (datum.children) {
510
- group = {};
511
- for (attr in datum) {
512
- if (datum.hasOwnProperty(attr)) group[attr]=datum[attr];
513
- }
514
- group.children=[];
515
- $(datum.children).each2(function(i, childDatum) { process(childDatum, group.children); });
516
- if (group.children.length || query.matcher(t, text(group), datum)) {
517
- collection.push(group);
518
- }
519
- } else {
520
- if (query.matcher(t, text(datum), datum)) {
521
- collection.push(datum);
522
- }
523
- }
524
- };
525
-
526
- $(data().results).each2(function(i, datum) { process(datum, filtered.results); });
527
- query.callback(filtered);
528
- };
529
- }
530
-
531
- // TODO javadoc
532
- function tags(data) {
533
- var isFunc = $.isFunction(data);
534
- return function (query) {
535
- var t = query.term, filtered = {results: []};
536
- $(isFunc ? data() : data).each(function () {
537
- var isObject = this.text !== undefined,
538
- text = isObject ? this.text : this;
539
- if (t === "" || query.matcher(t, text)) {
540
- filtered.results.push(isObject ? this : {id: this, text: this});
541
- }
542
- });
543
- query.callback(filtered);
544
- };
545
- }
546
-
547
- /**
548
- * Checks if the formatter function should be used.
549
- *
550
- * Throws an error if it is not a function. Returns true if it should be used,
551
- * false if no formatting should be performed.
552
- *
553
- * @param formatter
554
- */
555
- function checkFormatter(formatter, formatterName) {
556
- if ($.isFunction(formatter)) return true;
557
- if (!formatter) return false;
558
- throw new Error(formatterName +" must be a function or a falsy value");
559
- }
560
-
561
- function evaluate(val) {
562
- return $.isFunction(val) ? val() : val;
563
- }
564
-
565
- function countResults(results) {
566
- var count = 0;
567
- $.each(results, function(i, item) {
568
- if (item.children) {
569
- count += countResults(item.children);
570
- } else {
571
- count++;
572
- }
573
- });
574
- return count;
575
- }
576
-
577
- /**
578
- * Default tokenizer. This function uses breaks the input on substring match of any string from the
579
- * opts.tokenSeparators array and uses opts.createSearchChoice to create the choice object. Both of those
580
- * two options have to be defined in order for the tokenizer to work.
581
- *
582
- * @param input text user has typed so far or pasted into the search field
583
- * @param selection currently selected choices
584
- * @param selectCallback function(choice) callback tho add the choice to selection
585
- * @param opts select2's opts
586
- * @return undefined/null to leave the current input unchanged, or a string to change the input to the returned value
587
- */
588
- function defaultTokenizer(input, selection, selectCallback, opts) {
589
- var original = input, // store the original so we can compare and know if we need to tell the search to update its text
590
- dupe = false, // check for whether a token we extracted represents a duplicate selected choice
591
- token, // token
592
- index, // position at which the separator was found
593
- i, l, // looping variables
594
- separator; // the matched separator
595
-
596
- if (!opts.createSearchChoice || !opts.tokenSeparators || opts.tokenSeparators.length < 1) return undefined;
597
-
598
- while (true) {
599
- index = -1;
600
-
601
- for (i = 0, l = opts.tokenSeparators.length; i < l; i++) {
602
- separator = opts.tokenSeparators[i];
603
- index = input.indexOf(separator);
604
- if (index >= 0) break;
605
- }
606
-
607
- if (index < 0) break; // did not find any token separator in the input string, bail
608
-
609
- token = input.substring(0, index);
610
- input = input.substring(index + separator.length);
611
-
612
- if (token.length > 0) {
613
- token = opts.createSearchChoice.call(this, token, selection);
614
- if (token !== undefined && token !== null && opts.id(token) !== undefined && opts.id(token) !== null) {
615
- dupe = false;
616
- for (i = 0, l = selection.length; i < l; i++) {
617
- if (equal(opts.id(token), opts.id(selection[i]))) {
618
- dupe = true; break;
619
- }
620
- }
621
-
622
- if (!dupe) selectCallback(token);
623
- }
624
- }
625
- }
626
-
627
- if (original!==input) return input;
628
- }
629
-
630
- /**
631
- * Creates a new class
632
- *
633
- * @param superClass
634
- * @param methods
635
- */
636
- function clazz(SuperClass, methods) {
637
- var constructor = function () {};
638
- constructor.prototype = new SuperClass;
639
- constructor.prototype.constructor = constructor;
640
- constructor.prototype.parent = SuperClass.prototype;
641
- constructor.prototype = $.extend(constructor.prototype, methods);
642
- return constructor;
643
- }
644
-
645
- AbstractSelect2 = clazz(Object, {
646
-
647
- // abstract
648
- bind: function (func) {
649
- var self = this;
650
- return function () {
651
- func.apply(self, arguments);
652
- };
653
- },
654
-
655
- // abstract
656
- init: function (opts) {
657
- var results, search, resultsSelector = ".select2-results", disabled, readonly;
658
-
659
- // prepare options
660
- this.opts = opts = this.prepareOpts(opts);
661
-
662
- this.id=opts.id;
663
-
664
- // destroy if called on an existing component
665
- if (opts.element.data("select2") !== undefined &&
666
- opts.element.data("select2") !== null) {
667
- opts.element.data("select2").destroy();
668
- }
669
-
670
- this.container = this.createContainer();
671
-
672
- this.containerId="s2id_"+(opts.element.attr("id") || "autogen"+nextUid());
673
- this.containerSelector="#"+this.containerId.replace(/([;&,\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g, '\\$1');
674
- this.container.attr("id", this.containerId);
675
-
676
- // cache the body so future lookups are cheap
677
- this.body = thunk(function() { return opts.element.closest("body"); });
678
-
679
- syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
680
-
681
- this.container.attr("style", opts.element.attr("style"));
682
- this.container.css(evaluate(opts.containerCss));
683
- this.container.addClass(evaluate(opts.containerCssClass));
684
-
685
- this.elementTabIndex = this.opts.element.attr("tabindex");
686
-
687
- // swap container for the element
688
- this.opts.element
689
- .data("select2", this)
690
- .attr("tabindex", "-1")
691
- .before(this.container)
692
- .on("click.select2", killEvent); // do not leak click events
693
-
694
- this.container.data("select2", this);
695
-
696
- this.dropdown = this.container.find(".select2-drop");
697
-
698
- syncCssClasses(this.dropdown, this.opts.element, this.opts.adaptDropdownCssClass);
699
-
700
- this.dropdown.addClass(evaluate(opts.dropdownCssClass));
701
- this.dropdown.data("select2", this);
702
- this.dropdown.on("click", killEvent);
703
-
704
- this.results = results = this.container.find(resultsSelector);
705
- this.search = search = this.container.find("input.select2-input");
706
-
707
- this.queryCount = 0;
708
- this.resultsPage = 0;
709
- this.context = null;
710
-
711
- // initialize the container
712
- this.initContainer();
713
-
714
- this.container.on("click", killEvent);
715
-
716
- installFilteredMouseMove(this.results);
717
- this.dropdown.on("mousemove-filtered touchstart touchmove touchend", resultsSelector, this.bind(this.highlightUnderEvent));
718
-
719
- installDebouncedScroll(80, this.results);
720
- this.dropdown.on("scroll-debounced", resultsSelector, this.bind(this.loadMoreIfNeeded));
721
-
722
- // do not propagate change event from the search field out of the component
723
- $(this.container).on("change", ".select2-input", function(e) {e.stopPropagation();});
724
- $(this.dropdown).on("change", ".select2-input", function(e) {e.stopPropagation();});
725
-
726
- // if jquery.mousewheel plugin is installed we can prevent out-of-bounds scrolling of results via mousewheel
727
- if ($.fn.mousewheel) {
728
- results.mousewheel(function (e, delta, deltaX, deltaY) {
729
- var top = results.scrollTop(), height;
730
- if (deltaY > 0 && top - deltaY <= 0) {
731
- results.scrollTop(0);
732
- killEvent(e);
733
- } else if (deltaY < 0 && results.get(0).scrollHeight - results.scrollTop() + deltaY <= results.height()) {
734
- results.scrollTop(results.get(0).scrollHeight - results.height());
735
- killEvent(e);
736
- }
737
- });
738
- }
739
-
740
- installKeyUpChangeEvent(search);
741
- search.on("keyup-change input paste", this.bind(this.updateResults));
742
- search.on("focus", function () { search.addClass("select2-focused"); });
743
- search.on("blur", function () { search.removeClass("select2-focused");});
744
-
745
- this.dropdown.on("mouseup", resultsSelector, this.bind(function (e) {
746
- if ($(e.target).closest(".select2-result-selectable").length > 0) {
747
- this.highlightUnderEvent(e);
748
- this.selectHighlighted(e);
749
- }
750
- }));
751
-
752
- // trap all mouse events from leaving the dropdown. sometimes there may be a modal that is listening
753
- // for mouse events outside of itself so it can close itself. since the dropdown is now outside the select2's
754
- // dom it will trigger the popup close, which is not what we want
755
- this.dropdown.on("click mouseup mousedown", function (e) { e.stopPropagation(); });
756
-
757
- if ($.isFunction(this.opts.initSelection)) {
758
- // initialize selection based on the current value of the source element
759
- this.initSelection();
760
-
761
- // if the user has provided a function that can set selection based on the value of the source element
762
- // we monitor the change event on the element and trigger it, allowing for two way synchronization
763
- this.monitorSource();
764
- }
765
-
766
- if (opts.maximumInputLength !== null) {
767
- this.search.attr("maxlength", opts.maximumInputLength);
768
- }
769
-
770
- var disabled = opts.element.prop("disabled");
771
- if (disabled === undefined) disabled = false;
772
- this.enable(!disabled);
773
-
774
- var readonly = opts.element.prop("readonly");
775
- if (readonly === undefined) readonly = false;
776
- this.readonly(readonly);
777
-
778
- // Calculate size of scrollbar
779
- scrollBarDimensions = scrollBarDimensions || measureScrollbar();
780
-
781
- this.autofocus = opts.element.prop("autofocus");
782
- opts.element.prop("autofocus", false);
783
- if (this.autofocus) this.focus();
784
-
785
- this.nextSearchTerm = undefined;
786
-
787
- // MODIFIED
788
- if (this.opts.afterInitialize) { this.opts.afterInitialize(this) }
789
- },
790
-
791
- // abstract
792
- destroy: function () {
793
- var element=this.opts.element, select2 = element.data("select2");
794
-
795
- this.close();
796
-
797
- if (this.propertyObserver) { delete this.propertyObserver; this.propertyObserver = null; }
798
-
799
- if (select2 !== undefined) {
800
- select2.container.remove();
801
- select2.dropdown.remove();
802
- element
803
- .removeClass("select2-offscreen")
804
- .removeData("select2")
805
- .off(".select2")
806
- .prop("autofocus", this.autofocus || false);
807
- if (this.elementTabIndex) {
808
- element.attr({tabindex: this.elementTabIndex});
809
- } else {
810
- element.removeAttr("tabindex");
811
- }
812
- element.show();
813
- }
814
- },
815
-
816
- // abstract
817
- optionToData: function(element) {
818
- if (element.is("option")) {
819
- return {
820
- id:element.prop("value"),
821
- text:element.text(),
822
- element: element.get(),
823
- css: element.attr("class"),
824
- disabled: element.prop("disabled"),
825
- locked: equal(element.attr("locked"), "locked") || equal(element.data("locked"), true)
826
- };
827
- } else if (element.is("optgroup")) {
828
- return {
829
- text:element.attr("label"),
830
- children:[],
831
- element: element.get(),
832
- css: element.attr("class")
833
- };
834
- }
835
- },
836
-
837
- // abstract
838
- prepareOpts: function (opts) {
839
- var element, select, idKey, ajaxUrl, self = this;
840
-
841
- element = opts.element;
842
-
843
- if (element.get(0).tagName.toLowerCase() === "select") {
844
- this.select = select = opts.element;
845
- }
846
-
847
- if (select) {
848
- // these options are not allowed when attached to a select because they are picked up off the element itself
849
- $.each(["id", "multiple", "ajax", "query", "createSearchChoice", "initSelection", "data", "tags"], function () {
850
- if (this in opts) {
851
- throw new Error("Option '" + this + "' is not allowed for Select2 when attached to a <select> element.");
852
- }
853
- });
854
- }
855
-
856
- opts = $.extend({}, {
857
- populateResults: function(container, results, query) {
858
- var populate, data, result, children, id=this.opts.id;
859
-
860
- populate=function(results, container, depth) {
861
-
862
- var i, l, result, selectable, disabled, compound, node, label, innerContainer, formatted;
863
-
864
- results = opts.sortResults(results, container, query);
865
-
866
- for (i = 0, l = results.length; i < l; i = i + 1) {
867
-
868
- result=results[i];
869
-
870
- disabled = (result.disabled === true);
871
- selectable = (!disabled) && (id(result) !== undefined);
872
-
873
- compound=result.children && result.children.length > 0;
874
-
875
- node=$("<li></li>");
876
- node.addClass("select2-results-dept-"+depth);
877
- node.addClass("select2-result");
878
- node.addClass(selectable ? "select2-result-selectable" : "select2-result-unselectable");
879
- if (disabled) { node.addClass("select2-disabled"); }
880
- if (compound) { node.addClass("select2-result-with-children"); }
881
- node.addClass(self.opts.formatResultCssClass(result));
882
-
883
- label=$(document.createElement("div"));
884
- label.addClass("select2-result-label");
885
-
886
- formatted=opts.formatResult(result, label, query, self.opts.escapeMarkup);
887
- if (formatted!==undefined) {
888
- label.html(formatted);
889
- }
890
-
891
- node.append(label);
892
-
893
- if (compound) {
894
-
895
- innerContainer=$("<ul></ul>");
896
- innerContainer.addClass("select2-result-sub");
897
- populate(result.children, innerContainer, depth+1);
898
- node.append(innerContainer);
899
- }
900
-
901
- node.data("select2-data", result);
902
- container.append(node);
903
- }
904
- };
905
-
906
- populate(results, container, 0);
907
- }
908
- }, $.fn.select2.defaults, opts);
909
-
910
- if (typeof(opts.id) !== "function") {
911
- idKey = opts.id;
912
- opts.id = function (e) { return e[idKey]; };
913
- }
914
-
915
- if ($.isArray(opts.element.data("select2Tags"))) {
916
- if ("tags" in opts) {
917
- throw "tags specified as both an attribute 'data-select2-tags' and in options of Select2 " + opts.element.attr("id");
918
- }
919
- opts.tags=opts.element.data("select2Tags");
920
- }
921
-
922
- if (select) {
923
- opts.query = this.bind(function (query) {
924
- var data = { results: [], more: false },
925
- term = query.term,
926
- children, placeholderOption, process;
927
-
928
- process=function(element, collection) {
929
- var group;
930
- if (element.is("option")) {
931
- if (query.matcher(term, element.text(), element)) {
932
- collection.push(self.optionToData(element));
933
- }
934
- } else if (element.is("optgroup")) {
935
- group=self.optionToData(element);
936
- element.children().each2(function(i, elm) { process(elm, group.children); });
937
- if (group.children.length>0) {
938
- collection.push(group);
939
- }
940
- }
941
- };
942
-
943
- children=element.children();
944
-
945
- // ignore the placeholder option if there is one
946
- if (this.getPlaceholder() !== undefined && children.length > 0) {
947
- placeholderOption = this.getPlaceholderOption();
948
- if (placeholderOption) {
949
- children=children.not(placeholderOption);
950
- }
951
- }
952
-
953
- children.each2(function(i, elm) { process(elm, data.results); });
954
-
955
- query.callback(data);
956
- });
957
- // this is needed because inside val() we construct choices from options and there id is hardcoded
958
- opts.id=function(e) { return e.id; };
959
- opts.formatResultCssClass = function(data) { return data.css; };
960
- } else {
961
- if (!("query" in opts)) {
962
-
963
- if ("ajax" in opts) {
964
- ajaxUrl = opts.element.data("ajax-url");
965
- if (ajaxUrl && ajaxUrl.length > 0) {
966
- opts.ajax.url = ajaxUrl;
967
- }
968
- opts.query = ajax.call(opts.element, opts.ajax);
969
- } else if ("data" in opts) {
970
- opts.query = local(opts.data);
971
- } else if ("tags" in opts) {
972
- opts.query = tags(opts.tags);
973
- if (opts.createSearchChoice === undefined) {
974
- opts.createSearchChoice = function (term) { return {id: $.trim(term), text: $.trim(term)}; };
975
- }
976
- if (opts.initSelection === undefined) {
977
- opts.initSelection = function (element, callback) {
978
- var data = [];
979
- $(splitVal(element.val(), opts.separator)).each(function () {
980
- var obj = { id: this, text: this },
981
- tags = opts.tags;
982
- if ($.isFunction(tags)) tags=tags();
983
- $(tags).each(function() { if (equal(this.id, obj.id)) { obj = this; return false; } });
984
- data.push(obj);
985
- });
986
-
987
- callback(data);
988
- };
989
- }
990
- }
991
- }
992
- }
993
- if (typeof(opts.query) !== "function") {
994
- throw "query function not defined for Select2 " + opts.element.attr("id");
995
- }
996
-
997
- return opts;
998
- },
999
-
1000
- /**
1001
- * Monitor the original element for changes and update select2 accordingly
1002
- */
1003
- // abstract
1004
- monitorSource: function () {
1005
- var el = this.opts.element, sync;
1006
-
1007
- el.on("change.select2", this.bind(function (e) {
1008
- if (this.opts.element.data("select2-change-triggered") !== true) {
1009
- this.initSelection();
1010
- }
1011
- }));
1012
-
1013
- sync = this.bind(function () {
1014
-
1015
- var enabled, readonly, self = this;
1016
-
1017
- // sync enabled state
1018
- var disabled = el.prop("disabled");
1019
- if (disabled === undefined) disabled = false;
1020
- this.enable(!disabled);
1021
-
1022
- var readonly = el.prop("readonly");
1023
- if (readonly === undefined) readonly = false;
1024
- this.readonly(readonly);
1025
-
1026
- syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
1027
- this.container.addClass(evaluate(this.opts.containerCssClass));
1028
-
1029
- syncCssClasses(this.dropdown, this.opts.element, this.opts.adaptDropdownCssClass);
1030
- this.dropdown.addClass(evaluate(this.opts.dropdownCssClass));
1031
-
1032
- });
1033
-
1034
- // mozilla and IE
1035
- el.on("propertychange.select2 DOMAttrModified.select2", sync);
1036
-
1037
-
1038
- // hold onto a reference of the callback to work around a chromium bug
1039
- if (this.mutationCallback === undefined) {
1040
- this.mutationCallback = function (mutations) {
1041
- mutations.forEach(sync);
1042
- }
1043
- }
1044
-
1045
- // safari and chrome
1046
- if (typeof WebKitMutationObserver !== "undefined") {
1047
- if (this.propertyObserver) { delete this.propertyObserver; this.propertyObserver = null; }
1048
- this.propertyObserver = new WebKitMutationObserver(this.mutationCallback);
1049
- this.propertyObserver.observe(el.get(0), { attributes:true, subtree:false });
1050
- }
1051
- },
1052
-
1053
- // abstract
1054
- triggerSelect: function(data) {
1055
- var evt = $.Event("select2-selecting", { val: this.id(data), object: data });
1056
- this.opts.element.trigger(evt);
1057
- return !evt.isDefaultPrevented();
1058
- },
1059
-
1060
- /**
1061
- * Triggers the change event on the source element
1062
- */
1063
- // abstract
1064
- triggerChange: function (details) {
1065
-
1066
- details = details || {};
1067
- details= $.extend({}, details, { type: "change", val: this.val() });
1068
- // prevents recursive triggering
1069
- this.opts.element.data("select2-change-triggered", true);
1070
- this.opts.element.trigger(details);
1071
- this.opts.element.data("select2-change-triggered", false);
1072
-
1073
- // some validation frameworks ignore the change event and listen instead to keyup, click for selects
1074
- // so here we trigger the click event manually
1075
- this.opts.element.click();
1076
-
1077
- // ValidationEngine ignorea the change event and listens instead to blur
1078
- // so here we trigger the blur event manually if so desired
1079
- if (this.opts.blurOnChange)
1080
- this.opts.element.blur();
1081
- },
1082
-
1083
- //abstract
1084
- isInterfaceEnabled: function()
1085
- {
1086
- return this.enabledInterface === true;
1087
- },
1088
-
1089
- // abstract
1090
- enableInterface: function() {
1091
- var enabled = this._enabled && !this._readonly,
1092
- disabled = !enabled;
1093
-
1094
- if (enabled === this.enabledInterface) return false;
1095
-
1096
- this.container.toggleClass("select2-container-disabled", disabled);
1097
- this.close();
1098
- this.enabledInterface = enabled;
1099
-
1100
- return true;
1101
- },
1102
-
1103
- // abstract
1104
- enable: function(enabled) {
1105
- if (enabled === undefined) enabled = true;
1106
- if (this._enabled === enabled) return;
1107
- this._enabled = enabled;
1108
-
1109
- this.opts.element.prop("disabled", !enabled);
1110
- this.enableInterface();
1111
- },
1112
-
1113
- // abstract
1114
- disable: function() {
1115
- this.enable(false);
1116
- },
1117
-
1118
- // abstract
1119
- readonly: function(enabled) {
1120
- if (enabled === undefined) enabled = false;
1121
- if (this._readonly === enabled) return false;
1122
- this._readonly = enabled;
1123
-
1124
- this.opts.element.prop("readonly", enabled);
1125
- this.enableInterface();
1126
- return true;
1127
- },
1128
-
1129
- // abstract
1130
- opened: function () {
1131
- return this.container.hasClass("select2-dropdown-open");
1132
- },
1133
-
1134
- // abstract
1135
- positionDropdown: function() {
1136
- var $dropdown = this.dropdown,
1137
- offset = this.container.offset(),
1138
- height = this.container.outerHeight(false),
1139
- width = this.container.outerWidth(false),
1140
- dropHeight = $dropdown.outerHeight(false),
1141
- viewPortRight = $(window).scrollLeft() + $(window).width(),
1142
- viewportBottom = $(window).scrollTop() + $(window).height(),
1143
- dropTop = offset.top + height,
1144
- dropLeft = offset.left,
1145
- enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
1146
- enoughRoomAbove = (offset.top - dropHeight) >= this.body().scrollTop(),
1147
- dropWidth = $dropdown.outerWidth(false),
1148
- enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight,
1149
- aboveNow = $dropdown.hasClass("select2-drop-above"),
1150
- bodyOffset,
1151
- above,
1152
- css,
1153
- resultsListNode;
1154
-
1155
- if (this.opts.dropdownAutoWidth) {
1156
- resultsListNode = $('.select2-results', $dropdown)[0];
1157
- $dropdown.addClass('select2-drop-auto-width');
1158
- $dropdown.css('width', '');
1159
- // Add scrollbar width to dropdown if vertical scrollbar is present
1160
- dropWidth = $dropdown.outerWidth(false) + (resultsListNode.scrollHeight === resultsListNode.clientHeight ? 0 : scrollBarDimensions.width);
1161
- dropWidth > width ? width = dropWidth : dropWidth = width;
1162
- enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight;
1163
- }
1164
- else {
1165
- this.container.removeClass('select2-drop-auto-width');
1166
- }
1167
-
1168
- //console.log("below/ droptop:", dropTop, "dropHeight", dropHeight, "sum", (dropTop+dropHeight)+" viewport bottom", viewportBottom, "enough?", enoughRoomBelow);
1169
- //console.log("above/ offset.top", offset.top, "dropHeight", dropHeight, "top", (offset.top-dropHeight), "scrollTop", this.body().scrollTop(), "enough?", enoughRoomAbove);
1170
-
1171
- // fix positioning when body has an offset and is not position: static
1172
- if (this.body().css('position') !== 'static') {
1173
- bodyOffset = this.body().offset();
1174
- dropTop -= bodyOffset.top;
1175
- dropLeft -= bodyOffset.left;
1176
- }
1177
-
1178
- // always prefer the current above/below alignment, unless there is not enough room
1179
- if (aboveNow) {
1180
- above = true;
1181
- if (!enoughRoomAbove && enoughRoomBelow) above = false;
1182
- } else {
1183
- above = false;
1184
- if (!enoughRoomBelow && enoughRoomAbove) above = true;
1185
- }
1186
-
1187
- if (!enoughRoomOnRight) {
1188
- dropLeft = offset.left + width - dropWidth;
1189
- }
1190
-
1191
- if (above) {
1192
- dropTop = offset.top - dropHeight;
1193
- this.container.addClass("select2-drop-above");
1194
- $dropdown.addClass("select2-drop-above");
1195
- }
1196
- else {
1197
- this.container.removeClass("select2-drop-above");
1198
- $dropdown.removeClass("select2-drop-above");
1199
- }
1200
-
1201
- css = $.extend({
1202
- top: dropTop,
1203
- left: dropLeft,
1204
- width: width
1205
- }, evaluate(this.opts.dropdownCss));
1206
-
1207
- $dropdown.css(css);
1208
- },
1209
-
1210
- // abstract
1211
- shouldOpen: function() {
1212
- var event;
1213
-
1214
- if (this.opened()) return false;
1215
-
1216
- if (this._enabled === false || this._readonly === true) return false;
1217
-
1218
- event = $.Event("select2-opening");
1219
- this.opts.element.trigger(event);
1220
- return !event.isDefaultPrevented();
1221
- },
1222
-
1223
- // abstract
1224
- clearDropdownAlignmentPreference: function() {
1225
- // clear the classes used to figure out the preference of where the dropdown should be opened
1226
- this.container.removeClass("select2-drop-above");
1227
- this.dropdown.removeClass("select2-drop-above");
1228
- },
1229
-
1230
- /**
1231
- * Opens the dropdown
1232
- *
1233
- * @return {Boolean} whether or not dropdown was opened. This method will return false if, for example,
1234
- * the dropdown is already open, or if the 'open' event listener on the element called preventDefault().
1235
- */
1236
- // abstract
1237
- open: function () {
1238
-
1239
- if (!this.shouldOpen()) return false;
1240
-
1241
- this.opening();
1242
-
1243
- return true;
1244
- },
1245
-
1246
- /**
1247
- * Performs the opening of the dropdown
1248
- */
1249
- // abstract
1250
- opening: function() {
1251
- var cid = this.containerId,
1252
- scroll = "scroll." + cid,
1253
- resize = "resize."+cid,
1254
- orient = "orientationchange."+cid,
1255
- mask, maskCss;
1256
-
1257
- this.container.addClass("select2-dropdown-open").addClass("select2-container-active");
1258
-
1259
- this.clearDropdownAlignmentPreference();
1260
-
1261
- if(this.dropdown[0] !== this.body().children().last()[0]) {
1262
- this.dropdown.detach().appendTo(this.body());
1263
- }
1264
-
1265
- // create the dropdown mask if doesnt already exist
1266
- mask = $("#select2-drop-mask");
1267
- if (mask.length == 0) {
1268
- mask = $(document.createElement("div"));
1269
- mask.attr("id","select2-drop-mask").attr("class","select2-drop-mask");
1270
- mask.hide();
1271
- mask.appendTo(this.body());
1272
- mask.on("mousedown touchstart click", function (e) {
1273
- var dropdown = $("#select2-drop"), self;
1274
- if (dropdown.length > 0) {
1275
- self=dropdown.data("select2");
1276
- if (self.opts.selectOnBlur) {
1277
- self.selectHighlighted({noFocus: true});
1278
- }
1279
- self.close({focus:false});
1280
- e.preventDefault();
1281
- e.stopPropagation();
1282
- }
1283
- });
1284
- }
1285
-
1286
- // ensure the mask is always right before the dropdown
1287
- if (this.dropdown.prev()[0] !== mask[0]) {
1288
- this.dropdown.before(mask);
1289
- }
1290
-
1291
- // move the global id to the correct dropdown
1292
- $("#select2-drop").removeAttr("id");
1293
- this.dropdown.attr("id", "select2-drop");
1294
-
1295
- // show the elements
1296
- mask.show();
1297
-
1298
- this.positionDropdown();
1299
- this.dropdown.show();
1300
-
1301
- // MODIFIED: added following two lines for footer
1302
- this.dropdown.find('.select2-footer').remove();
1303
- if (this.opts.footer) this.opts.footer(this);
1304
-
1305
- this.positionDropdown();
1306
-
1307
- this.dropdown.addClass("select2-drop-active");
1308
-
1309
- // attach listeners to events that can change the position of the container and thus require
1310
- // the position of the dropdown to be updated as well so it does not come unglued from the container
1311
- var that = this;
1312
- this.container.parents().add(window).each(function () {
1313
- $(this).on(resize+" "+scroll+" "+orient, function (e) {
1314
- that.positionDropdown();
1315
- });
1316
- });
1317
-
1318
-
1319
- },
1320
-
1321
- // abstract
1322
- close: function () {
1323
- if (!this.opened()) return;
1324
-
1325
- var cid = this.containerId,
1326
- scroll = "scroll." + cid,
1327
- resize = "resize."+cid,
1328
- orient = "orientationchange."+cid;
1329
-
1330
- // unbind event listeners
1331
- this.container.parents().add(window).each(function () { $(this).off(scroll).off(resize).off(orient); });
1332
-
1333
- this.clearDropdownAlignmentPreference();
1334
-
1335
- $("#select2-drop-mask").hide();
1336
- this.dropdown.removeAttr("id"); // only the active dropdown has the select2-drop id
1337
- this.dropdown.hide();
1338
- this.container.removeClass("select2-dropdown-open").removeClass("select2-container-active");
1339
- this.results.empty();
1340
-
1341
-
1342
- this.clearSearch();
1343
- this.search.removeClass("select2-active");
1344
- this.opts.element.trigger($.Event("select2-close"));
1345
- },
1346
-
1347
- /**
1348
- * Opens control, sets input value, and updates results.
1349
- */
1350
- // abstract
1351
- externalSearch: function (term) {
1352
- this.open();
1353
- this.search.val(term);
1354
- this.updateResults(false);
1355
- },
1356
-
1357
- // abstract
1358
- clearSearch: function () {
1359
-
1360
- },
1361
-
1362
- //abstract
1363
- getMaximumSelectionSize: function() {
1364
- return evaluate(this.opts.maximumSelectionSize);
1365
- },
1366
-
1367
- // abstract
1368
- ensureHighlightVisible: function () {
1369
- var results = this.results, children, index, child, hb, rb, y, more;
1370
-
1371
- index = this.highlight();
1372
-
1373
- if (index < 0) return;
1374
-
1375
- if (index == 0) {
1376
-
1377
- // if the first element is highlighted scroll all the way to the top,
1378
- // that way any unselectable headers above it will also be scrolled
1379
- // into view
1380
-
1381
- results.scrollTop(0);
1382
- return;
1383
- }
1384
-
1385
- children = this.findHighlightableChoices().find('.select2-result-label');
1386
-
1387
- child = $(children[index]);
1388
-
1389
- hb = child.offset().top + child.outerHeight(true);
1390
-
1391
- // if this is the last child lets also make sure select2-more-results is visible
1392
- if (index === children.length - 1) {
1393
- more = results.find("li.select2-more-results");
1394
- if (more.length > 0) {
1395
- hb = more.offset().top + more.outerHeight(true);
1396
- }
1397
- }
1398
-
1399
- rb = results.offset().top + results.outerHeight(true);
1400
- if (hb > rb) {
1401
- results.scrollTop(results.scrollTop() + (hb - rb));
1402
- }
1403
- y = child.offset().top - results.offset().top;
1404
-
1405
- // make sure the top of the element is visible
1406
- if (y < 0 && child.css('display') != 'none' ) {
1407
- results.scrollTop(results.scrollTop() + y); // y is negative
1408
- }
1409
- },
1410
-
1411
- // abstract
1412
- findHighlightableChoices: function() {
1413
- return this.results.find(".select2-result-selectable:not(.select2-disabled)");
1414
- },
1415
-
1416
- // abstract
1417
- moveHighlight: function (delta) {
1418
- var choices = this.findHighlightableChoices(),
1419
- index = this.highlight();
1420
-
1421
- while (index > -1 && index < choices.length) {
1422
- index += delta;
1423
- var choice = $(choices[index]);
1424
- if (choice.hasClass("select2-result-selectable") && !choice.hasClass("select2-disabled") && !choice.hasClass("select2-selected")) {
1425
- this.highlight(index);
1426
- break;
1427
- }
1428
- }
1429
- },
1430
-
1431
- // abstract
1432
- highlight: function (index) {
1433
- var choices = this.findHighlightableChoices(),
1434
- choice,
1435
- data;
1436
-
1437
- if (arguments.length === 0) {
1438
- return indexOf(choices.filter(".select2-highlighted")[0], choices.get());
1439
- }
1440
-
1441
- if (index >= choices.length) index = choices.length - 1;
1442
- if (index < 0) index = 0;
1443
-
1444
- this.removeHighlight();
1445
-
1446
- choice = $(choices[index]);
1447
- choice.addClass("select2-highlighted");
1448
-
1449
- this.ensureHighlightVisible();
1450
-
1451
- data = choice.data("select2-data");
1452
- if (data) {
1453
- this.opts.element.trigger({ type: "select2-highlight", val: this.id(data), choice: data });
1454
- }
1455
- },
1456
-
1457
- removeHighlight: function() {
1458
- this.results.find(".select2-highlighted").removeClass("select2-highlighted");
1459
- },
1460
-
1461
- // abstract
1462
- countSelectableResults: function() {
1463
- return this.findHighlightableChoices().length;
1464
- },
1465
-
1466
- // abstract
1467
- highlightUnderEvent: function (event) {
1468
- var el = $(event.target).closest(".select2-result-selectable");
1469
- if (el.length > 0 && !el.is(".select2-highlighted")) {
1470
- var choices = this.findHighlightableChoices();
1471
- this.highlight(choices.index(el));
1472
- } else if (el.length == 0) {
1473
- // if we are over an unselectable item remove all highlights
1474
- this.removeHighlight();
1475
- }
1476
- },
1477
-
1478
- // abstract
1479
- loadMoreIfNeeded: function () {
1480
- var results = this.results,
1481
- more = results.find("li.select2-more-results"),
1482
- below, // pixels the element is below the scroll fold, below==0 is when the element is starting to be visible
1483
- offset = -1, // index of first element without data
1484
- page = this.resultsPage + 1,
1485
- self=this,
1486
- term=this.search.val(),
1487
- context=this.context;
1488
-
1489
- if (more.length === 0) return;
1490
- below = more.offset().top - results.offset().top - results.height();
1491
-
1492
- if (below <= this.opts.loadMorePadding) {
1493
- more.addClass("select2-active");
1494
- this.opts.query({
1495
- element: this.opts.element,
1496
- term: term,
1497
- page: page,
1498
- context: context,
1499
- matcher: this.opts.matcher,
1500
- callback: this.bind(function (data) {
1501
-
1502
- // ignore a response if the select2 has been closed before it was received
1503
- if (!self.opened()) return;
1504
-
1505
-
1506
- self.opts.populateResults.call(this, results, data.results, {term: term, page: page, context:context});
1507
- self.postprocessResults(data, false, false);
1508
-
1509
- if (data.more===true) {
1510
- more.detach().appendTo(results).text(self.opts.formatLoadMore(page+1));
1511
- window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
1512
- } else {
1513
- more.remove();
1514
- }
1515
- self.positionDropdown();
1516
- self.resultsPage = page;
1517
- self.context = data.context;
1518
- this.opts.element.trigger({ type: "select2-loaded", items: data });
1519
- })});
1520
- }
1521
- },
1522
-
1523
- /**
1524
- * Default tokenizer function which does nothing
1525
- */
1526
- tokenize: function() {
1527
-
1528
- },
1529
-
1530
- /**
1531
- * @param initial whether or not this is the call to this method right after the dropdown has been opened
1532
- */
1533
- // abstract
1534
- updateResults: function (initial) {
1535
- var search = this.search,
1536
- results = this.results,
1537
- opts = this.opts,
1538
- data,
1539
- self = this,
1540
- input,
1541
- term = search.val(),
1542
- lastTerm = $.data(this.container, "select2-last-term"),
1543
- // sequence number used to drop out-of-order responses
1544
- queryNumber;
1545
-
1546
- // prevent duplicate queries against the same term
1547
- if (initial !== true && lastTerm && equal(term, lastTerm)) return;
1548
-
1549
- $.data(this.container, "select2-last-term", term);
1550
-
1551
- // if the search is currently hidden we do not alter the results
1552
- if (initial !== true && (this.showSearchInput === false || !this.opened())) {
1553
- return;
1554
- }
1555
-
1556
- function postRender() {
1557
- search.removeClass("select2-active");
1558
- self.positionDropdown();
1559
- }
1560
-
1561
- function render(html) {
1562
- results.html(html);
1563
- postRender();
1564
- }
1565
-
1566
- queryNumber = ++this.queryCount;
1567
-
1568
- var maxSelSize = this.getMaximumSelectionSize();
1569
- if (maxSelSize >=1) {
1570
- data = this.data();
1571
- if ($.isArray(data) && data.length >= maxSelSize && checkFormatter(opts.formatSelectionTooBig, "formatSelectionTooBig")) {
1572
- render("<li class='select2-selection-limit'>" + opts.formatSelectionTooBig(maxSelSize) + "</li>");
1573
- return;
1574
- }
1575
- }
1576
-
1577
- if (search.val().length < opts.minimumInputLength) {
1578
- if (checkFormatter(opts.formatInputTooShort, "formatInputTooShort")) {
1579
- render("<li class='select2-no-results'>" + opts.formatInputTooShort(search.val(), opts.minimumInputLength) + "</li>");
1580
- } else {
1581
- render("");
1582
- }
1583
- if (initial && this.showSearch) this.showSearch(true);
1584
- return;
1585
- }
1586
-
1587
- if (opts.maximumInputLength && search.val().length > opts.maximumInputLength) {
1588
- if (checkFormatter(opts.formatInputTooLong, "formatInputTooLong")) {
1589
- render("<li class='select2-no-results'>" + opts.formatInputTooLong(search.val(), opts.maximumInputLength) + "</li>");
1590
- } else {
1591
- render("");
1592
- }
1593
- return;
1594
- }
1595
-
1596
- if (opts.formatSearching && this.findHighlightableChoices().length === 0) {
1597
- render("<li class='select2-searching'>" + opts.formatSearching() + "</li>");
1598
- }
1599
-
1600
- search.addClass("select2-active");
1601
-
1602
- this.removeHighlight();
1603
-
1604
- // give the tokenizer a chance to pre-process the input
1605
- input = this.tokenize();
1606
- if (input != undefined && input != null) {
1607
- search.val(input);
1608
- }
1609
-
1610
- this.resultsPage = 1;
1611
-
1612
- opts.query({
1613
- element: opts.element,
1614
- term: search.val(),
1615
- page: this.resultsPage,
1616
- context: null,
1617
- matcher: opts.matcher,
1618
- callback: this.bind(function (data) {
1619
- var def; // default choice
1620
-
1621
- // ignore old responses
1622
- if (queryNumber != this.queryCount) {
1623
- return;
1624
- }
1625
-
1626
- // ignore a response if the select2 has been closed before it was received
1627
- if (!this.opened()) {
1628
- this.search.removeClass("select2-active");
1629
- return;
1630
- }
1631
-
1632
- // save context, if any
1633
- this.context = (data.context===undefined) ? null : data.context;
1634
- // create a default choice and prepend it to the list
1635
- if (this.opts.createSearchChoice && search.val() !== "") {
1636
- def = this.opts.createSearchChoice.call(self, search.val(), data.results);
1637
- if (def !== undefined && def !== null && self.id(def) !== undefined && self.id(def) !== null) {
1638
- if ($(data.results).filter(
1639
- function () {
1640
- return equal(self.id(this), self.id(def));
1641
- }).length === 0) {
1642
- data.results.unshift(def);
1643
- }
1644
- }
1645
- }
1646
-
1647
- if (data.results.length === 0 && checkFormatter(opts.formatNoMatches, "formatNoMatches")) {
1648
- render("<li class='select2-no-results'>" + opts.formatNoMatches(search.val()) + "</li>");
1649
- return;
1650
- }
1651
-
1652
- results.empty();
1653
- self.opts.populateResults.call(this, results, data.results, {term: search.val(), page: this.resultsPage, context:null});
1654
-
1655
- if (data.more === true && checkFormatter(opts.formatLoadMore, "formatLoadMore")) {
1656
- results.append("<li class='select2-more-results'>" + self.opts.escapeMarkup(opts.formatLoadMore(this.resultsPage)) + "</li>");
1657
- window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
1658
- }
1659
-
1660
- this.postprocessResults(data, initial);
1661
-
1662
- postRender();
1663
-
1664
- this.opts.element.trigger({ type: "select2-loaded", items: data });
1665
- })});
1666
- },
1667
-
1668
- // abstract
1669
- cancel: function () {
1670
- this.close();
1671
- },
1672
-
1673
- // abstract
1674
- blur: function () {
1675
- // if selectOnBlur == true, select the currently highlighted option
1676
- if (this.opts.selectOnBlur)
1677
- this.selectHighlighted({noFocus: true});
1678
-
1679
- this.close();
1680
- this.container.removeClass("select2-container-active");
1681
- // synonymous to .is(':focus'), which is available in jquery >= 1.6
1682
- if (this.search[0] === document.activeElement) { this.search.blur(); }
1683
- this.clearSearch();
1684
- this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
1685
- },
1686
-
1687
- // abstract
1688
- focusSearch: function () {
1689
- focus(this.search);
1690
- },
1691
-
1692
- // abstract
1693
- selectHighlighted: function (options) {
1694
- var index=this.highlight(),
1695
- highlighted=this.results.find(".select2-highlighted"),
1696
- data = highlighted.closest('.select2-result').data("select2-data");
1697
-
1698
- if (data) {
1699
- this.highlight(index);
1700
- this.onSelect(data, options);
1701
- } else if (options && options.noFocus) {
1702
- this.close();
1703
- }
1704
- },
1705
-
1706
- // abstract
1707
- getPlaceholder: function () {
1708
- var placeholderOption;
1709
- return this.opts.element.attr("placeholder") ||
1710
- this.opts.element.attr("data-placeholder") || // jquery 1.4 compat
1711
- this.opts.element.data("placeholder") ||
1712
- this.opts.placeholder ||
1713
- ((placeholderOption = this.getPlaceholderOption()) !== undefined ? placeholderOption.text() : undefined);
1714
- },
1715
-
1716
- // abstract
1717
- getPlaceholderOption: function() {
1718
- if (this.select) {
1719
- var firstOption = this.select.children().first();
1720
- if (this.opts.placeholderOption !== undefined ) {
1721
- //Determine the placeholder option based on the specified placeholderOption setting
1722
- return (this.opts.placeholderOption === "first" && firstOption) ||
1723
- (typeof this.opts.placeholderOption === "function" && this.opts.placeholderOption(this.select));
1724
- } else if (firstOption.text() === "" && firstOption.val() === "") {
1725
- //No explicit placeholder option specified, use the first if it's blank
1726
- return firstOption;
1727
- }
1728
- }
1729
- },
1730
-
1731
- /**
1732
- * Get the desired width for the container element. This is
1733
- * derived first from option `width` passed to select2, then
1734
- * the inline 'style' on the original element, and finally
1735
- * falls back to the jQuery calculated element width.
1736
- */
1737
- // abstract
1738
- initContainerWidth: function () {
1739
- function resolveContainerWidth() {
1740
- var style, attrs, matches, i, l;
1741
-
1742
- if (this.opts.width === "off") {
1743
- return null;
1744
- } else if (this.opts.width === "element"){
1745
- return this.opts.element.outerWidth(false) === 0 ? 'auto' : this.opts.element.outerWidth(false) + 'px';
1746
- } else if (this.opts.width === "copy" || this.opts.width === "resolve") {
1747
- // check if there is inline style on the element that contains width
1748
- style = this.opts.element.attr('style');
1749
- if (style !== undefined) {
1750
- attrs = style.split(';');
1751
- for (i = 0, l = attrs.length; i < l; i = i + 1) {
1752
- matches = attrs[i].replace(/\s/g, '')
1753
- .match(/[^-]width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i);
1754
- if (matches !== null && matches.length >= 1)
1755
- return matches[1];
1756
- }
1757
- }
1758
-
1759
- if (this.opts.width === "resolve") {
1760
- // next check if css('width') can resolve a width that is percent based, this is sometimes possible
1761
- // when attached to input type=hidden or elements hidden via css
1762
- style = this.opts.element.css('width');
1763
- if (style.indexOf("%") > 0) return style;
1764
-
1765
- // finally, fallback on the calculated width of the element
1766
- return (this.opts.element.outerWidth(false) === 0 ? 'auto' : this.opts.element.outerWidth(false) + 'px');
1767
- }
1768
-
1769
- return null;
1770
- } else if ($.isFunction(this.opts.width)) {
1771
- return this.opts.width();
1772
- } else {
1773
- return this.opts.width;
1774
- }
1775
- };
1776
-
1777
- var width = resolveContainerWidth.call(this);
1778
- if (width !== null) {
1779
- this.container.css("width", width);
1780
- }
1781
- }
1782
- });
1783
-
1784
- SingleSelect2 = clazz(AbstractSelect2, {
1785
-
1786
- // single
1787
-
1788
- createContainer: function () {
1789
- var container = $(document.createElement("div")).attr({
1790
- "class": "select2-container"
1791
- }).html([
1792
- "<a href='javascript:void(0)' onclick='return false;' class='select2-choice' tabindex='-1'>",
1793
- " <span class='select2-chosen'>&nbsp;</span><abbr class='select2-search-choice-close'></abbr>",
1794
- " <span class='select2-arrow'><b></b></span>",
1795
- "</a>",
1796
- "<input class='select2-focusser select2-offscreen' type='text'/>",
1797
- "<div class='select2-drop select2-display-none'>",
1798
- " <div class='select2-search'>",
1799
- " <input type='text' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' class='select2-input'/>",
1800
- " </div>",
1801
- " <ul class='select2-results'>",
1802
- " </ul>",
1803
- "</div>"].join(""));
1804
- return container;
1805
- },
1806
-
1807
- // single
1808
- enableInterface: function() {
1809
- if (this.parent.enableInterface.apply(this, arguments)) {
1810
- this.focusser.prop("disabled", !this.isInterfaceEnabled());
1811
- }
1812
- },
1813
-
1814
- // single
1815
- opening: function () {
1816
- var el, range, len;
1817
-
1818
- if (this.opts.minimumResultsForSearch >= 0) {
1819
- this.showSearch(true);
1820
- }
1821
-
1822
- this.parent.opening.apply(this, arguments);
1823
-
1824
- if (this.showSearchInput !== false) {
1825
- // IE appends focusser.val() at the end of field :/ so we manually insert it at the beginning using a range
1826
- // all other browsers handle this just fine
1827
-
1828
- this.search.val(this.focusser.val());
1829
- }
1830
- this.search.focus();
1831
- // move the cursor to the end after focussing, otherwise it will be at the beginning and
1832
- // new text will appear *before* focusser.val()
1833
- el = this.search.get(0);
1834
- if (el.createTextRange) {
1835
- range = el.createTextRange();
1836
- range.collapse(false);
1837
- range.select();
1838
- } else if (el.setSelectionRange) {
1839
- len = this.search.val().length;
1840
- el.setSelectionRange(len, len);
1841
- }
1842
-
1843
- // initializes search's value with nextSearchTerm (if defined by user)
1844
- // ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
1845
- if(this.search.val() === "") {
1846
- if(this.nextSearchTerm != undefined){
1847
- this.search.val(this.nextSearchTerm);
1848
- this.search.select();
1849
- }
1850
- }
1851
-
1852
- this.focusser.prop("disabled", true).val("");
1853
- this.updateResults(true);
1854
- this.opts.element.trigger($.Event("select2-open"));
1855
- },
1856
-
1857
- // single
1858
- close: function (params) {
1859
- if (!this.opened()) return;
1860
- this.parent.close.apply(this, arguments);
1861
-
1862
- params = params || {focus: true};
1863
- this.focusser.removeAttr("disabled");
1864
-
1865
- if (params.focus) {
1866
- this.focusser.focus();
1867
- }
1868
- },
1869
-
1870
- // single
1871
- focus: function () {
1872
- if (this.opened()) {
1873
- this.close();
1874
- } else {
1875
- this.focusser.removeAttr("disabled");
1876
- this.focusser.focus();
1877
- }
1878
- },
1879
-
1880
- // single
1881
- isFocused: function () {
1882
- return this.container.hasClass("select2-container-active");
1883
- },
1884
-
1885
- // single
1886
- cancel: function () {
1887
- this.parent.cancel.apply(this, arguments);
1888
- this.focusser.removeAttr("disabled");
1889
- this.focusser.focus();
1890
- },
1891
-
1892
- // single
1893
- destroy: function() {
1894
- $("label[for='" + this.focusser.attr('id') + "']")
1895
- .attr('for', this.opts.element.attr("id"));
1896
- this.parent.destroy.apply(this, arguments);
1897
- },
1898
-
1899
- // single
1900
- initContainer: function () {
1901
-
1902
- var selection,
1903
- container = this.container,
1904
- dropdown = this.dropdown;
1905
-
1906
- if (this.opts.minimumResultsForSearch < 0) {
1907
- this.showSearch(false);
1908
- } else {
1909
- this.showSearch(true);
1910
- }
1911
-
1912
- this.selection = selection = container.find(".select2-choice");
1913
-
1914
- this.focusser = container.find(".select2-focusser");
1915
-
1916
- // rewrite labels from original element to focusser
1917
- this.focusser.attr("id", "s2id_autogen"+nextUid());
1918
-
1919
- $("label[for='" + this.opts.element.attr("id") + "']")
1920
- .attr('for', this.focusser.attr('id'));
1921
-
1922
- this.focusser.attr("tabindex", this.elementTabIndex);
1923
-
1924
- this.search.on("keydown", this.bind(function (e) {
1925
- if (!this.isInterfaceEnabled()) return;
1926
-
1927
- if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
1928
- // prevent the page from scrolling
1929
- killEvent(e);
1930
- return;
1931
- }
1932
-
1933
- switch (e.which) {
1934
- case KEY.UP:
1935
- case KEY.DOWN:
1936
- this.moveHighlight((e.which === KEY.UP) ? -1 : 1);
1937
- killEvent(e);
1938
- return;
1939
- case KEY.ENTER:
1940
- this.selectHighlighted();
1941
- killEvent(e);
1942
- return;
1943
- case KEY.TAB:
1944
- this.selectHighlighted({noFocus: true});
1945
- return;
1946
- case KEY.ESC:
1947
- this.cancel(e);
1948
- killEvent(e);
1949
- return;
1950
- }
1951
- }));
1952
-
1953
- this.search.on("blur", this.bind(function(e) {
1954
- // a workaround for chrome to keep the search field focussed when the scroll bar is used to scroll the dropdown.
1955
- // without this the search field loses focus which is annoying
1956
- if (document.activeElement === this.body().get(0)) {
1957
- window.setTimeout(this.bind(function() {
1958
- this.search.focus();
1959
- }), 0);
1960
- }
1961
- }));
1962
-
1963
- this.focusser.on("keydown", this.bind(function (e) {
1964
- if (!this.isInterfaceEnabled()) return;
1965
-
1966
- if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) {
1967
- return;
1968
- }
1969
-
1970
- if (this.opts.openOnEnter === false && e.which === KEY.ENTER) {
1971
- killEvent(e);
1972
- return;
1973
- }
1974
-
1975
- if (e.which == KEY.DOWN || e.which == KEY.UP
1976
- || (e.which == KEY.ENTER && this.opts.openOnEnter)) {
1977
-
1978
- if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) return;
1979
-
1980
- this.open();
1981
- killEvent(e);
1982
- return;
1983
- }
1984
-
1985
- if (e.which == KEY.DELETE || e.which == KEY.BACKSPACE) {
1986
- if (this.opts.allowClear) {
1987
- this.clear();
1988
- }
1989
- killEvent(e);
1990
- return;
1991
- }
1992
- }));
1993
-
1994
-
1995
- installKeyUpChangeEvent(this.focusser);
1996
- this.focusser.on("keyup-change input", this.bind(function(e) {
1997
- if (this.opts.minimumResultsForSearch >= 0) {
1998
- e.stopPropagation();
1999
- if (this.opened()) return;
2000
- this.open();
2001
- }
2002
- }));
2003
-
2004
- selection.on("mousedown", "abbr", this.bind(function (e) {
2005
- if (!this.isInterfaceEnabled()) return;
2006
- this.clear();
2007
- killEventImmediately(e);
2008
- this.close();
2009
- this.selection.focus();
2010
- }));
2011
-
2012
- selection.on("mousedown", this.bind(function (e) {
2013
-
2014
- if (!this.container.hasClass("select2-container-active")) {
2015
- this.opts.element.trigger($.Event("select2-focus"));
2016
- }
2017
-
2018
- if (this.opened()) {
2019
- this.close();
2020
- } else if (this.isInterfaceEnabled()) {
2021
- this.open();
2022
- }
2023
-
2024
- killEvent(e);
2025
- }));
2026
-
2027
- dropdown.on("mousedown", this.bind(function() { this.search.focus(); }));
2028
-
2029
- selection.on("focus", this.bind(function(e) {
2030
- killEvent(e);
2031
- }));
2032
-
2033
- this.focusser.on("focus", this.bind(function(){
2034
- if (!this.container.hasClass("select2-container-active")) {
2035
- this.opts.element.trigger($.Event("select2-focus"));
2036
- }
2037
- this.container.addClass("select2-container-active");
2038
- })).on("blur", this.bind(function() {
2039
- if (!this.opened()) {
2040
- this.container.removeClass("select2-container-active");
2041
- this.opts.element.trigger($.Event("select2-blur"));
2042
- }
2043
- }));
2044
- this.search.on("focus", this.bind(function(){
2045
- if (!this.container.hasClass("select2-container-active")) {
2046
- this.opts.element.trigger($.Event("select2-focus"));
2047
- }
2048
- this.container.addClass("select2-container-active");
2049
- }));
2050
-
2051
- this.initContainerWidth();
2052
- this.opts.element.addClass("select2-offscreen");
2053
- this.setPlaceholder();
2054
-
2055
- },
2056
-
2057
- // single
2058
- clear: function(triggerChange) {
2059
- var data=this.selection.data("select2-data");
2060
- if (data) { // guard against queued quick consecutive clicks
2061
- var evt = $.Event("select2-clearing");
2062
- this.opts.element.trigger(evt);
2063
- if (evt.isDefaultPrevented()) {
2064
- return;
2065
- }
2066
- var placeholderOption = this.getPlaceholderOption();
2067
- this.opts.element.val(placeholderOption ? placeholderOption.val() : "");
2068
- this.selection.find(".select2-chosen").empty();
2069
- this.selection.removeData("select2-data");
2070
- this.setPlaceholder();
2071
-
2072
- if (triggerChange !== false){
2073
- this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data });
2074
- this.triggerChange({removed:data});
2075
- }
2076
- }
2077
- },
2078
-
2079
- /**
2080
- * Sets selection based on source element's value
2081
- */
2082
- // single
2083
- initSelection: function () {
2084
- var selected;
2085
- if (this.isPlaceholderOptionSelected()) {
2086
- this.updateSelection(null);
2087
- this.close();
2088
- this.setPlaceholder();
2089
- } else {
2090
- var self = this;
2091
- this.opts.initSelection.call(null, this.opts.element, function(selected){
2092
- if (selected !== undefined && selected !== null) {
2093
- self.updateSelection(selected);
2094
- self.close();
2095
- self.setPlaceholder();
2096
- }
2097
- });
2098
- }
2099
- },
2100
-
2101
- isPlaceholderOptionSelected: function() {
2102
- var placeholderOption;
2103
- if (!this.getPlaceholder()) return false; // no placeholder specified so no option should be considered
2104
- return ((placeholderOption = this.getPlaceholderOption()) !== undefined && placeholderOption.is(':selected'))
2105
- || (this.opts.element.val() === "")
2106
- || (this.opts.element.val() === undefined)
2107
- || (this.opts.element.val() === null);
2108
- },
2109
-
2110
- // single
2111
- prepareOpts: function () {
2112
- var opts = this.parent.prepareOpts.apply(this, arguments),
2113
- self=this;
2114
-
2115
- if (opts.element.get(0).tagName.toLowerCase() === "select") {
2116
- // install the selection initializer
2117
- opts.initSelection = function (element, callback) {
2118
- var selected = element.find(":selected");
2119
- // a single select box always has a value, no need to null check 'selected'
2120
- callback(self.optionToData(selected));
2121
- };
2122
- } else if ("data" in opts) {
2123
- // install default initSelection when applied to hidden input and data is local
2124
- opts.initSelection = opts.initSelection || function (element, callback) {
2125
- var id = element.val();
2126
- //search in data by id, storing the actual matching item
2127
- var match = null;
2128
- opts.query({
2129
- matcher: function(term, text, el){
2130
- var is_match = equal(id, opts.id(el));
2131
- if (is_match) {
2132
- match = el;
2133
- }
2134
- return is_match;
2135
- },
2136
- callback: !$.isFunction(callback) ? $.noop : function() {
2137
- callback(match);
2138
- }
2139
- });
2140
- };
2141
- }
2142
-
2143
- return opts;
2144
- },
2145
-
2146
- // single
2147
- getPlaceholder: function() {
2148
- // if a placeholder is specified on a single select without a valid placeholder option ignore it
2149
- if (this.select) {
2150
- if (this.getPlaceholderOption() === undefined) {
2151
- return undefined;
2152
- }
2153
- }
2154
-
2155
- return this.parent.getPlaceholder.apply(this, arguments);
2156
- },
2157
-
2158
- // single
2159
- setPlaceholder: function () {
2160
- var placeholder = this.getPlaceholder();
2161
-
2162
- if (this.isPlaceholderOptionSelected() && placeholder !== undefined) {
2163
-
2164
- // check for a placeholder option if attached to a select
2165
- if (this.select && this.getPlaceholderOption() === undefined) return;
2166
-
2167
- this.selection.find(".select2-chosen").html(this.opts.escapeMarkup(placeholder));
2168
-
2169
- this.selection.addClass("select2-default");
2170
-
2171
- this.container.removeClass("select2-allowclear");
2172
- }
2173
- },
2174
-
2175
- // single
2176
- postprocessResults: function (data, initial, noHighlightUpdate) {
2177
- var selected = 0, self = this, showSearchInput = true;
2178
-
2179
- // find the selected element in the result list
2180
-
2181
- this.findHighlightableChoices().each2(function (i, elm) {
2182
- if (equal(self.id(elm.data("select2-data")), self.opts.element.val())) {
2183
- selected = i;
2184
- return false;
2185
- }
2186
- });
2187
-
2188
- // and highlight it
2189
- if (noHighlightUpdate !== false) {
2190
- if (initial === true && selected >= 0) {
2191
- this.highlight(selected);
2192
- } else {
2193
- this.highlight(0);
2194
- }
2195
- }
2196
-
2197
- // hide the search box if this is the first we got the results and there are enough of them for search
2198
-
2199
- if (initial === true) {
2200
- var min = this.opts.minimumResultsForSearch;
2201
- if (min >= 0) {
2202
- this.showSearch(countResults(data.results) >= min);
2203
- }
2204
- }
2205
- },
2206
-
2207
- // single
2208
- showSearch: function(showSearchInput) {
2209
- if (this.showSearchInput === showSearchInput) return;
2210
-
2211
- this.showSearchInput = showSearchInput;
2212
-
2213
- this.dropdown.find(".select2-search").toggleClass("select2-search-hidden", !showSearchInput);
2214
- this.dropdown.find(".select2-search").toggleClass("select2-offscreen", !showSearchInput);
2215
- //add "select2-with-searchbox" to the container if search box is shown
2216
- $(this.dropdown, this.container).toggleClass("select2-with-searchbox", showSearchInput);
2217
- },
2218
-
2219
- // single
2220
- onSelect: function (data, options) {
2221
-
2222
- if (!this.triggerSelect(data)) { return; }
2223
-
2224
- var old = this.opts.element.val(),
2225
- oldData = this.data();
2226
-
2227
- this.opts.element.val(this.id(data));
2228
- this.updateSelection(data);
2229
-
2230
- this.opts.element.trigger({ type: "select2-selected", val: this.id(data), choice: data });
2231
-
2232
- this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
2233
- this.close();
2234
-
2235
- if (!options || !options.noFocus)
2236
- this.focusser.focus();
2237
-
2238
- if (!equal(old, this.id(data))) { this.triggerChange({added:data,removed:oldData}); }
2239
- },
2240
-
2241
- // single
2242
- updateSelection: function (data) {
2243
-
2244
- var container=this.selection.find(".select2-chosen"), formatted, cssClass;
2245
-
2246
- this.selection.data("select2-data", data);
2247
-
2248
- container.empty();
2249
- if (data !== null) {
2250
- formatted=this.opts.formatSelection(data, container, this.opts.escapeMarkup);
2251
- }
2252
- if (formatted !== undefined) {
2253
- container.append(formatted);
2254
- }
2255
- cssClass=this.opts.formatSelectionCssClass(data, container);
2256
- if (cssClass !== undefined) {
2257
- container.addClass(cssClass);
2258
- }
2259
-
2260
- this.selection.removeClass("select2-default");
2261
-
2262
- if (this.opts.allowClear && this.getPlaceholder() !== undefined) {
2263
- this.container.addClass("select2-allowclear");
2264
- }
2265
- },
2266
-
2267
- // single
2268
- val: function () {
2269
- var val,
2270
- triggerChange = false,
2271
- data = null,
2272
- self = this,
2273
- oldData = this.data();
2274
-
2275
- if (arguments.length === 0) {
2276
- return this.opts.element.val();
2277
- }
2278
-
2279
- val = arguments[0];
2280
-
2281
- if (arguments.length > 1) {
2282
- triggerChange = arguments[1];
2283
- }
2284
-
2285
- if (this.select) {
2286
- this.select
2287
- .val(val)
2288
- .find(":selected").each2(function (i, elm) {
2289
- data = self.optionToData(elm);
2290
- return false;
2291
- });
2292
- this.updateSelection(data);
2293
- this.setPlaceholder();
2294
- if (triggerChange) {
2295
- this.triggerChange({added: data, removed:oldData});
2296
- }
2297
- } else {
2298
- // val is an id. !val is true for [undefined,null,'',0] - 0 is legal
2299
- if (!val && val !== 0) {
2300
- this.clear(triggerChange);
2301
- return;
2302
- }
2303
- if (this.opts.initSelection === undefined) {
2304
- throw new Error("cannot call val() if initSelection() is not defined");
2305
- }
2306
- this.opts.element.val(val);
2307
- this.opts.initSelection(this.opts.element, function(data){
2308
- self.opts.element.val(!data ? "" : self.id(data));
2309
- self.updateSelection(data);
2310
- self.setPlaceholder();
2311
- if (triggerChange) {
2312
- self.triggerChange({added: data, removed:oldData});
2313
- }
2314
- });
2315
- }
2316
- },
2317
-
2318
- // single
2319
- clearSearch: function () {
2320
- this.search.val("");
2321
- this.focusser.val("");
2322
- },
2323
-
2324
- // single
2325
- data: function(value) {
2326
- var data,
2327
- triggerChange = false;
2328
-
2329
- if (arguments.length === 0) {
2330
- data = this.selection.data("select2-data");
2331
- if (data == undefined) data = null;
2332
- return data;
2333
- } else {
2334
- if (arguments.length > 1) {
2335
- triggerChange = arguments[1];
2336
- }
2337
- if (!value) {
2338
- this.clear(triggerChange);
2339
- } else {
2340
- data = this.data();
2341
- this.opts.element.val(!value ? "" : this.id(value));
2342
- this.updateSelection(value);
2343
- if (triggerChange) {
2344
- this.triggerChange({added: value, removed:data});
2345
- }
2346
- }
2347
- }
2348
- }
2349
- });
2350
-
2351
- MultiSelect2 = clazz(AbstractSelect2, {
2352
-
2353
- // multi
2354
- createContainer: function () {
2355
- var container = $(document.createElement("div")).attr({
2356
- "class": "select2-container select2-container-multi"
2357
- }).html([
2358
- "<ul class='select2-choices'>",
2359
- " <li class='select2-search-field'>",
2360
- " <input type='text' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' class='select2-input'>",
2361
- " </li>",
2362
- "</ul>",
2363
- "<div class='select2-drop select2-drop-multi select2-display-none'>",
2364
- " <ul class='select2-results'>",
2365
- " </ul>",
2366
- "</div>"].join(""));
2367
- return container;
2368
- },
2369
-
2370
- // multi
2371
- prepareOpts: function () {
2372
- var opts = this.parent.prepareOpts.apply(this, arguments),
2373
- self=this;
2374
-
2375
- // TODO validate placeholder is a string if specified
2376
-
2377
- if (opts.element.get(0).tagName.toLowerCase() === "select") {
2378
- // install sthe selection initializer
2379
- opts.initSelection = function (element, callback) {
2380
-
2381
- var data = [];
2382
-
2383
- element.find(":selected").each2(function (i, elm) {
2384
- data.push(self.optionToData(elm));
2385
- });
2386
- callback(data);
2387
- };
2388
- } else if ("data" in opts) {
2389
- // install default initSelection when applied to hidden input and data is local
2390
- opts.initSelection = opts.initSelection || function (element, callback) {
2391
- var ids = splitVal(element.val(), opts.separator);
2392
- //search in data by array of ids, storing matching items in a list
2393
- var matches = [];
2394
- opts.query({
2395
- matcher: function(term, text, el){
2396
- var is_match = $.grep(ids, function(id) {
2397
- return equal(id, opts.id(el));
2398
- }).length;
2399
- if (is_match) {
2400
- matches.push(el);
2401
- }
2402
- return is_match;
2403
- },
2404
- callback: !$.isFunction(callback) ? $.noop : function() {
2405
- // reorder matches based on the order they appear in the ids array because right now
2406
- // they are in the order in which they appear in data array
2407
- var ordered = [];
2408
- for (var i = 0; i < ids.length; i++) {
2409
- var id = ids[i];
2410
- for (var j = 0; j < matches.length; j++) {
2411
- var match = matches[j];
2412
- if (equal(id, opts.id(match))) {
2413
- ordered.push(match);
2414
- matches.splice(j, 1);
2415
- break;
2416
- }
2417
- }
2418
- }
2419
- callback(ordered);
2420
- }
2421
- });
2422
- };
2423
- }
2424
-
2425
- return opts;
2426
- },
2427
-
2428
- selectChoice: function (choice) {
2429
-
2430
- var selected = this.container.find(".select2-search-choice-focus");
2431
- if (selected.length && choice && choice[0] == selected[0]) {
2432
-
2433
- } else {
2434
- if (selected.length) {
2435
- this.opts.element.trigger("choice-deselected", selected);
2436
- }
2437
- selected.removeClass("select2-search-choice-focus");
2438
- if (choice && choice.length) {
2439
- this.close();
2440
- choice.addClass("select2-search-choice-focus");
2441
- this.opts.element.trigger("choice-selected", choice);
2442
- }
2443
- }
2444
- },
2445
-
2446
- // multi
2447
- destroy: function() {
2448
- $("label[for='" + this.search.attr('id') + "']")
2449
- .attr('for', this.opts.element.attr("id"));
2450
- this.parent.destroy.apply(this, arguments);
2451
- },
2452
-
2453
- // multi
2454
- initContainer: function () {
2455
-
2456
- var selector = ".select2-choices", selection;
2457
-
2458
- this.searchContainer = this.container.find(".select2-search-field");
2459
- this.selection = selection = this.container.find(selector);
2460
-
2461
- var _this = this;
2462
- this.selection.on("click", ".select2-search-choice:not(.select2-locked)", function (e) {
2463
- //killEvent(e);
2464
- _this.search[0].focus();
2465
- _this.selectChoice($(this));
2466
- });
2467
-
2468
- // rewrite labels from original element to focusser
2469
- this.search.attr("id", "s2id_autogen"+nextUid());
2470
- $("label[for='" + this.opts.element.attr("id") + "']")
2471
- .attr('for', this.search.attr('id'));
2472
-
2473
- this.search.on("input paste", this.bind(function() {
2474
- if (!this.isInterfaceEnabled()) return;
2475
- if (!this.opened()) {
2476
- this.open();
2477
- }
2478
- }));
2479
-
2480
- this.search.attr("tabindex", this.elementTabIndex);
2481
-
2482
- this.keydowns = 0;
2483
- this.search.on("keydown", this.bind(function (e) {
2484
- if (!this.isInterfaceEnabled()) return;
2485
-
2486
- ++this.keydowns;
2487
- var selected = selection.find(".select2-search-choice-focus");
2488
- var prev = selected.prev(".select2-search-choice:not(.select2-locked)");
2489
- var next = selected.next(".select2-search-choice:not(.select2-locked)");
2490
- var pos = getCursorInfo(this.search);
2491
-
2492
- if (selected.length &&
2493
- (e.which == KEY.LEFT || e.which == KEY.RIGHT || e.which == KEY.BACKSPACE || e.which == KEY.DELETE || e.which == KEY.ENTER)) {
2494
- var selectedChoice = selected;
2495
- if (e.which == KEY.LEFT && prev.length) {
2496
- selectedChoice = prev;
2497
- }
2498
- else if (e.which == KEY.RIGHT) {
2499
- selectedChoice = next.length ? next : null;
2500
- }
2501
- else if (e.which === KEY.BACKSPACE) {
2502
- this.unselect(selected.first());
2503
- this.search.width(10);
2504
- selectedChoice = prev.length ? prev : next;
2505
- } else if (e.which == KEY.DELETE) {
2506
- this.unselect(selected.first());
2507
- this.search.width(10);
2508
- selectedChoice = next.length ? next : null;
2509
- } else if (e.which == KEY.ENTER) {
2510
- selectedChoice = null;
2511
- }
2512
-
2513
- this.selectChoice(selectedChoice);
2514
- killEvent(e);
2515
- if (!selectedChoice || !selectedChoice.length) {
2516
- this.open();
2517
- }
2518
- return;
2519
- } else if (((e.which === KEY.BACKSPACE && this.keydowns == 1)
2520
- || e.which == KEY.LEFT) && (pos.offset == 0 && !pos.length)) {
2521
-
2522
- this.selectChoice(selection.find(".select2-search-choice:not(.select2-locked)").last());
2523
- killEvent(e);
2524
- return;
2525
- } else {
2526
- this.selectChoice(null);
2527
- }
2528
-
2529
- if (this.opened()) {
2530
- switch (e.which) {
2531
- case KEY.UP:
2532
- case KEY.DOWN:
2533
- this.moveHighlight((e.which === KEY.UP) ? -1 : 1);
2534
- killEvent(e);
2535
- return;
2536
- case KEY.ENTER:
2537
- this.selectHighlighted();
2538
- killEvent(e);
2539
- return;
2540
- case KEY.TAB:
2541
- this.selectHighlighted({noFocus:true});
2542
- this.close();
2543
- return;
2544
- case KEY.ESC:
2545
- this.cancel(e);
2546
- killEvent(e);
2547
- return;
2548
- }
2549
- }
2550
-
2551
- if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e)
2552
- || e.which === KEY.BACKSPACE || e.which === KEY.ESC) {
2553
- return;
2554
- }
2555
-
2556
- if (e.which === KEY.ENTER) {
2557
- if (this.opts.openOnEnter === false) {
2558
- return;
2559
- } else if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) {
2560
- return;
2561
- }
2562
- }
2563
-
2564
- this.open();
2565
-
2566
- if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
2567
- // prevent the page from scrolling
2568
- killEvent(e);
2569
- }
2570
-
2571
- if (e.which === KEY.ENTER) {
2572
- // prevent form from being submitted
2573
- killEvent(e);
2574
- }
2575
-
2576
- }));
2577
-
2578
- this.search.on("keyup", this.bind(function (e) {
2579
- this.keydowns = 0;
2580
- this.resizeSearch();
2581
- })
2582
- );
2583
-
2584
- this.search.on("blur", this.bind(function(e) {
2585
- this.container.removeClass("select2-container-active");
2586
- this.search.removeClass("select2-focused");
2587
- this.selectChoice(null);
2588
- if (!this.opened()) this.clearSearch();
2589
- e.stopImmediatePropagation();
2590
- this.opts.element.trigger($.Event("select2-blur"));
2591
- }));
2592
-
2593
- this.container.on("click", selector, this.bind(function (e) {
2594
- if (!this.isInterfaceEnabled()) return;
2595
- if ($(e.target).closest(".select2-search-choice").length > 0) {
2596
- // clicked inside a select2 search choice, do not open
2597
- return;
2598
- }
2599
- this.selectChoice(null);
2600
- this.clearPlaceholder();
2601
- if (!this.container.hasClass("select2-container-active")) {
2602
- this.opts.element.trigger($.Event("select2-focus"));
2603
- }
2604
- this.open();
2605
- this.focusSearch();
2606
- e.preventDefault();
2607
- }));
2608
-
2609
- this.container.on("focus", selector, this.bind(function () {
2610
- if (!this.isInterfaceEnabled()) return;
2611
- if (!this.container.hasClass("select2-container-active")) {
2612
- this.opts.element.trigger($.Event("select2-focus"));
2613
- }
2614
- this.container.addClass("select2-container-active");
2615
- this.dropdown.addClass("select2-drop-active");
2616
- this.clearPlaceholder();
2617
- }));
2618
-
2619
- this.initContainerWidth();
2620
- this.opts.element.addClass("select2-offscreen");
2621
-
2622
- // set the placeholder if necessary
2623
- this.clearSearch();
2624
- },
2625
-
2626
- // multi
2627
- enableInterface: function() {
2628
- if (this.parent.enableInterface.apply(this, arguments)) {
2629
- this.search.prop("disabled", !this.isInterfaceEnabled());
2630
- }
2631
- },
2632
-
2633
- // multi
2634
- initSelection: function () {
2635
- var data;
2636
- if (this.opts.element.val() === "" && this.opts.element.text() === "") {
2637
- this.updateSelection([]);
2638
- this.close();
2639
- // set the placeholder if necessary
2640
- this.clearSearch();
2641
- }
2642
- if (this.select || this.opts.element.val() !== "") {
2643
- var self = this;
2644
- this.opts.initSelection.call(null, this.opts.element, function(data){
2645
- if (data !== undefined && data !== null) {
2646
- self.updateSelection(data);
2647
- self.close();
2648
- // set the placeholder if necessary
2649
- self.clearSearch();
2650
- }
2651
- });
2652
- }
2653
- },
2654
-
2655
- // multi
2656
- clearSearch: function () {
2657
- var placeholder = this.getPlaceholder(),
2658
- maxWidth = this.getMaxSearchWidth();
2659
-
2660
- if (placeholder !== undefined && this.getVal().length === 0 && this.search.hasClass("select2-focused") === false) {
2661
- this.search.val(placeholder).addClass("select2-default");
2662
- // stretch the search box to full width of the container so as much of the placeholder is visible as possible
2663
- // we could call this.resizeSearch(), but we do not because that requires a sizer and we do not want to create one so early because of a firefox bug, see #944
2664
- this.search.width(maxWidth > 0 ? maxWidth : this.container.css("width"));
2665
- } else {
2666
- this.search.val("").width(10);
2667
- }
2668
- },
2669
-
2670
- // multi
2671
- clearPlaceholder: function () {
2672
- if (this.search.hasClass("select2-default")) {
2673
- this.search.val("").removeClass("select2-default");
2674
- }
2675
- },
2676
-
2677
- // multi
2678
- opening: function () {
2679
- this.clearPlaceholder(); // should be done before super so placeholder is not used to search
2680
- this.resizeSearch();
2681
-
2682
- this.parent.opening.apply(this, arguments);
2683
-
2684
- this.focusSearch();
2685
-
2686
- this.updateResults(true);
2687
- this.search.focus();
2688
- this.opts.element.trigger($.Event("select2-open"));
2689
- },
2690
-
2691
- // multi
2692
- close: function () {
2693
- if (!this.opened()) return;
2694
- this.parent.close.apply(this, arguments);
2695
- },
2696
-
2697
- // multi
2698
- focus: function () {
2699
- this.close();
2700
- this.search.focus();
2701
- },
2702
-
2703
- // multi
2704
- isFocused: function () {
2705
- return this.search.hasClass("select2-focused");
2706
- },
2707
-
2708
- // multi
2709
- updateSelection: function (data) {
2710
- var ids = [], filtered = [], self = this;
2711
-
2712
- // filter out duplicates
2713
- $(data).each(function () {
2714
- if (indexOf(self.id(this), ids) < 0) {
2715
- ids.push(self.id(this));
2716
- filtered.push(this);
2717
- }
2718
- });
2719
- data = filtered;
2720
-
2721
- this.selection.find(".select2-search-choice").remove();
2722
- $(data).each(function () {
2723
- self.addSelectedChoice(this);
2724
- });
2725
- self.postprocessResults();
2726
- },
2727
-
2728
- // multi
2729
- tokenize: function() {
2730
- var input = this.search.val();
2731
- input = this.opts.tokenizer.call(this, input, this.data(), this.bind(this.onSelect), this.opts);
2732
- if (input != null && input != undefined) {
2733
- this.search.val(input);
2734
- if (input.length > 0) {
2735
- this.open();
2736
- }
2737
- }
2738
-
2739
- },
2740
-
2741
- // multi
2742
- onSelect: function (data, options) {
2743
-
2744
- if (!this.triggerSelect(data)) { return; }
2745
-
2746
- this.addSelectedChoice(data);
2747
-
2748
- this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
2749
-
2750
- if (this.select || !this.opts.closeOnSelect) this.postprocessResults(data, false, this.opts.closeOnSelect===true);
2751
-
2752
- if (this.opts.closeOnSelect) {
2753
- this.close();
2754
- this.search.width(10);
2755
- } else {
2756
- if (this.countSelectableResults()>0) {
2757
- this.search.width(10);
2758
- this.resizeSearch();
2759
- if (this.getMaximumSelectionSize() > 0 && this.val().length >= this.getMaximumSelectionSize()) {
2760
- // if we reached max selection size repaint the results so choices
2761
- // are replaced with the max selection reached message
2762
- this.updateResults(true);
2763
- }
2764
- this.positionDropdown();
2765
- } else {
2766
- // if nothing left to select close
2767
- this.close();
2768
- this.search.width(10);
2769
- }
2770
- }
2771
-
2772
- // since its not possible to select an element that has already been
2773
- // added we do not need to check if this is a new element before firing change
2774
- this.triggerChange({ added: data });
2775
-
2776
- if (!options || !options.noFocus)
2777
- this.focusSearch();
2778
- },
2779
-
2780
- // multi
2781
- cancel: function () {
2782
- this.close();
2783
- this.focusSearch();
2784
- },
2785
-
2786
- addSelectedChoice: function (data) {
2787
- var enableChoice = !data.locked,
2788
- enabledItem = $(
2789
- "<li class='select2-search-choice'>" +
2790
- " <div></div>" +
2791
- " <a href='#' onclick='return false;' class='select2-search-choice-close' tabindex='-1'></a>" +
2792
- "</li>"),
2793
- disabledItem = $(
2794
- "<li class='select2-search-choice select2-locked'>" +
2795
- "<div></div>" +
2796
- "</li>");
2797
- var choice = enableChoice ? enabledItem : disabledItem,
2798
- id = this.id(data),
2799
- val = this.getVal(),
2800
- formatted,
2801
- cssClass;
2802
-
2803
- formatted=this.opts.formatSelection(data, choice.find("div"), this.opts.escapeMarkup);
2804
- if (formatted != undefined) {
2805
- choice.find("div").replaceWith("<div>"+formatted+"</div>");
2806
- }
2807
- cssClass=this.opts.formatSelectionCssClass(data, choice.find("div"));
2808
- if (cssClass != undefined) {
2809
- choice.addClass(cssClass);
2810
- }
2811
-
2812
- if(enableChoice){
2813
- choice.find(".select2-search-choice-close")
2814
- .on("mousedown", killEvent)
2815
- .on("click dblclick", this.bind(function (e) {
2816
- if (!this.isInterfaceEnabled()) return;
2817
-
2818
- $(e.target).closest(".select2-search-choice").fadeOut('fast', this.bind(function(){
2819
- this.unselect($(e.target));
2820
- this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
2821
- this.close();
2822
- this.focusSearch();
2823
- })).dequeue();
2824
- killEvent(e);
2825
- })).on("focus", this.bind(function () {
2826
- if (!this.isInterfaceEnabled()) return;
2827
- this.container.addClass("select2-container-active");
2828
- this.dropdown.addClass("select2-drop-active");
2829
- }));
2830
- }
2831
-
2832
- choice.data("select2-data", data);
2833
- choice.insertBefore(this.searchContainer);
2834
-
2835
- val.push(id);
2836
- this.setVal(val);
2837
- },
2838
-
2839
- // multi
2840
- unselect: function (selected) {
2841
- var val = this.getVal(),
2842
- data,
2843
- index;
2844
-
2845
- selected = selected.closest(".select2-search-choice");
2846
-
2847
- if (selected.length === 0) {
2848
- throw "Invalid argument: " + selected + ". Must be .select2-search-choice";
2849
- }
2850
-
2851
- data = selected.data("select2-data");
2852
-
2853
- if (!data) {
2854
- // prevent a race condition when the 'x' is clicked really fast repeatedly the event can be queued
2855
- // and invoked on an element already removed
2856
- return;
2857
- }
2858
-
2859
- while((index = indexOf(this.id(data), val)) >= 0) {
2860
- val.splice(index, 1);
2861
- this.setVal(val);
2862
- if (this.select) this.postprocessResults();
2863
- }
2864
- selected.remove();
2865
-
2866
- this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data });
2867
- this.triggerChange({ removed: data });
2868
- },
2869
-
2870
- // multi
2871
- postprocessResults: function (data, initial, noHighlightUpdate) {
2872
- var val = this.getVal(),
2873
- choices = this.results.find(".select2-result"),
2874
- compound = this.results.find(".select2-result-with-children"),
2875
- self = this;
2876
-
2877
- choices.each2(function (i, choice) {
2878
- var id = self.id(choice.data("select2-data"));
2879
- if (indexOf(id, val) >= 0) {
2880
- choice.addClass("select2-selected");
2881
- // mark all children of the selected parent as selected
2882
- choice.find(".select2-result-selectable").addClass("select2-selected");
2883
- }
2884
- });
2885
-
2886
- compound.each2(function(i, choice) {
2887
- // hide an optgroup if it doesnt have any selectable children
2888
- if (!choice.is('.select2-result-selectable')
2889
- && choice.find(".select2-result-selectable:not(.select2-selected)").length === 0) {
2890
- choice.addClass("select2-selected");
2891
- }
2892
- });
2893
-
2894
- if (this.highlight() == -1 && noHighlightUpdate !== false){
2895
- self.highlight(0);
2896
- }
2897
-
2898
- //If all results are chosen render formatNoMAtches
2899
- if(!this.opts.createSearchChoice && !choices.filter('.select2-result:not(.select2-selected)').length > 0){
2900
- if(!data || data && !data.more && this.results.find(".select2-no-results").length === 0) {
2901
- if (checkFormatter(self.opts.formatNoMatches, "formatNoMatches")) {
2902
- this.results.append("<li class='select2-no-results'>" + self.opts.formatNoMatches(self.search.val()) + "</li>");
2903
- }
2904
- }
2905
- }
2906
-
2907
- },
2908
-
2909
- // multi
2910
- getMaxSearchWidth: function() {
2911
- return this.selection.width() - getSideBorderPadding(this.search);
2912
- },
2913
-
2914
- // multi
2915
- resizeSearch: function () {
2916
- var minimumWidth, left, maxWidth, containerLeft, searchWidth,
2917
- sideBorderPadding = getSideBorderPadding(this.search);
2918
-
2919
- minimumWidth = measureTextWidth(this.search) + 10;
2920
-
2921
- left = this.search.offset().left;
2922
-
2923
- maxWidth = this.selection.width();
2924
- containerLeft = this.selection.offset().left;
2925
-
2926
- searchWidth = maxWidth - (left - containerLeft) - sideBorderPadding;
2927
-
2928
- if (searchWidth < minimumWidth) {
2929
- searchWidth = maxWidth - sideBorderPadding;
2930
- }
2931
-
2932
- if (searchWidth < 40) {
2933
- searchWidth = maxWidth - sideBorderPadding;
2934
- }
2935
-
2936
- if (searchWidth <= 0) {
2937
- searchWidth = minimumWidth;
2938
- }
2939
-
2940
- this.search.width(Math.floor(searchWidth));
2941
- },
2942
-
2943
- // multi
2944
- getVal: function () {
2945
- var val;
2946
- if (this.select) {
2947
- val = this.select.val();
2948
- return val === null ? [] : val;
2949
- } else {
2950
- val = this.opts.element.val();
2951
- return splitVal(val, this.opts.separator);
2952
- }
2953
- },
2954
-
2955
- // multi
2956
- setVal: function (val) {
2957
- var unique;
2958
- if (this.select) {
2959
- this.select.val(val);
2960
- } else {
2961
- unique = [];
2962
- // filter out duplicates
2963
- $(val).each(function () {
2964
- if (indexOf(this, unique) < 0) unique.push(this);
2965
- });
2966
- this.opts.element.val(unique.length === 0 ? "" : unique.join(this.opts.separator));
2967
- }
2968
- },
2969
-
2970
- // multi
2971
- buildChangeDetails: function (old, current) {
2972
- var current = current.slice(0),
2973
- old = old.slice(0);
2974
-
2975
- // remove intersection from each array
2976
- for (var i = 0; i < current.length; i++) {
2977
- for (var j = 0; j < old.length; j++) {
2978
- if (equal(this.opts.id(current[i]), this.opts.id(old[j]))) {
2979
- current.splice(i, 1);
2980
- i--;
2981
- old.splice(j, 1);
2982
- j--;
2983
- }
2984
- }
2985
- }
2986
-
2987
- return {added: current, removed: old};
2988
- },
2989
-
2990
-
2991
- // multi
2992
- val: function (val, triggerChange) {
2993
- var oldData, self=this, changeDetails;
2994
-
2995
- if (arguments.length === 0) {
2996
- return this.getVal();
2997
- }
2998
-
2999
- oldData=this.data();
3000
- if (!oldData.length) oldData=[];
3001
-
3002
- // val is an id. !val is true for [undefined,null,'',0] - 0 is legal
3003
- if (!val && val !== 0) {
3004
- this.opts.element.val("");
3005
- this.updateSelection([]);
3006
- this.clearSearch();
3007
- if (triggerChange) {
3008
- this.triggerChange({added: this.data(), removed: oldData});
3009
- }
3010
- return;
3011
- }
3012
-
3013
- // val is a list of ids
3014
- this.setVal(val);
3015
-
3016
- if (this.select) {
3017
- this.opts.initSelection(this.select, this.bind(this.updateSelection));
3018
- if (triggerChange) {
3019
- this.triggerChange(this.buildChangeDetails(oldData, this.data()));
3020
- }
3021
- } else {
3022
- if (this.opts.initSelection === undefined) {
3023
- throw new Error("val() cannot be called if initSelection() is not defined");
3024
- }
3025
-
3026
- this.opts.initSelection(this.opts.element, function(data){
3027
- var ids=$.map(data, self.id);
3028
- self.setVal(ids);
3029
- self.updateSelection(data);
3030
- self.clearSearch();
3031
- if (triggerChange) {
3032
- self.triggerChange(self.buildChangeDetails(oldData, this.data()));
3033
- }
3034
- });
3035
- }
3036
- this.clearSearch();
3037
- },
3038
-
3039
- // multi
3040
- onSortStart: function() {
3041
- if (this.select) {
3042
- throw new Error("Sorting of elements is not supported when attached to <select>. Attach to <input type='hidden'/> instead.");
3043
- }
3044
-
3045
- // collapse search field into 0 width so its container can be collapsed as well
3046
- this.search.width(0);
3047
- // hide the container
3048
- this.searchContainer.hide();
3049
- },
3050
-
3051
- // multi
3052
- onSortEnd:function() {
3053
-
3054
- var val=[], self=this;
3055
-
3056
- // show search and move it to the end of the list
3057
- this.searchContainer.show();
3058
- // make sure the search container is the last item in the list
3059
- this.searchContainer.appendTo(this.searchContainer.parent());
3060
- // since we collapsed the width in dragStarted, we resize it here
3061
- this.resizeSearch();
3062
-
3063
- // update selection
3064
- this.selection.find(".select2-search-choice").each(function() {
3065
- val.push(self.opts.id($(this).data("select2-data")));
3066
- });
3067
- this.setVal(val);
3068
- this.triggerChange();
3069
- },
3070
-
3071
- // multi
3072
- data: function(values, triggerChange) {
3073
- var self=this, ids, old;
3074
- if (arguments.length === 0) {
3075
- return this.selection
3076
- .find(".select2-search-choice")
3077
- .map(function() { return $(this).data("select2-data"); })
3078
- .get();
3079
- } else {
3080
- old = this.data();
3081
- if (!values) { values = []; }
3082
- ids = $.map(values, function(e) { return self.opts.id(e); });
3083
- this.setVal(ids);
3084
- this.updateSelection(values);
3085
- this.clearSearch();
3086
- if (triggerChange) {
3087
- this.triggerChange(this.buildChangeDetails(old, this.data()));
3088
- }
3089
- }
3090
- }
3091
- });
3092
-
3093
- $.fn.select2 = function () {
3094
-
3095
- var args = Array.prototype.slice.call(arguments, 0),
3096
- opts,
3097
- select2,
3098
- method, value, multiple,
3099
- allowedMethods = ["val", "destroy", "opened", "open", "close", "focus", "isFocused", "container", "dropdown", "onSortStart", "onSortEnd", "enable", "disable", "readonly", "positionDropdown", "data", "search"],
3100
- valueMethods = ["opened", "isFocused", "container", "dropdown"],
3101
- propertyMethods = ["val", "data"],
3102
- methodsMap = { search: "externalSearch" };
3103
-
3104
- this.each(function () {
3105
- if (args.length === 0 || typeof(args[0]) === "object") {
3106
- opts = args.length === 0 ? {} : $.extend({}, args[0]);
3107
- opts.element = $(this);
3108
-
3109
- if (opts.element.get(0).tagName.toLowerCase() === "select") {
3110
- multiple = opts.element.prop("multiple");
3111
- } else {
3112
- multiple = opts.multiple || false;
3113
- if ("tags" in opts) {opts.multiple = multiple = true;}
3114
- }
3115
-
3116
- select2 = multiple ? new MultiSelect2() : new SingleSelect2();
3117
- select2.init(opts);
3118
- } else if (typeof(args[0]) === "string") {
3119
-
3120
- if (indexOf(args[0], allowedMethods) < 0) {
3121
- throw "Unknown method: " + args[0];
3122
- }
3123
-
3124
- value = undefined;
3125
- select2 = $(this).data("select2");
3126
- if (select2 === undefined) return;
3127
-
3128
- method=args[0];
3129
-
3130
- if (method === "container") {
3131
- value = select2.container;
3132
- } else if (method === "dropdown") {
3133
- value = select2.dropdown;
3134
- } else {
3135
- if (methodsMap[method]) method = methodsMap[method];
3136
-
3137
- value = select2[method].apply(select2, args.slice(1));
3138
- }
3139
- if (indexOf(args[0], valueMethods) >= 0
3140
- || (indexOf(args[0], propertyMethods) && args.length == 1)) {
3141
- return false; // abort the iteration, ready to return first matched value
3142
- }
3143
- } else {
3144
- throw "Invalid arguments to select2 plugin: " + args;
3145
- }
3146
- });
3147
- return (value === undefined) ? this : value;
3148
- };
3149
-
3150
- // plugin defaults, accessible to users
3151
- $.fn.select2.defaults = {
3152
- width: "copy",
3153
- loadMorePadding: 0,
3154
- closeOnSelect: true,
3155
- openOnEnter: true,
3156
- containerCss: {},
3157
- dropdownCss: {},
3158
- containerCssClass: "",
3159
- dropdownCssClass: "",
3160
- formatResult: function(result, container, query, escapeMarkup) {
3161
- var markup=[];
3162
- markMatch(result.text, query.term, markup, escapeMarkup);
3163
- return markup.join("");
3164
- },
3165
- formatSelection: function (data, container, escapeMarkup) {
3166
- return data ? escapeMarkup(data.text) : undefined;
3167
- },
3168
- sortResults: function (results, container, query) {
3169
- return results;
3170
- },
3171
- formatResultCssClass: function(data) {return undefined;},
3172
- formatSelectionCssClass: function(data, container) {return undefined;},
3173
- formatNoMatches: function () { return "No matches found"; },
3174
- formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " more character" + (n == 1? "" : "s"); },
3175
- formatInputTooLong: function (input, max) { var n = input.length - max; return "Please delete " + n + " character" + (n == 1? "" : "s"); },
3176
- formatSelectionTooBig: function (limit) { return "You can only select " + limit + " item" + (limit == 1 ? "" : "s"); },
3177
- formatLoadMore: function (pageNumber) { return "Loading more results..."; },
3178
- formatSearching: function () { return "Searching..."; },
3179
- minimumResultsForSearch: 0,
3180
- minimumInputLength: 0,
3181
- maximumInputLength: null,
3182
- maximumSelectionSize: 0,
3183
- id: function (e) { return e.id; },
3184
- matcher: function(term, text) {
3185
- return stripDiacritics(''+text).toUpperCase().indexOf(stripDiacritics(''+term).toUpperCase()) >= 0;
3186
- },
3187
- separator: ",",
3188
- tokenSeparators: [],
3189
- tokenizer: defaultTokenizer,
3190
- escapeMarkup: defaultEscapeMarkup,
3191
- blurOnChange: false,
3192
- selectOnBlur: false,
3193
- adaptContainerCssClass: function(c) { return c; },
3194
- adaptDropdownCssClass: function(c) { return null; },
3195
- nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; }
3196
- };
3197
-
3198
- $.fn.select2.ajaxDefaults = {
3199
- transport: $.ajax,
3200
- params: {
3201
- type: "GET",
3202
- cache: false,
3203
- dataType: "json"
3204
- }
3205
- };
3206
-
3207
- // exports
3208
- window.Select2 = {
3209
- query: {
3210
- ajax: ajax,
3211
- local: local,
3212
- tags: tags
3213
- }, util: {
3214
- debounce: debounce,
3215
- markMatch: markMatch,
3216
- escapeMarkup: defaultEscapeMarkup,
3217
- stripDiacritics: stripDiacritics
3218
- }, "class": {
3219
- "abstract": AbstractSelect2,
3220
- "single": SingleSelect2,
3221
- "multi": MultiSelect2
3222
- }
3223
- };
3224
-
3225
- }(jQuery));