active_admin_pro 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (295) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +5 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/active_admin_pro.js +41 -0
  6. data/app/assets/javascripts/active_admin_pro/actions/new.js +8 -0
  7. data/app/assets/javascripts/active_admin_pro/actions/show.js +12 -0
  8. data/app/assets/javascripts/active_admin_pro/components/codemirror_input.js +92 -0
  9. data/app/assets/javascripts/active_admin_pro/components/flashes.js +9 -0
  10. data/app/assets/javascripts/active_admin_pro/components/link.js +23 -0
  11. data/app/assets/javascripts/active_admin_pro/components/phone_input.js +52 -0
  12. data/app/assets/javascripts/active_admin_pro/components/select_input.js +31 -0
  13. data/app/assets/javascripts/active_admin_pro/components/sortable_handle.js +8 -0
  14. data/app/assets/javascripts/active_admin_pro/components/summernote_input.js +132 -0
  15. data/app/assets/javascripts/active_admin_pro/components/text_input.js +47 -0
  16. data/app/assets/javascripts/active_admin_pro/components/time_zone_input.js +51 -0
  17. data/app/assets/javascripts/active_admin_pro/components/title_to_slug.js +16 -0
  18. data/app/assets/stylesheets/active_admin_pro.scss +20 -0
  19. data/app/assets/stylesheets/active_admin_pro/breakpoints.scss +3 -0
  20. data/app/assets/stylesheets/active_admin_pro/components/_input_variables.scss +9 -0
  21. data/app/assets/stylesheets/active_admin_pro/components/actions.scss +13 -0
  22. data/app/assets/stylesheets/active_admin_pro/components/boolean_input.scss +13 -0
  23. data/app/assets/stylesheets/active_admin_pro/components/button.scss +7 -0
  24. data/app/assets/stylesheets/active_admin_pro/components/check_boxes_input.scss +38 -0
  25. data/app/assets/stylesheets/active_admin_pro/components/codemirror_input.scss +53 -0
  26. data/app/assets/stylesheets/active_admin_pro/components/comments.scss +17 -0
  27. data/app/assets/stylesheets/active_admin_pro/components/datepicker.scss +108 -0
  28. data/app/assets/stylesheets/active_admin_pro/components/dialog.scss +66 -0
  29. data/app/assets/stylesheets/active_admin_pro/components/dropdown_menu_button.scss +40 -0
  30. data/app/assets/stylesheets/active_admin_pro/components/fieldset.scss +26 -0
  31. data/app/assets/stylesheets/active_admin_pro/components/file_input.scss +27 -0
  32. data/app/assets/stylesheets/active_admin_pro/components/has_many_fields.scss +4 -0
  33. data/app/assets/stylesheets/active_admin_pro/components/inline_errors.scss +7 -0
  34. data/app/assets/stylesheets/active_admin_pro/components/link.scss +16 -0
  35. data/app/assets/stylesheets/active_admin_pro/components/panel.scss +62 -0
  36. data/app/assets/stylesheets/active_admin_pro/components/phone_input.scss +31 -0
  37. data/app/assets/stylesheets/active_admin_pro/components/radio_input.scss +38 -0
  38. data/app/assets/stylesheets/active_admin_pro/components/segmented_control.scss +41 -0
  39. data/app/assets/stylesheets/active_admin_pro/components/select_input.scss +42 -0
  40. data/app/assets/stylesheets/active_admin_pro/components/sortable_handle.scss +21 -0
  41. data/app/assets/stylesheets/active_admin_pro/components/string_input.scss +85 -0
  42. data/app/assets/stylesheets/active_admin_pro/components/summernote_input.scss +190 -0
  43. data/app/assets/stylesheets/active_admin_pro/components/table.scss +100 -0
  44. data/app/assets/stylesheets/active_admin_pro/components/text_input.scss +55 -0
  45. data/app/assets/stylesheets/active_admin_pro/functions/color.scss +130 -0
  46. data/app/assets/stylesheets/active_admin_pro/functions/text-color.scss +35 -0
  47. data/app/assets/stylesheets/active_admin_pro/layout/actions/comments.scss +14 -0
  48. data/app/assets/stylesheets/active_admin_pro/layout/actions/index.scss +88 -0
  49. data/app/assets/stylesheets/active_admin_pro/layout/actions/show.scss +25 -0
  50. data/app/assets/stylesheets/active_admin_pro/layout/body.scss +60 -0
  51. data/app/assets/stylesheets/active_admin_pro/layout/desktop/action_items.scss +32 -0
  52. data/app/assets/stylesheets/active_admin_pro/layout/desktop/actions/comments.scss +10 -0
  53. data/app/assets/stylesheets/active_admin_pro/layout/desktop/active_admin_content.scss +22 -0
  54. data/app/assets/stylesheets/active_admin_pro/layout/desktop/breadcrumbs.scss +57 -0
  55. data/app/assets/stylesheets/active_admin_pro/layout/desktop/navigation.scss +197 -0
  56. data/app/assets/stylesheets/active_admin_pro/layout/desktop/sidebar.scss +5 -0
  57. data/app/assets/stylesheets/active_admin_pro/layout/desktop/title_bar.scss +24 -0
  58. data/app/assets/stylesheets/active_admin_pro/layout/desktop/wrapper.scss +5 -0
  59. data/app/assets/stylesheets/active_admin_pro/layout/filters.scss +41 -0
  60. data/app/assets/stylesheets/active_admin_pro/layout/flashes.scss +52 -0
  61. data/app/assets/stylesheets/active_admin_pro/layout/footer.scss +3 -0
  62. data/app/assets/stylesheets/active_admin_pro/layout/mobile/actions/index.scss +7 -0
  63. data/app/assets/stylesheets/active_admin_pro/layout/tablet/actions/dashboard.scss +105 -0
  64. data/app/assets/stylesheets/active_admin_pro/layout/tablet/actions/index.scss +20 -0
  65. data/app/assets/stylesheets/active_admin_pro/layout/tablet/actions/show.scss +78 -0
  66. data/app/assets/stylesheets/active_admin_pro/layout/tablet/active_admin_content.scss +9 -0
  67. data/app/assets/stylesheets/active_admin_pro/layout/tablet/flashes.scss +5 -0
  68. data/app/assets/stylesheets/active_admin_pro/layout/tablet/navigation.scss +48 -0
  69. data/app/assets/stylesheets/active_admin_pro/layout/tablet/title_bar.scss +53 -0
  70. data/app/assets/stylesheets/active_admin_pro/mixins/button.scss +48 -0
  71. data/app/assets/stylesheets/active_admin_pro/variables.scss +10 -0
  72. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon.scss +87 -0
  73. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/_bourbon-deprecated-upcoming.scss +411 -0
  74. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_border-color.scss +26 -0
  75. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_border-radius.scss +48 -0
  76. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_border-style.scss +25 -0
  77. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_border-width.scss +25 -0
  78. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_buttons.scss +64 -0
  79. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_clearfix.scss +25 -0
  80. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_ellipsis.scss +30 -0
  81. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_font-stacks.scss +31 -0
  82. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_hide-text.scss +27 -0
  83. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_margin.scss +26 -0
  84. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_padding.scss +26 -0
  85. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_position.scss +48 -0
  86. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_prefixer.scss +66 -0
  87. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_retina-image.scss +25 -0
  88. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_size.scss +51 -0
  89. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_text-inputs.scss +113 -0
  90. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_timing-functions.scss +34 -0
  91. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_triangle.scss +63 -0
  92. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/addons/_word-wrap.scss +29 -0
  93. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_animation.scss +43 -0
  94. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_appearance.scss +3 -0
  95. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_backface-visibility.scss +3 -0
  96. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_background-image.scss +42 -0
  97. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_background.scss +55 -0
  98. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_border-image.scss +59 -0
  99. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_calc.scss +4 -0
  100. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_columns.scss +47 -0
  101. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_filter.scss +4 -0
  102. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_flex-box.scss +287 -0
  103. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_font-face.scss +24 -0
  104. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_font-feature-settings.scss +4 -0
  105. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_hidpi-media-query.scss +10 -0
  106. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_hyphens.scss +4 -0
  107. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_image-rendering.scss +14 -0
  108. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_keyframes.scss +36 -0
  109. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_linear-gradient.scss +38 -0
  110. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_perspective.scss +8 -0
  111. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_placeholder.scss +8 -0
  112. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_radial-gradient.scss +39 -0
  113. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_selection.scss +42 -0
  114. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_text-decoration.scss +19 -0
  115. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_transform.scss +15 -0
  116. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_transition.scss +71 -0
  117. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/css3/_user-select.scss +3 -0
  118. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_assign-inputs.scss +11 -0
  119. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_contains-falsy.scss +20 -0
  120. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_contains.scss +26 -0
  121. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_is-length.scss +11 -0
  122. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_is-light.scss +21 -0
  123. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_is-number.scss +11 -0
  124. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_is-size.scss +13 -0
  125. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_modular-scale.scss +69 -0
  126. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_px-to-em.scss +13 -0
  127. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_px-to-rem.scss +15 -0
  128. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_shade.scss +24 -0
  129. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_strip-units.scss +17 -0
  130. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_tint.scss +24 -0
  131. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_transition-property-name.scss +22 -0
  132. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/functions/_unpack.scss +27 -0
  133. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_convert-units.scss +21 -0
  134. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_directional-values.scss +96 -0
  135. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_font-source-declaration.scss +43 -0
  136. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_gradient-positions-parser.scss +13 -0
  137. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_linear-angle-parser.scss +25 -0
  138. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_linear-gradient-parser.scss +41 -0
  139. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_linear-positions-parser.scss +61 -0
  140. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_linear-side-corner-parser.scss +31 -0
  141. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_radial-arg-parser.scss +69 -0
  142. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_radial-gradient-parser.scss +50 -0
  143. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_radial-positions-parser.scss +18 -0
  144. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_render-gradients.scss +26 -0
  145. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_shape-size-stripper.scss +10 -0
  146. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/helpers/_str-to-num.scss +50 -0
  147. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/settings/_asset-pipeline.scss +7 -0
  148. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/settings/_prefixer.scss +9 -0
  149. data/app/assets/stylesheets/active_admin_pro/vendor/bourbon/settings/_px-to-em.scss +1 -0
  150. data/app/assets/stylesheets/active_admin_pro/vendor/neat.scss +22 -0
  151. data/app/assets/stylesheets/active_admin_pro/vendor/neat/_neat-helpers.scss +8 -0
  152. data/app/assets/stylesheets/active_admin_pro/vendor/neat/functions/_new-breakpoint.scss +49 -0
  153. data/app/assets/stylesheets/active_admin_pro/vendor/neat/functions/_private.scss +108 -0
  154. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_box-sizing.scss +11 -0
  155. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_direction-context.scss +31 -0
  156. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_display-context.scss +26 -0
  157. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_fill-parent.scss +22 -0
  158. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_media.scss +92 -0
  159. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_omega.scss +91 -0
  160. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_outer-container.scss +36 -0
  161. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_pad.scss +23 -0
  162. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_private.scss +35 -0
  163. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_row.scss +53 -0
  164. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_shift.scss +48 -0
  165. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_span-columns.scss +90 -0
  166. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_to-deprecate.scss +105 -0
  167. data/app/assets/stylesheets/active_admin_pro/vendor/neat/grid/_visual-grid.scss +40 -0
  168. data/app/assets/stylesheets/active_admin_pro/vendor/neat/settings/_disable-warnings.scss +11 -0
  169. data/app/assets/stylesheets/active_admin_pro/vendor/neat/settings/_grid.scss +53 -0
  170. data/app/assets/stylesheets/active_admin_pro/vendor/neat/settings/_visual-grid.scss +25 -0
  171. data/app/assets/stylesheets/active_admin_pro/vendor/normalize.css +423 -0
  172. data/app/assets/stylesheets/codemirror/themes/activeadmin_pro.scss +117 -0
  173. data/app/inputs/codemirror_input.rb +27 -0
  174. data/app/inputs/datepicker_input.rb +16 -0
  175. data/app/inputs/phone_input.rb +5 -0
  176. data/app/inputs/summernote_input.rb +5 -0
  177. data/app/inputs/time_zone_input.rb +43 -0
  178. data/app/models/activeadmin_pro/summernote_image.rb +5 -0
  179. data/config/initializers/active_admin.rb +50 -0
  180. data/config/locales/en.yml +55 -0
  181. data/lib/active_admin_pro/admin_user/admin_user.rb +52 -0
  182. data/lib/active_admin_pro/engine.rb +8 -0
  183. data/lib/active_admin_pro/summernote_image/summernote_image.rb +61 -0
  184. data/lib/active_admin_pro/user/user.rb +53 -0
  185. data/lib/active_admin_pro/version.rb +3 -0
  186. data/lib/activeadmin_pro.rb +9 -0
  187. data/lib/generators/activeadmin_pro/install_generator.rb +14 -0
  188. data/lib/tasks/activeadmin_pro_tasks.rake +4 -0
  189. data/spec/spec_helper.rb +34 -0
  190. data/vendor/assets/javascripts/bootstrap.js +1243 -0
  191. data/vendor/assets/javascripts/codemirror.js +8887 -0
  192. data/vendor/assets/javascripts/codemirror/addons/comment/comment.js +183 -0
  193. data/vendor/assets/javascripts/codemirror/addons/comment/continuecomment.js +85 -0
  194. data/vendor/assets/javascripts/codemirror/addons/dialog/dialog.css +32 -0
  195. data/vendor/assets/javascripts/codemirror/addons/dialog/dialog.js +157 -0
  196. data/vendor/assets/javascripts/codemirror/addons/display/autorefresh.js +47 -0
  197. data/vendor/assets/javascripts/codemirror/addons/display/fullscreen.css +6 -0
  198. data/vendor/assets/javascripts/codemirror/addons/display/fullscreen.js +41 -0
  199. data/vendor/assets/javascripts/codemirror/addons/display/panel.js +112 -0
  200. data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +60 -0
  201. data/vendor/assets/javascripts/codemirror/addons/display/rulers.js +63 -0
  202. data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +195 -0
  203. data/vendor/assets/javascripts/codemirror/addons/edit/closetag.js +169 -0
  204. data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +51 -0
  205. data/vendor/assets/javascripts/codemirror/addons/edit/matchbrackets.js +120 -0
  206. data/vendor/assets/javascripts/codemirror/addons/edit/matchtags.js +66 -0
  207. data/vendor/assets/javascripts/codemirror/addons/edit/trailingspace.js +27 -0
  208. data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +105 -0
  209. data/vendor/assets/javascripts/codemirror/addons/fold/comment-fold.js +57 -0
  210. data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +149 -0
  211. data/vendor/assets/javascripts/codemirror/addons/fold/foldgutter.css +20 -0
  212. data/vendor/assets/javascripts/codemirror/addons/fold/foldgutter.js +146 -0
  213. data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +44 -0
  214. data/vendor/assets/javascripts/codemirror/addons/fold/markdown-fold.js +49 -0
  215. data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +182 -0
  216. data/vendor/assets/javascripts/codemirror/addons/hint/anyword-hint.js +41 -0
  217. data/vendor/assets/javascripts/codemirror/addons/hint/css-hint.js +60 -0
  218. data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +348 -0
  219. data/vendor/assets/javascripts/codemirror/addons/hint/javascript-hint.js +146 -0
  220. data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.css +38 -0
  221. data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +386 -0
  222. data/vendor/assets/javascripts/codemirror/addons/hint/sql-hint.js +254 -0
  223. data/vendor/assets/javascripts/codemirror/addons/hint/xml-hint.js +110 -0
  224. data/vendor/assets/javascripts/codemirror/addons/lint/coffeescript-lint.js +41 -0
  225. data/vendor/assets/javascripts/codemirror/addons/lint/css-lint.js +35 -0
  226. data/vendor/assets/javascripts/codemirror/addons/lint/html-lint.js +46 -0
  227. data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +136 -0
  228. data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +31 -0
  229. data/vendor/assets/javascripts/codemirror/addons/lint/lint.css +73 -0
  230. data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +231 -0
  231. data/vendor/assets/javascripts/codemirror/addons/lint/yaml-lint.js +28 -0
  232. data/vendor/assets/javascripts/codemirror/addons/merge/merge.css +112 -0
  233. data/vendor/assets/javascripts/codemirror/addons/merge/merge.js +775 -0
  234. data/vendor/assets/javascripts/codemirror/addons/mode/loadmode.js +64 -0
  235. data/vendor/assets/javascripts/codemirror/addons/mode/multiplex.js +123 -0
  236. data/vendor/assets/javascripts/codemirror/addons/mode/multiplex_test.js +33 -0
  237. data/vendor/assets/javascripts/codemirror/addons/mode/overlay.js +85 -0
  238. data/vendor/assets/javascripts/codemirror/addons/mode/simple.js +213 -0
  239. data/vendor/assets/javascripts/codemirror/addons/runmode/colorize.js +40 -0
  240. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode-standalone.js +157 -0
  241. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.js +72 -0
  242. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +178 -0
  243. data/vendor/assets/javascripts/codemirror/addons/scroll/annotatescrollbar.js +115 -0
  244. data/vendor/assets/javascripts/codemirror/addons/scroll/scrollpastend.js +46 -0
  245. data/vendor/assets/javascripts/codemirror/addons/scroll/simplescrollbars.css +66 -0
  246. data/vendor/assets/javascripts/codemirror/addons/scroll/simplescrollbars.js +147 -0
  247. data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +128 -0
  248. data/vendor/assets/javascripts/codemirror/addons/search/matchesonscrollbar.css +8 -0
  249. data/vendor/assets/javascripts/codemirror/addons/search/matchesonscrollbar.js +97 -0
  250. data/vendor/assets/javascripts/codemirror/addons/search/search.js +228 -0
  251. data/vendor/assets/javascripts/codemirror/addons/search/searchcursor.js +189 -0
  252. data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +71 -0
  253. data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +118 -0
  254. data/vendor/assets/javascripts/codemirror/addons/selection/selection-pointer.js +98 -0
  255. data/vendor/assets/javascripts/codemirror/addons/tern/tern.css +87 -0
  256. data/vendor/assets/javascripts/codemirror/addons/tern/tern.js +700 -0
  257. data/vendor/assets/javascripts/codemirror/addons/tern/worker.js +44 -0
  258. data/vendor/assets/javascripts/codemirror/addons/wrap/hardwrap.js +139 -0
  259. data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +366 -0
  260. data/vendor/assets/javascripts/codemirror/modes/css.js +823 -0
  261. data/vendor/assets/javascripts/codemirror/modes/diff.js +47 -0
  262. data/vendor/assets/javascripts/codemirror/modes/dockerfile.js +79 -0
  263. data/vendor/assets/javascripts/codemirror/modes/gfm.js +130 -0
  264. data/vendor/assets/javascripts/codemirror/modes/go.js +185 -0
  265. data/vendor/assets/javascripts/codemirror/modes/haml.js +159 -0
  266. data/vendor/assets/javascripts/codemirror/modes/handlebars.js +53 -0
  267. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +28 -0
  268. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +150 -0
  269. data/vendor/assets/javascripts/codemirror/modes/javascript.js +708 -0
  270. data/vendor/assets/javascripts/codemirror/modes/markdown.js +792 -0
  271. data/vendor/assets/javascripts/codemirror/modes/nginx.js +178 -0
  272. data/vendor/assets/javascripts/codemirror/modes/php.js +234 -0
  273. data/vendor/assets/javascripts/codemirror/modes/python.js +358 -0
  274. data/vendor/assets/javascripts/codemirror/modes/ruby.js +285 -0
  275. data/vendor/assets/javascripts/codemirror/modes/rust.js +58 -0
  276. data/vendor/assets/javascripts/codemirror/modes/sass.js +414 -0
  277. data/vendor/assets/javascripts/codemirror/modes/shell.js +139 -0
  278. data/vendor/assets/javascripts/codemirror/modes/xml.js +385 -0
  279. data/vendor/assets/javascripts/codemirror/modes/yaml.js +117 -0
  280. data/vendor/assets/javascripts/intl-tel-input.js +963 -0
  281. data/vendor/assets/javascripts/intl-tel-utils.js +480 -0
  282. data/vendor/assets/javascripts/slug.js +212 -0
  283. data/vendor/assets/javascripts/summernote.js +6939 -0
  284. data/vendor/assets/stylesheets/codemirror.css +334 -0
  285. data/vendor/assets/stylesheets/codemirror/themes/base16-dark.css +38 -0
  286. data/vendor/assets/stylesheets/codemirror/themes/base16-light.css +38 -0
  287. data/vendor/assets/stylesheets/codemirror/themes/dracula.css +41 -0
  288. data/vendor/assets/stylesheets/codemirror/themes/material.css +53 -0
  289. data/vendor/assets/stylesheets/codemirror/themes/monokai.css +35 -0
  290. data/vendor/assets/stylesheets/codemirror/themes/solarized.css +163 -0
  291. data/vendor/assets/stylesheets/codemirror/themes/vibrant-ink.css +34 -0
  292. data/vendor/assets/stylesheets/intl-tel-input.scss +1054 -0
  293. data/vendor/assets/stylesheets/summernote-bs3.css +5425 -0
  294. data/vendor/assets/stylesheets/summernote.css +1 -0
  295. metadata +604 -0
@@ -0,0 +1,117 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+
14
+ CodeMirror.defineMode("yaml", function() {
15
+
16
+ var cons = ['true', 'false', 'on', 'off', 'yes', 'no'];
17
+ var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i');
18
+
19
+ return {
20
+ token: function(stream, state) {
21
+ var ch = stream.peek();
22
+ var esc = state.escaped;
23
+ state.escaped = false;
24
+ /* comments */
25
+ if (ch == "#" && (stream.pos == 0 || /\s/.test(stream.string.charAt(stream.pos - 1)))) {
26
+ stream.skipToEnd();
27
+ return "comment";
28
+ }
29
+
30
+ if (stream.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/))
31
+ return "string";
32
+
33
+ if (state.literal && stream.indentation() > state.keyCol) {
34
+ stream.skipToEnd(); return "string";
35
+ } else if (state.literal) { state.literal = false; }
36
+ if (stream.sol()) {
37
+ state.keyCol = 0;
38
+ state.pair = false;
39
+ state.pairStart = false;
40
+ /* document start */
41
+ if(stream.match(/---/)) { return "def"; }
42
+ /* document end */
43
+ if (stream.match(/\.\.\./)) { return "def"; }
44
+ /* array list item */
45
+ if (stream.match(/\s*-\s+/)) { return 'meta'; }
46
+ }
47
+ /* inline pairs/lists */
48
+ if (stream.match(/^(\{|\}|\[|\])/)) {
49
+ if (ch == '{')
50
+ state.inlinePairs++;
51
+ else if (ch == '}')
52
+ state.inlinePairs--;
53
+ else if (ch == '[')
54
+ state.inlineList++;
55
+ else
56
+ state.inlineList--;
57
+ return 'meta';
58
+ }
59
+
60
+ /* list seperator */
61
+ if (state.inlineList > 0 && !esc && ch == ',') {
62
+ stream.next();
63
+ return 'meta';
64
+ }
65
+ /* pairs seperator */
66
+ if (state.inlinePairs > 0 && !esc && ch == ',') {
67
+ state.keyCol = 0;
68
+ state.pair = false;
69
+ state.pairStart = false;
70
+ stream.next();
71
+ return 'meta';
72
+ }
73
+
74
+ /* start of value of a pair */
75
+ if (state.pairStart) {
76
+ /* block literals */
77
+ if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; };
78
+ /* references */
79
+ if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; }
80
+ /* numbers */
81
+ if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; }
82
+ if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; }
83
+ /* keywords */
84
+ if (stream.match(keywordRegex)) { return 'keyword'; }
85
+ }
86
+
87
+ /* pairs (associative arrays) -> key */
88
+ if (!state.pair && stream.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)) {
89
+ state.pair = true;
90
+ state.keyCol = stream.indentation();
91
+ return "atom";
92
+ }
93
+ if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }
94
+
95
+ /* nothing found, continue */
96
+ state.pairStart = false;
97
+ state.escaped = (ch == '\\');
98
+ stream.next();
99
+ return null;
100
+ },
101
+ startState: function() {
102
+ return {
103
+ pair: false,
104
+ pairStart: false,
105
+ keyCol: 0,
106
+ inlinePairs: 0,
107
+ inlineList: 0,
108
+ literal: false,
109
+ escaped: false
110
+ };
111
+ }
112
+ };
113
+ });
114
+
115
+ CodeMirror.defineMIME("text/x-yaml", "yaml");
116
+
117
+ });
@@ -0,0 +1,963 @@
1
+ /*
2
+ International Telephone Input v3.7.1
3
+ https://github.com/Bluefieldscom/intl-tel-input.git
4
+ */
5
+ // wrap in UMD - see https://github.com/umdjs/umd/blob/master/jqueryPlugin.js
6
+ (function(factory) {
7
+ if (typeof define === "function" && define.amd) {
8
+ define([ "jquery" ], function($) {
9
+ factory($, window, document);
10
+ });
11
+ } else {
12
+ factory(jQuery, window, document);
13
+ }
14
+ })(function($, window, document, undefined) {
15
+ "use strict";
16
+ var pluginName = "intlTelInput", id = 1, // give each instance it's own id for namespaced event handling
17
+ defaults = {
18
+ // automatically format the number according to the selected country
19
+ autoFormat: true,
20
+ // if there is just a dial code in the input: remove it on blur, and re-add it on focus
21
+ autoHideDialCode: true,
22
+ // default country
23
+ defaultCountry: "",
24
+ // token for ipinfo - required for https or over 1000 daily page views support
25
+ ipinfoToken: "",
26
+ // don't insert international dial codes
27
+ nationalMode: false,
28
+ // number type to use for placeholders
29
+ numberType: "MOBILE",
30
+ // display only these countries
31
+ onlyCountries: [],
32
+ // the countries at the top of the list. defaults to united states and united kingdom
33
+ preferredCountries: [ "us", "gb" ],
34
+ // make the dropdown the same width as the input
35
+ responsiveDropdown: false,
36
+ // specify the path to the libphonenumber script to enable validation/formatting
37
+ utilsScript: ""
38
+ }, keys = {
39
+ UP: 38,
40
+ DOWN: 40,
41
+ ENTER: 13,
42
+ ESC: 27,
43
+ PLUS: 43,
44
+ A: 65,
45
+ Z: 90,
46
+ ZERO: 48,
47
+ NINE: 57,
48
+ SPACE: 32,
49
+ BSPACE: 8,
50
+ DEL: 46,
51
+ CTRL: 17,
52
+ CMD1: 91,
53
+ // Chrome
54
+ CMD2: 224
55
+ }, windowLoaded = false;
56
+ // keep track of if the window.load event has fired as impossible to check after the fact
57
+ $(window).load(function() {
58
+ windowLoaded = true;
59
+ });
60
+ function Plugin(element, options) {
61
+ this.element = element;
62
+ this.options = $.extend({}, defaults, options);
63
+ this._defaults = defaults;
64
+ // event namespace
65
+ this.ns = "." + pluginName + id++;
66
+ // Chrome, FF, Safari, IE9+
67
+ this.isGoodBrowser = Boolean(element.setSelectionRange);
68
+ this.hadInitialPlaceholder = Boolean($(element).attr("placeholder"));
69
+ this._name = pluginName;
70
+ this.init();
71
+ }
72
+ Plugin.prototype = {
73
+ init: function() {
74
+ var that = this;
75
+ // if defaultCountry is set to "auto", we must do a lookup first
76
+ if (this.options.defaultCountry == "auto") {
77
+ // reset this in case lookup fails
78
+ this.options.defaultCountry = "";
79
+ var ipinfoURL = "//ipinfo.io";
80
+ if (this.options.ipinfoToken) {
81
+ ipinfoURL += "?token=" + this.options.ipinfoToken;
82
+ }
83
+ $.get(ipinfoURL, function(response) {
84
+ if (response && response.country) {
85
+ that.options.defaultCountry = response.country.toLowerCase();
86
+ }
87
+ }, "jsonp").always(function() {
88
+ that._ready();
89
+ });
90
+ } else {
91
+ this._ready();
92
+ }
93
+ },
94
+ _ready: function() {
95
+ // if in nationalMode, disable options relating to dial codes
96
+ if (this.options.nationalMode) {
97
+ this.options.autoHideDialCode = false;
98
+ }
99
+ // IE Mobile doesn't support the keypress event (see issue 68) which makes autoFormat impossible
100
+ if (navigator.userAgent.match(/IEMobile/i)) {
101
+ this.options.autoFormat = false;
102
+ }
103
+ // auto enable responsiveDropdown mode on small screens (dropdown is currently set to 430px in CSS)
104
+ if (window.innerWidth < 500) {
105
+ this.options.responsiveDropdown = true;
106
+ }
107
+ // process all the data: onlyCountries, preferredCountries etc
108
+ this._processCountryData();
109
+ // generate the markup
110
+ this._generateMarkup();
111
+ // set the initial state of the input value and the selected flag
112
+ this._setInitialState();
113
+ // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click
114
+ this._initListeners();
115
+ },
116
+ /********************
117
+ * PRIVATE METHODS
118
+ ********************/
119
+ // prepare all of the country data, including onlyCountries and preferredCountries options
120
+ _processCountryData: function() {
121
+ // set the instances country data objects
122
+ this._setInstanceCountryData();
123
+ // set the preferredCountries property
124
+ this._setPreferredCountries();
125
+ },
126
+ // add a country code to this.countryCodes
127
+ _addCountryCode: function(iso2, dialCode, priority) {
128
+ if (!(dialCode in this.countryCodes)) {
129
+ this.countryCodes[dialCode] = [];
130
+ }
131
+ var index = priority || 0;
132
+ this.countryCodes[dialCode][index] = iso2;
133
+ },
134
+ // process onlyCountries array if present, and generate the countryCodes map
135
+ _setInstanceCountryData: function() {
136
+ var i;
137
+ // process onlyCountries option
138
+ if (this.options.onlyCountries.length) {
139
+ this.countries = [];
140
+ for (i = 0; i < allCountries.length; i++) {
141
+ if ($.inArray(allCountries[i].iso2, this.options.onlyCountries) != -1) {
142
+ this.countries.push(allCountries[i]);
143
+ }
144
+ }
145
+ } else {
146
+ this.countries = allCountries;
147
+ }
148
+ // generate countryCodes map
149
+ this.countryCodes = {};
150
+ for (i = 0; i < this.countries.length; i++) {
151
+ var c = this.countries[i];
152
+ this._addCountryCode(c.iso2, c.dialCode, c.priority);
153
+ // area codes
154
+ if (c.areaCodes) {
155
+ for (var j = 0; j < c.areaCodes.length; j++) {
156
+ // full dial code is country code + dial code
157
+ this._addCountryCode(c.iso2, c.dialCode + c.areaCodes[j]);
158
+ }
159
+ }
160
+ }
161
+ },
162
+ // process preferred countries - iterate through the preferences,
163
+ // fetching the country data for each one
164
+ _setPreferredCountries: function() {
165
+ this.preferredCountries = [];
166
+ for (var i = 0; i < this.options.preferredCountries.length; i++) {
167
+ var countryCode = this.options.preferredCountries[i], countryData = this._getCountryData(countryCode, false, true);
168
+ if (countryData) {
169
+ this.preferredCountries.push(countryData);
170
+ }
171
+ }
172
+ },
173
+ // generate all of the markup for the plugin: the selected flag overlay, and the dropdown
174
+ _generateMarkup: function() {
175
+ // telephone input
176
+ this.telInput = $(this.element);
177
+ // containers (mostly for positioning)
178
+ this.telInput.wrap($("<div>", {
179
+ "class": "intl-tel-input"
180
+ }));
181
+ var flagsContainer = $("<div>", {
182
+ "class": "flag-dropdown"
183
+ }).insertAfter(this.telInput);
184
+ // currently selected flag (displayed to left of input)
185
+ var selectedFlag = $("<div>", {
186
+ "class": "selected-flag"
187
+ }).appendTo(flagsContainer);
188
+ this.selectedFlagInner = $("<div>", {
189
+ "class": "flag"
190
+ }).appendTo(selectedFlag);
191
+ // CSS triangle
192
+ $("<div>", {
193
+ "class": "arrow"
194
+ }).appendTo(this.selectedFlagInner);
195
+ // country list contains: preferred countries, then divider, then all countries
196
+ this.countryList = $("<ul>", {
197
+ "class": "country-list v-hide"
198
+ }).appendTo(flagsContainer);
199
+ if (this.preferredCountries.length) {
200
+ this._appendListItems(this.preferredCountries, "preferred");
201
+ $("<li>", {
202
+ "class": "divider"
203
+ }).appendTo(this.countryList);
204
+ }
205
+ this._appendListItems(this.countries, "");
206
+ // now we can grab the dropdown height, and hide it properly
207
+ this.dropdownHeight = this.countryList.outerHeight();
208
+ this.countryList.removeClass("v-hide").addClass("hide");
209
+ // and set the width
210
+ if (this.options.responsiveDropdown) {
211
+ this.countryList.outerWidth(this.telInput.outerWidth());
212
+ }
213
+ // this is useful in lots of places
214
+ this.countryListItems = this.countryList.children(".country");
215
+ },
216
+ // add a country <li> to the countryList <ul> container
217
+ _appendListItems: function(countries, className) {
218
+ // we create so many DOM elements, I decided it was faster to build a temp string
219
+ // and then add everything to the DOM in one go at the end
220
+ var tmp = "";
221
+ // for each country
222
+ for (var i = 0; i < countries.length; i++) {
223
+ var c = countries[i];
224
+ // open the list item
225
+ tmp += "<li class='country " + className + "' data-dial-code='" + c.dialCode + "' data-country-code='" + c.iso2 + "'>";
226
+ // add the flag
227
+ tmp += "<div class='flag " + c.iso2 + "'></div>";
228
+ // and the country name and dial code
229
+ tmp += "<span class='country-name'>" + c.name + "</span>";
230
+ tmp += "<span class='dial-code'>+" + c.dialCode + "</span>";
231
+ // close the list item
232
+ tmp += "</li>";
233
+ }
234
+ this.countryList.append(tmp);
235
+ },
236
+ // set the initial state of the input value and the selected flag
237
+ _setInitialState: function() {
238
+ var val = this.telInput.val();
239
+ // if there is a number, and it's valid, we can go ahead and set the flag, else fall back to default
240
+ if (this._getDialCode(val)) {
241
+ this._updateFlagFromNumber(val);
242
+ } else {
243
+ var defaultCountry;
244
+ // check the defaultCountry option, else fall back to the first in the list
245
+ if (this.options.defaultCountry) {
246
+ defaultCountry = this._getCountryData(this.options.defaultCountry, false, false);
247
+ } else {
248
+ defaultCountry = this.preferredCountries.length ? this.preferredCountries[0] : this.countries[0];
249
+ }
250
+ this._selectFlag(defaultCountry.iso2);
251
+ // if empty, insert the default dial code (this function will check !nationalMode and !autoHideDialCode)
252
+ if (!val) {
253
+ this._updateDialCode(defaultCountry.dialCode, false);
254
+ }
255
+ }
256
+ // format
257
+ if (val) {
258
+ // this wont be run after _updateDialCode as that's only called if no val
259
+ this._updateVal(val, false);
260
+ }
261
+ },
262
+ // initialise the main event listeners: input keyup, and click selected flag
263
+ _initListeners: function() {
264
+ var that = this;
265
+ this._initKeyListeners();
266
+ // autoFormat prevents the change event from firing, so we need to check for changes between focus and blur in order to manually trigger it
267
+ if (this.options.autoHideDialCode || this.options.autoFormat) {
268
+ this._initFocusListeners();
269
+ }
270
+ // hack for input nested inside label: clicking the selected-flag to open the dropdown would then automatically trigger a 2nd click on the input which would close it again
271
+ var label = this.telInput.closest("label");
272
+ if (label.length) {
273
+ label.on("click" + this.ns, function(e) {
274
+ // if the dropdown is closed, then focus the input, else ignore the click
275
+ if (that.countryList.hasClass("hide")) {
276
+ that.telInput.focus();
277
+ } else {
278
+ e.preventDefault();
279
+ }
280
+ });
281
+ }
282
+ // toggle country dropdown on click
283
+ var selectedFlag = this.selectedFlagInner.parent();
284
+ selectedFlag.on("click" + this.ns, function(e) {
285
+ // only intercept this event if we're opening the dropdown
286
+ // else let it bubble up to the top ("click-off-to-close" listener)
287
+ // we cannot just stopPropagation as it may be needed to close another instance
288
+ if (that.countryList.hasClass("hide") && !that.telInput.prop("disabled")) {
289
+ that._showDropdown();
290
+ }
291
+ });
292
+ // if the user has specified the path to the utils script, fetch it on window.load
293
+ if (this.options.utilsScript) {
294
+ // if the plugin is being initialised after the window.load event has already been fired
295
+ if (windowLoaded) {
296
+ this.loadUtils();
297
+ } else {
298
+ // wait until the load event so we don't block any other requests e.g. the flags image
299
+ $(window).load(function() {
300
+ that.loadUtils();
301
+ });
302
+ }
303
+ }
304
+ },
305
+ _initKeyListeners: function() {
306
+ var that = this;
307
+ if (this.options.autoFormat) {
308
+ // format number and update flag on keypress
309
+ // use keypress event as we want to ignore all input except for a select few keys,
310
+ // but we dont want to ignore the navigation keys like the arrows etc.
311
+ // NOTE: no point in refactoring this to only bind these listeners on focus/blur because then you would need to have those 2 listeners running the whole time anyway...
312
+ this.telInput.on("keypress" + this.ns, function(e) {
313
+ // 32 is space, and after that it's all chars (not meta/nav keys)
314
+ // this fix is needed for Firefox, which triggers keypress event for some meta/nav keys
315
+ // Update: also ignore if this is a metaKey e.g. FF and Safari trigger keypress on the v of Ctrl+v
316
+ // Update: also check that we have utils before we do any autoFormat stuff
317
+ if (e.which >= keys.SPACE && !e.metaKey && window.intlTelInputUtils) {
318
+ e.preventDefault();
319
+ // allowed keys are just numeric keys and plus
320
+ // we must allow plus for the case where the user does select-all and then hits plus to start typing a new number. we could refine this logic to first check that the selection contains a plus, but that wont work in old browsers, and I think it's overkill anyway
321
+ var isAllowedKey = e.which >= keys.ZERO && e.which <= keys.NINE || e.which == keys.PLUS, input = that.telInput[0], noSelection = that.isGoodBrowser && input.selectionStart == input.selectionEnd, max = that.telInput.attr("maxlength"), // assumes that if max exists, it is >0
322
+ isBelowMax = max ? that.telInput.val().length < max : true;
323
+ // first: ensure we dont go over maxlength. we must do this here to prevent adding digits in the middle of the number
324
+ // still reformat even if not an allowed key as they could by typing a formatting char, but ignore if there's a selection as doesn't make sense to replace selection with illegal char and then immediately remove it
325
+ if (isBelowMax && (isAllowedKey || noSelection)) {
326
+ var newChar = isAllowedKey ? String.fromCharCode(e.which) : null;
327
+ that._handleInputKey(newChar, true);
328
+ }
329
+ if (!isAllowedKey) {
330
+ that.telInput.trigger("invalidkey");
331
+ }
332
+ }
333
+ });
334
+ }
335
+ // handle keyup event
336
+ // for autoFormat: we use keyup to catch delete events after the fact
337
+ this.telInput.on("keyup" + this.ns, function(e) {
338
+ // the "enter" key event from selecting a dropdown item is triggered here on the input, because the document.keydown handler that initially handles that event triggers a focus on the input, and so the keyup for that same key event gets triggered here. weird, but just make sure we dont bother doing any re-formatting in this case (we've already done preventDefault in the keydown handler, so it wont actually submit the form or anything).
339
+ if (e.which == keys.ENTER) {} else if (that.options.autoFormat && window.intlTelInputUtils) {
340
+ var isCtrl = e.which == keys.CTRL || e.which == keys.CMD1 || e.which == keys.CMD2, input = that.telInput[0], // noSelection defaults to false for bad browsers, else would be reformatting on all ctrl keys e.g. select-all/copy
341
+ noSelection = that.isGoodBrowser && input.selectionStart == input.selectionEnd, // cursorAtEnd defaults to false for bad browsers else they would never get a reformat on delete
342
+ cursorAtEnd = that.isGoodBrowser && input.selectionStart == that.telInput.val().length;
343
+ // if delete in the middle: reformat with no suffix (no need to reformat if delete at end)
344
+ // if backspace: reformat with no suffix (need to reformat if at end to remove any lingering suffix - this is a feature)
345
+ // if ctrl and no selection (i.e. could have just been a paste): reformat (if cursorAtEnd: add suffix)
346
+ if (e.which == keys.DEL && !cursorAtEnd || e.which == keys.BSPACE || isCtrl && noSelection) {
347
+ // important to remember never to add suffix on any delete key as can fuck up in ie8 so you can never delete a formatting char at the end
348
+ that._handleInputKey(null, isCtrl && cursorAtEnd);
349
+ }
350
+ // prevent deleting the plus (if not in nationalMode)
351
+ if (!that.options.nationalMode) {
352
+ var val = that.telInput.val();
353
+ if (val.substr(0, 1) != "+") {
354
+ // newCursorPos is current pos + 1 to account for the plus we are about to add
355
+ var newCursorPos = that.isGoodBrowser ? input.selectionStart + 1 : 0;
356
+ that.telInput.val("+" + val);
357
+ if (that.isGoodBrowser) {
358
+ input.setSelectionRange(newCursorPos, newCursorPos);
359
+ }
360
+ }
361
+ }
362
+ } else {
363
+ // if no autoFormat, just update flag
364
+ that._updateFlagFromNumber(that.telInput.val());
365
+ }
366
+ });
367
+ },
368
+ // when autoFormat is enabled: handle various key events on the input: the 2 main situations are 1) adding a new number character, which will replace any selection, reformat, and try to preserve the cursor position. and 2) reformatting on backspace, or paste event
369
+ _handleInputKey: function(newNumericChar, addSuffix) {
370
+ var val = this.telInput.val(), newCursor = null, cursorAtEnd = false, // raw DOM element
371
+ input = this.telInput[0];
372
+ if (this.isGoodBrowser) {
373
+ var selectionEnd = input.selectionEnd, originalLen = val.length;
374
+ cursorAtEnd = selectionEnd == originalLen;
375
+ // if handling a new number character: insert it in the right place and calculate the new cursor position
376
+ if (newNumericChar) {
377
+ // replace any selection they may have made with the new char
378
+ val = val.substr(0, input.selectionStart) + newNumericChar + val.substring(selectionEnd, originalLen);
379
+ // if the cursor was not at the end then calculate it's new pos
380
+ if (!cursorAtEnd) {
381
+ newCursor = selectionEnd + (val.length - originalLen);
382
+ }
383
+ } else {
384
+ // here we're not handling a new char, we're just doing a re-format, but we still need to maintain the cursor position
385
+ newCursor = input.selectionStart;
386
+ }
387
+ } else if (newNumericChar) {
388
+ val += newNumericChar;
389
+ }
390
+ // update the number and flag
391
+ this.setNumber(val, addSuffix);
392
+ // update the cursor position
393
+ if (this.isGoodBrowser) {
394
+ // if it was at the end, keep it there
395
+ if (cursorAtEnd) {
396
+ newCursor = this.telInput.val().length;
397
+ }
398
+ input.setSelectionRange(newCursor, newCursor);
399
+ }
400
+ },
401
+ // listen for focus and blur
402
+ _initFocusListeners: function() {
403
+ var that = this;
404
+ if (this.options.autoHideDialCode) {
405
+ // mousedown decides where the cursor goes, so if we're focusing we must preventDefault as we'll be inserting the dial code, and we want the cursor to be at the end no matter where they click
406
+ this.telInput.on("mousedown" + this.ns, function(e) {
407
+ if (!that.telInput.is(":focus") && !that.telInput.val()) {
408
+ e.preventDefault();
409
+ // but this also cancels the focus, so we must trigger that manually
410
+ that.telInput.focus();
411
+ }
412
+ });
413
+ }
414
+ this.telInput.on("focus" + this.ns, function() {
415
+ var value = that.telInput.val();
416
+ // save this to compare on blur
417
+ that.telInput.data("focusVal", value);
418
+ if (that.options.autoHideDialCode) {
419
+ // on focus: if empty, insert the dial code for the currently selected flag
420
+ if (!value) {
421
+ that._updateVal("+" + that.selectedCountryData.dialCode, true);
422
+ // after auto-inserting a dial code, if the first key they hit is '+' then assume they are entering a new number, so remove the dial code. use keypress instead of keydown because keydown gets triggered for the shift key (required to hit the + key), and instead of keyup because that shows the new '+' before removing the old one
423
+ that.telInput.one("keypress.plus" + that.ns, function(e) {
424
+ if (e.which == keys.PLUS) {
425
+ // if autoFormat is enabled, this key event will have already have been handled by another keypress listener (hence we need to add the "+"). if disabled, it will be handled after this by a keyup listener (hence no need to add the "+").
426
+ var newVal = that.options.autoFormat && window.intlTelInputUtils ? "+" : "";
427
+ that.telInput.val(newVal);
428
+ }
429
+ });
430
+ // after tabbing in, make sure the cursor is at the end we must use setTimeout to get outside of the focus handler as it seems the selection happens after that
431
+ setTimeout(function() {
432
+ var input = that.telInput[0];
433
+ if (that.isGoodBrowser) {
434
+ var len = that.telInput.val().length;
435
+ input.setSelectionRange(len, len);
436
+ }
437
+ });
438
+ }
439
+ }
440
+ });
441
+ this.telInput.on("blur" + this.ns, function() {
442
+ if (that.options.autoHideDialCode) {
443
+ // on blur: if just a dial code then remove it
444
+ var value = that.telInput.val(), startsPlus = value.substr(0, 1) == "+";
445
+ if (startsPlus) {
446
+ var numeric = that._getNumeric(value);
447
+ // if just a plus, or if just a dial code
448
+ if (!numeric || that.selectedCountryData.dialCode == numeric) {
449
+ that.telInput.val("");
450
+ }
451
+ }
452
+ // remove the keypress listener we added on focus
453
+ that.telInput.off("keypress.plus" + that.ns);
454
+ }
455
+ // if autoFormat, we must manually trigger change event if value has changed
456
+ if (that.options.autoFormat && window.intlTelInputUtils && that.telInput.val() != that.telInput.data("focusVal")) {
457
+ that.telInput.trigger("change");
458
+ }
459
+ });
460
+ },
461
+ // extract the numeric digits from the given string
462
+ _getNumeric: function(s) {
463
+ return s.replace(/\D/g, "");
464
+ },
465
+ // show the dropdown
466
+ _showDropdown: function() {
467
+ this._setDropdownPosition();
468
+ // update highlighting and scroll to active list item
469
+ var activeListItem = this.countryList.children(".active");
470
+ this._highlightListItem(activeListItem);
471
+ // show it
472
+ this.countryList.removeClass("hide");
473
+ this._scrollTo(activeListItem);
474
+ // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
475
+ this._bindDropdownListeners();
476
+ // update the arrow
477
+ this.selectedFlagInner.children(".arrow").addClass("up");
478
+ },
479
+ // decide where to position dropdown (depends on position within viewport, and scroll)
480
+ _setDropdownPosition: function() {
481
+ var inputTop = this.telInput.offset().top, windowTop = $(window).scrollTop(), // dropdownFitsBelow = (dropdownBottom < windowBottom)
482
+ dropdownFitsBelow = inputTop + this.telInput.outerHeight() + this.dropdownHeight < windowTop + $(window).height(), dropdownFitsAbove = inputTop - this.dropdownHeight > windowTop;
483
+ // dropdownHeight - 1 for border
484
+ var cssTop = !dropdownFitsBelow && dropdownFitsAbove ? "-" + (this.dropdownHeight - 1) + "px" : "";
485
+ this.countryList.css("top", cssTop);
486
+ },
487
+ // we only bind dropdown listeners when the dropdown is open
488
+ _bindDropdownListeners: function() {
489
+ var that = this;
490
+ // when mouse over a list item, just highlight that one
491
+ // we add the class "highlight", so if they hit "enter" we know which one to select
492
+ this.countryList.on("mouseover" + this.ns, ".country", function(e) {
493
+ that._highlightListItem($(this));
494
+ });
495
+ // listen for country selection
496
+ this.countryList.on("click" + this.ns, ".country", function(e) {
497
+ that._selectListItem($(this));
498
+ });
499
+ // click off to close
500
+ // (except when this initial opening click is bubbling up)
501
+ // we cannot just stopPropagation as it may be needed to close another instance
502
+ var isOpening = true;
503
+ $("html").on("click" + this.ns, function(e) {
504
+ if (!isOpening) {
505
+ that._closeDropdown();
506
+ }
507
+ isOpening = false;
508
+ });
509
+ // listen for up/down scrolling, enter to select, or letters to jump to country name.
510
+ // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
511
+ // just hit down and hold it to scroll down (no keyup event).
512
+ // listen on the document because that's where key events are triggered if no input has focus
513
+ var query = "", queryTimer = null;
514
+ $(document).on("keydown" + this.ns, function(e) {
515
+ // prevent down key from scrolling the whole page,
516
+ // and enter key from submitting a form etc
517
+ e.preventDefault();
518
+ if (e.which == keys.UP || e.which == keys.DOWN) {
519
+ // up and down to navigate
520
+ that._handleUpDownKey(e.which);
521
+ } else if (e.which == keys.ENTER) {
522
+ // enter to select
523
+ that._handleEnterKey();
524
+ } else if (e.which == keys.ESC) {
525
+ // esc to close
526
+ that._closeDropdown();
527
+ } else if (e.which >= keys.A && e.which <= keys.Z || e.which == keys.SPACE) {
528
+ // upper case letters (note: keyup/keydown only return upper case letters)
529
+ // jump to countries that start with the query string
530
+ if (queryTimer) {
531
+ clearTimeout(queryTimer);
532
+ }
533
+ query += String.fromCharCode(e.which);
534
+ that._searchForCountry(query);
535
+ // if the timer hits 1 second, reset the query
536
+ queryTimer = setTimeout(function() {
537
+ query = "";
538
+ }, 1e3);
539
+ }
540
+ });
541
+ },
542
+ // highlight the next/prev item in the list (and ensure it is visible)
543
+ _handleUpDownKey: function(key) {
544
+ var current = this.countryList.children(".highlight").first();
545
+ var next = key == keys.UP ? current.prev() : current.next();
546
+ if (next.length) {
547
+ // skip the divider
548
+ if (next.hasClass("divider")) {
549
+ next = key == keys.UP ? next.prev() : next.next();
550
+ }
551
+ this._highlightListItem(next);
552
+ this._scrollTo(next);
553
+ }
554
+ },
555
+ // select the currently highlighted item
556
+ _handleEnterKey: function() {
557
+ var currentCountry = this.countryList.children(".highlight").first();
558
+ if (currentCountry.length) {
559
+ this._selectListItem(currentCountry);
560
+ }
561
+ },
562
+ // find the first list item whose name starts with the query string
563
+ _searchForCountry: function(query) {
564
+ for (var i = 0; i < this.countries.length; i++) {
565
+ if (this._startsWith(this.countries[i].name, query)) {
566
+ var listItem = this.countryList.children("[data-country-code=" + this.countries[i].iso2 + "]").not(".preferred");
567
+ // update highlighting and scroll
568
+ this._highlightListItem(listItem);
569
+ this._scrollTo(listItem, true);
570
+ break;
571
+ }
572
+ }
573
+ },
574
+ // check if (uppercase) string a starts with string b
575
+ _startsWith: function(a, b) {
576
+ return a.substr(0, b.length).toUpperCase() == b;
577
+ },
578
+ // update the input's value to the given val
579
+ // if autoFormat=true, format it first according to the country-specific formatting rules
580
+ _updateVal: function(val, addSuffix) {
581
+ var formatted;
582
+ if (this.options.autoFormat && window.intlTelInputUtils) {
583
+ formatted = intlTelInputUtils.formatNumber(val, this.selectedCountryData.iso2, addSuffix);
584
+ // ensure we dont go over maxlength. we must do this here to truncate any formatting suffix, and also handle paste events
585
+ var max = this.telInput.attr("maxlength");
586
+ if (max && formatted.length > max) {
587
+ formatted = formatted.substr(0, max);
588
+ }
589
+ } else {
590
+ // no autoFormat, so just insert the original value
591
+ formatted = val;
592
+ }
593
+ this.telInput.val(formatted);
594
+ },
595
+ // check if need to select a new flag based on the given number
596
+ _updateFlagFromNumber: function(number) {
597
+ // if we're in nationalMode and we're on US/Canada, make sure the number starts with a +1 so _getDialCode will be able to extract the area code
598
+ // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag from the number), that means we're initialising the plugin with a number that already has a dial code, so fine to ignore this bit
599
+ if (this.options.nationalMode && this.selectedCountryData && this.selectedCountryData.dialCode == "1" && number.substr(0, 1) != "+") {
600
+ number = "+1" + number;
601
+ }
602
+ // try and extract valid dial code from input
603
+ var dialCode = this._getDialCode(number);
604
+ if (dialCode) {
605
+ // check if one of the matching countries is already selected
606
+ var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = false;
607
+ if (this.selectedCountryData) {
608
+ for (var i = 0; i < countryCodes.length; i++) {
609
+ if (countryCodes[i] == this.selectedCountryData.iso2) {
610
+ alreadySelected = true;
611
+ }
612
+ }
613
+ }
614
+ // if a matching country is not already selected (or this is an unknown NANP area code): choose the first in the list
615
+ if (!alreadySelected || this._isUnknownNanp(number, dialCode)) {
616
+ // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first non-empty index
617
+ for (var j = 0; j < countryCodes.length; j++) {
618
+ if (countryCodes[j]) {
619
+ this._selectFlag(countryCodes[j]);
620
+ break;
621
+ }
622
+ }
623
+ }
624
+ }
625
+ },
626
+ // check if the given number contains an unknown area code from the North American Numbering Plan i.e. the only dialCode that could be extracted was +1 but the actual number's length is >=4
627
+ _isUnknownNanp: function(number, dialCode) {
628
+ return dialCode == "+1" && this._getNumeric(number).length >= 4;
629
+ },
630
+ // remove highlighting from other list items and highlight the given item
631
+ _highlightListItem: function(listItem) {
632
+ this.countryListItems.removeClass("highlight");
633
+ listItem.addClass("highlight");
634
+ },
635
+ // find the country data for the given country code
636
+ // the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array
637
+ _getCountryData: function(countryCode, ignoreOnlyCountriesOption, allowFail) {
638
+ var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries;
639
+ for (var i = 0; i < countryList.length; i++) {
640
+ if (countryList[i].iso2 == countryCode) {
641
+ return countryList[i];
642
+ }
643
+ }
644
+ if (allowFail) {
645
+ return null;
646
+ } else {
647
+ throw new Error("No country data for '" + countryCode + "'");
648
+ }
649
+ },
650
+ // select the given flag, update the placeholder and the active list item
651
+ _selectFlag: function(countryCode) {
652
+ // do this first as it will throw an error and stop if countryCode is invalid
653
+ this.selectedCountryData = this._getCountryData(countryCode, false, false);
654
+ this.selectedFlagInner.attr("class", "flag " + countryCode);
655
+ // update the selected country's title attribute
656
+ var title = this.selectedCountryData.name + ": +" + this.selectedCountryData.dialCode;
657
+ this.selectedFlagInner.parent().attr("title", title);
658
+ // and the input's placeholder
659
+ this._updatePlaceholder();
660
+ // update the active list item
661
+ var listItem = this.countryListItems.children(".flag." + countryCode).first().parent();
662
+ this.countryListItems.removeClass("active");
663
+ listItem.addClass("active");
664
+ },
665
+ // update the input placeholder to an example number from the currently selected country
666
+ _updatePlaceholder: function() {
667
+ if (window.intlTelInputUtils && !this.hadInitialPlaceholder) {
668
+ var iso2 = this.selectedCountryData.iso2, numberType = intlTelInputUtils.numberType[this.options.numberType || "FIXED_LINE"], placeholder = intlTelInputUtils.getExampleNumber(iso2, this.options.nationalMode, numberType);
669
+ this.telInput.attr("placeholder", placeholder);
670
+ }
671
+ },
672
+ // called when the user selects a list item from the dropdown
673
+ _selectListItem: function(listItem) {
674
+ // update selected flag and active list item
675
+ var countryCode = listItem.attr("data-country-code");
676
+ this._selectFlag(countryCode);
677
+ this._closeDropdown();
678
+ this._updateDialCode(listItem.attr("data-dial-code"), true);
679
+ // always fire the change event as even if nationalMode=true (and we haven't updated the input val), the system as a whole has still changed - see country-sync example. think of it as making a selection from a select element.
680
+ this.telInput.trigger("change");
681
+ // focus the input
682
+ this.telInput.focus();
683
+ },
684
+ // close the dropdown and unbind any listeners
685
+ _closeDropdown: function() {
686
+ this.countryList.addClass("hide");
687
+ // update the arrow
688
+ this.selectedFlagInner.children(".arrow").removeClass("up");
689
+ // unbind key events
690
+ $(document).off(this.ns);
691
+ // unbind click-off-to-close
692
+ $("html").off(this.ns);
693
+ // unbind hover and click listeners
694
+ this.countryList.off(this.ns);
695
+ },
696
+ // check if an element is visible within it's container, else scroll until it is
697
+ _scrollTo: function(element, middle) {
698
+ var container = this.countryList, containerHeight = container.height(), containerTop = container.offset().top, containerBottom = containerTop + containerHeight, elementHeight = element.outerHeight(), elementTop = element.offset().top, elementBottom = elementTop + elementHeight, newScrollTop = elementTop - containerTop + container.scrollTop(), middleOffset = containerHeight / 2 - elementHeight / 2;
699
+ if (elementTop < containerTop) {
700
+ // scroll up
701
+ if (middle) {
702
+ newScrollTop -= middleOffset;
703
+ }
704
+ container.scrollTop(newScrollTop);
705
+ } else if (elementBottom > containerBottom) {
706
+ // scroll down
707
+ if (middle) {
708
+ newScrollTop += middleOffset;
709
+ }
710
+ var heightDifference = containerHeight - elementHeight;
711
+ container.scrollTop(newScrollTop - heightDifference);
712
+ }
713
+ },
714
+ // replace any existing dial code with the new one (if not in nationalMode)
715
+ // also we need to know if we're focusing for a couple of reasons e.g. if so, we want to add any formatting suffix, also if the input is empty and we're not in nationalMode, then we want to insert the dial code
716
+ _updateDialCode: function(newDialCode, focusing) {
717
+ var inputVal = this.telInput.val(), newNumber;
718
+ // save having to pass this every time
719
+ newDialCode = "+" + newDialCode;
720
+ if (this.options.nationalMode && inputVal.substr(0, 1) != "+") {
721
+ // if nationalMode, we just want to re-format
722
+ newNumber = inputVal;
723
+ } else if (inputVal) {
724
+ // if the previous number contained a valid dial code, replace it
725
+ // (if more than just a plus character)
726
+ var prevDialCode = this._getDialCode(inputVal);
727
+ if (prevDialCode.length > 1) {
728
+ newNumber = inputVal.replace(prevDialCode, newDialCode);
729
+ } else {
730
+ // if the previous number didn't contain a dial code, we should persist it
731
+ var existingNumber = inputVal.substr(0, 1) != "+" ? $.trim(inputVal) : "";
732
+ newNumber = newDialCode + existingNumber;
733
+ }
734
+ } else {
735
+ newNumber = !this.options.autoHideDialCode || focusing ? newDialCode : "";
736
+ }
737
+ this._updateVal(newNumber, focusing);
738
+ },
739
+ // try and extract a valid international dial code from a full telephone number
740
+ // Note: returns the raw string inc plus character and any whitespace/dots etc
741
+ _getDialCode: function(number) {
742
+ var dialCode = "";
743
+ // only interested in international numbers (starting with a plus)
744
+ if (number.charAt(0) == "+") {
745
+ var numericChars = "";
746
+ // iterate over chars
747
+ for (var i = 0; i < number.length; i++) {
748
+ var c = number.charAt(i);
749
+ // if char is number
750
+ if ($.isNumeric(c)) {
751
+ numericChars += c;
752
+ // if current numericChars make a valid dial code
753
+ if (this.countryCodes[numericChars]) {
754
+ // store the actual raw string (useful for matching later)
755
+ dialCode = number.substr(0, i + 1);
756
+ }
757
+ // longest dial code is 4 chars
758
+ if (numericChars.length == 4) {
759
+ break;
760
+ }
761
+ }
762
+ }
763
+ }
764
+ return dialCode;
765
+ },
766
+ /********************
767
+ * PUBLIC METHODS
768
+ ********************/
769
+ // remove plugin
770
+ destroy: function() {
771
+ // make sure the dropdown is closed (and unbind listeners)
772
+ this._closeDropdown();
773
+ // key events, and focus/blur events if autoHideDialCode=true
774
+ this.telInput.off(this.ns);
775
+ // click event to open dropdown
776
+ this.selectedFlagInner.parent().off(this.ns);
777
+ // label click hack
778
+ this.telInput.closest("label").off(this.ns);
779
+ // remove markup
780
+ var container = this.telInput.parent();
781
+ container.before(this.telInput).remove();
782
+ },
783
+ // format the number to E164
784
+ getCleanNumber: function() {
785
+ if (window.intlTelInputUtils) {
786
+ return intlTelInputUtils.formatNumberE164(this.telInput.val(), this.selectedCountryData.iso2);
787
+ }
788
+ return "";
789
+ },
790
+ // get the type of the entered number e.g. landline/mobile
791
+ getNumberType: function() {
792
+ if (window.intlTelInputUtils) {
793
+ return intlTelInputUtils.getNumberType(this.telInput.val(), this.selectedCountryData.iso2);
794
+ }
795
+ return -99;
796
+ },
797
+ // get the country data for the currently selected flag
798
+ getSelectedCountryData: function() {
799
+ // if this is undefined, the plugin will return it's instance instead, so in that case an empty object makes more sense
800
+ return this.selectedCountryData || {};
801
+ },
802
+ // get the validation error
803
+ getValidationError: function() {
804
+ if (window.intlTelInputUtils) {
805
+ return intlTelInputUtils.getValidationError(this.telInput.val(), this.selectedCountryData.iso2);
806
+ }
807
+ return -99;
808
+ },
809
+ // validate the input val - assumes the global function isValidNumber (from utilsScript)
810
+ isValidNumber: function() {
811
+ var val = $.trim(this.telInput.val()), countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "", // libphonenumber allows alpha chars, but in order to allow that, we'd need a method to retrieve the processed number, with letters replaced with numbers
812
+ containsAlpha = /[a-zA-Z]/.test(val);
813
+ if (!containsAlpha && window.intlTelInputUtils) {
814
+ return intlTelInputUtils.isValidNumber(val, countryCode);
815
+ }
816
+ return false;
817
+ },
818
+ // load the utils script
819
+ loadUtils: function(path) {
820
+ var utilsScript = path || this.options.utilsScript;
821
+ if (!$.fn[pluginName].loadedUtilsScript && utilsScript) {
822
+ // don't do this twice! (dont just check if the global intlTelInputUtils exists as if init plugin multiple times in quick succession, it may not have finished loading yet)
823
+ $.fn[pluginName].loadedUtilsScript = true;
824
+ // dont use $.getScript as it prevents caching
825
+ $.ajax({
826
+ url: utilsScript,
827
+ success: function() {
828
+ // tell all instances the utils are ready
829
+ $(".intl-tel-input input").intlTelInput("utilsLoaded");
830
+ },
831
+ dataType: "script",
832
+ cache: true
833
+ });
834
+ }
835
+ },
836
+ // update the selected flag, and update the input val accordingly
837
+ selectCountry: function(countryCode) {
838
+ // check if already selected
839
+ if (!this.selectedFlagInner.hasClass(countryCode)) {
840
+ this._selectFlag(countryCode);
841
+ this._updateDialCode(this.selectedCountryData.dialCode, false);
842
+ }
843
+ },
844
+ // set the input value and update the flag
845
+ setNumber: function(number, addSuffix) {
846
+ // ensure starts with plus
847
+ if (!this.options.nationalMode && number.substr(0, 1) != "+") {
848
+ number = "+" + number;
849
+ }
850
+ // we must update the flag first, which updates this.selectedCountryData, which is used later for formatting the number before displaying it
851
+ this._updateFlagFromNumber(number);
852
+ this._updateVal(number, addSuffix);
853
+ },
854
+ // this is called when the utils are ready
855
+ utilsLoaded: function() {
856
+ // if autoFormat is enabled and there's an initial value in the input, then format it
857
+ if (this.options.autoFormat && this.telInput.val()) {
858
+ this._updateVal(this.telInput.val());
859
+ }
860
+ this._updatePlaceholder();
861
+ }
862
+ };
863
+ // adapted to allow public functions
864
+ // using https://github.com/jquery-boilerplate/jquery-boilerplate/wiki/Extending-jQuery-Boilerplate
865
+ $.fn[pluginName] = function(options) {
866
+ var args = arguments;
867
+ // Is the first parameter an object (options), or was omitted,
868
+ // instantiate a new instance of the plugin.
869
+ if (options === undefined || typeof options === "object") {
870
+ return this.each(function() {
871
+ if (!$.data(this, "plugin_" + pluginName)) {
872
+ $.data(this, "plugin_" + pluginName, new Plugin(this, options));
873
+ }
874
+ });
875
+ } else if (typeof options === "string" && options[0] !== "_" && options !== "init") {
876
+ // If the first parameter is a string and it doesn't start
877
+ // with an underscore or "contains" the `init`-function,
878
+ // treat this as a call to a public method.
879
+ // Cache the method call to make it possible to return a value
880
+ var returns;
881
+ this.each(function() {
882
+ var instance = $.data(this, "plugin_" + pluginName);
883
+ // Tests that there's already a plugin-instance
884
+ // and checks that the requested public method exists
885
+ if (instance instanceof Plugin && typeof instance[options] === "function") {
886
+ // Call the method of our plugin instance,
887
+ // and pass it the supplied arguments.
888
+ returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
889
+ }
890
+ // Allow instances to be destroyed via the 'destroy' method
891
+ if (options === "destroy") {
892
+ $.data(this, "plugin_" + pluginName, null);
893
+ }
894
+ });
895
+ // If the earlier cached method gives a value back return the value,
896
+ // otherwise return this to preserve chainability.
897
+ return returns !== undefined ? returns : this;
898
+ }
899
+ };
900
+ /********************
901
+ * STATIC METHODS
902
+ ********************/
903
+ // get the country data object
904
+ $.fn[pluginName].getCountryData = function() {
905
+ return allCountries;
906
+ };
907
+ // set the country data object
908
+ $.fn[pluginName].setCountryData = function(obj) {
909
+ allCountries = obj;
910
+ };
911
+ // Tell JSHint to ignore this warning: "character may get silently deleted by one or more browsers"
912
+ // jshint -W100
913
+ // Array of country objects for the flag dropdown.
914
+ // Each contains a name, country code (ISO 3166-1 alpha-2) and dial code.
915
+ // Originally from https://github.com/mledoze/countries
916
+ // then modified using the following JavaScript (NOW OUT OF DATE):
917
+ /*
918
+ var result = [];
919
+ _.each(countries, function(c) {
920
+ // ignore countries without a dial code
921
+ if (c.callingCode[0].length) {
922
+ result.push({
923
+ // var locals contains country names with localised versions in brackets
924
+ n: _.findWhere(locals, {
925
+ countryCode: c.cca2
926
+ }).name,
927
+ i: c.cca2.toLowerCase(),
928
+ d: c.callingCode[0]
929
+ });
930
+ }
931
+ });
932
+ JSON.stringify(result);
933
+ */
934
+ // then with a couple of manual re-arrangements to be alphabetical
935
+ // then changed Kazakhstan from +76 to +7
936
+ // and Vatican City from +379 to +39 (see issue 50)
937
+ // and Caribean Netherlands from +5997 to +599
938
+ // and Curacao from +5999 to +599
939
+ // Removed: Åland Islands, Christmas Island, Cocos Islands, Guernsey, Isle of Man, Jersey, Kosovo, Mayotte, Pitcairn Islands, South Georgia, Svalbard, Western Sahara
940
+ // Update: converted objects to arrays to save bytes!
941
+ // Update: added "priority" for countries with the same dialCode as others
942
+ // Update: added array of area codes for countries with the same dialCode as others
943
+ // So each country array has the following information:
944
+ // [
945
+ // Country name,
946
+ // iso2 code,
947
+ // International dial code,
948
+ // Order (if >1 country with same dial code),
949
+ // Area codes (if >1 country with same dial code)
950
+ // ]
951
+ var allCountries = [ [ "Afghanistan (‫افغانستان‬‎)", "af", "93" ], [ "Albania (Shqipëri)", "al", "355" ], [ "Algeria (‫الجزائر‬‎)", "dz", "213" ], [ "American Samoa", "as", "1684" ], [ "Andorra", "ad", "376" ], [ "Angola", "ao", "244" ], [ "Anguilla", "ai", "1264" ], [ "Antigua and Barbuda", "ag", "1268" ], [ "Argentina", "ar", "54" ], [ "Armenia (Հայաստան)", "am", "374" ], [ "Aruba", "aw", "297" ], [ "Australia", "au", "61" ], [ "Austria (Österreich)", "at", "43" ], [ "Azerbaijan (Azərbaycan)", "az", "994" ], [ "Bahamas", "bs", "1242" ], [ "Bahrain (‫البحرين‬‎)", "bh", "973" ], [ "Bangladesh (বাংলাদেশ)", "bd", "880" ], [ "Barbados", "bb", "1246" ], [ "Belarus (Беларусь)", "by", "375" ], [ "Belgium (België)", "be", "32" ], [ "Belize", "bz", "501" ], [ "Benin (Bénin)", "bj", "229" ], [ "Bermuda", "bm", "1441" ], [ "Bhutan (འབྲུག)", "bt", "975" ], [ "Bolivia", "bo", "591" ], [ "Bosnia and Herzegovina (Босна и Херцеговина)", "ba", "387" ], [ "Botswana", "bw", "267" ], [ "Brazil (Brasil)", "br", "55" ], [ "British Indian Ocean Territory", "io", "246" ], [ "British Virgin Islands", "vg", "1284" ], [ "Brunei", "bn", "673" ], [ "Bulgaria (България)", "bg", "359" ], [ "Burkina Faso", "bf", "226" ], [ "Burundi (Uburundi)", "bi", "257" ], [ "Cambodia (កម្ពុជា)", "kh", "855" ], [ "Cameroon (Cameroun)", "cm", "237" ], [ "Canada", "ca", "1", 1, [ "204", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905" ] ], [ "Cape Verde (Kabu Verdi)", "cv", "238" ], [ "Caribbean Netherlands", "bq", "599", 1 ], [ "Cayman Islands", "ky", "1345" ], [ "Central African Republic (République centrafricaine)", "cf", "236" ], [ "Chad (Tchad)", "td", "235" ], [ "Chile", "cl", "56" ], [ "China (中国)", "cn", "86" ], [ "Colombia", "co", "57" ], [ "Comoros (‫جزر القمر‬‎)", "km", "269" ], [ "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)", "cd", "243" ], [ "Congo (Republic) (Congo-Brazzaville)", "cg", "242" ], [ "Cook Islands", "ck", "682" ], [ "Costa Rica", "cr", "506" ], [ "Côte d’Ivoire", "ci", "225" ], [ "Croatia (Hrvatska)", "hr", "385" ], [ "Cuba", "cu", "53" ], [ "Curaçao", "cw", "599", 0 ], [ "Cyprus (Κύπρος)", "cy", "357" ], [ "Czech Republic (Česká republika)", "cz", "420" ], [ "Denmark (Danmark)", "dk", "45" ], [ "Djibouti", "dj", "253" ], [ "Dominica", "dm", "1767" ], [ "Dominican Republic (República Dominicana)", "do", "1", 2, [ "809", "829", "849" ] ], [ "Ecuador", "ec", "593" ], [ "Egypt (‫مصر‬‎)", "eg", "20" ], [ "El Salvador", "sv", "503" ], [ "Equatorial Guinea (Guinea Ecuatorial)", "gq", "240" ], [ "Eritrea", "er", "291" ], [ "Estonia (Eesti)", "ee", "372" ], [ "Ethiopia", "et", "251" ], [ "Falkland Islands (Islas Malvinas)", "fk", "500" ], [ "Faroe Islands (Føroyar)", "fo", "298" ], [ "Fiji", "fj", "679" ], [ "Finland (Suomi)", "fi", "358" ], [ "France", "fr", "33" ], [ "French Guiana (Guyane française)", "gf", "594" ], [ "French Polynesia (Polynésie française)", "pf", "689" ], [ "Gabon", "ga", "241" ], [ "Gambia", "gm", "220" ], [ "Georgia (საქართველო)", "ge", "995" ], [ "Germany (Deutschland)", "de", "49" ], [ "Ghana (Gaana)", "gh", "233" ], [ "Gibraltar", "gi", "350" ], [ "Greece (Ελλάδα)", "gr", "30" ], [ "Greenland (Kalaallit Nunaat)", "gl", "299" ], [ "Grenada", "gd", "1473" ], [ "Guadeloupe", "gp", "590", 0 ], [ "Guam", "gu", "1671" ], [ "Guatemala", "gt", "502" ], [ "Guinea (Guinée)", "gn", "224" ], [ "Guinea-Bissau (Guiné Bissau)", "gw", "245" ], [ "Guyana", "gy", "592" ], [ "Haiti", "ht", "509" ], [ "Honduras", "hn", "504" ], [ "Hong Kong (香港)", "hk", "852" ], [ "Hungary (Magyarország)", "hu", "36" ], [ "Iceland (Ísland)", "is", "354" ], [ "India (भारत)", "in", "91" ], [ "Indonesia", "id", "62" ], [ "Iran (‫ایران‬‎)", "ir", "98" ], [ "Iraq (‫العراق‬‎)", "iq", "964" ], [ "Ireland", "ie", "353" ], [ "Israel (‫ישראל‬‎)", "il", "972" ], [ "Italy (Italia)", "it", "39", 0 ], [ "Jamaica", "jm", "1876" ], [ "Japan (日本)", "jp", "81" ], [ "Jordan (‫الأردن‬‎)", "jo", "962" ], [ "Kazakhstan (Казахстан)", "kz", "7", 1 ], [ "Kenya", "ke", "254" ], [ "Kiribati", "ki", "686" ], [ "Kuwait (‫الكويت‬‎)", "kw", "965" ], [ "Kyrgyzstan (Кыргызстан)", "kg", "996" ], [ "Laos (ລາວ)", "la", "856" ], [ "Latvia (Latvija)", "lv", "371" ], [ "Lebanon (‫لبنان‬‎)", "lb", "961" ], [ "Lesotho", "ls", "266" ], [ "Liberia", "lr", "231" ], [ "Libya (‫ليبيا‬‎)", "ly", "218" ], [ "Liechtenstein", "li", "423" ], [ "Lithuania (Lietuva)", "lt", "370" ], [ "Luxembourg", "lu", "352" ], [ "Macau (澳門)", "mo", "853" ], [ "Macedonia (FYROM) (Македонија)", "mk", "389" ], [ "Madagascar (Madagasikara)", "mg", "261" ], [ "Malawi", "mw", "265" ], [ "Malaysia", "my", "60" ], [ "Maldives", "mv", "960" ], [ "Mali", "ml", "223" ], [ "Malta", "mt", "356" ], [ "Marshall Islands", "mh", "692" ], [ "Martinique", "mq", "596" ], [ "Mauritania (‫موريتانيا‬‎)", "mr", "222" ], [ "Mauritius (Moris)", "mu", "230" ], [ "Mexico (México)", "mx", "52" ], [ "Micronesia", "fm", "691" ], [ "Moldova (Republica Moldova)", "md", "373" ], [ "Monaco", "mc", "377" ], [ "Mongolia (Монгол)", "mn", "976" ], [ "Montenegro (Crna Gora)", "me", "382" ], [ "Montserrat", "ms", "1664" ], [ "Morocco (‫المغرب‬‎)", "ma", "212" ], [ "Mozambique (Moçambique)", "mz", "258" ], [ "Myanmar (Burma) (မြန်မာ)", "mm", "95" ], [ "Namibia (Namibië)", "na", "264" ], [ "Nauru", "nr", "674" ], [ "Nepal (नेपाल)", "np", "977" ], [ "Netherlands (Nederland)", "nl", "31" ], [ "New Caledonia (Nouvelle-Calédonie)", "nc", "687" ], [ "New Zealand", "nz", "64" ], [ "Nicaragua", "ni", "505" ], [ "Niger (Nijar)", "ne", "227" ], [ "Nigeria", "ng", "234" ], [ "Niue", "nu", "683" ], [ "Norfolk Island", "nf", "672" ], [ "North Korea (조선 민주주의 인민 공화국)", "kp", "850" ], [ "Northern Mariana Islands", "mp", "1670" ], [ "Norway (Norge)", "no", "47" ], [ "Oman (‫عُمان‬‎)", "om", "968" ], [ "Pakistan (‫پاکستان‬‎)", "pk", "92" ], [ "Palau", "pw", "680" ], [ "Palestine (‫فلسطين‬‎)", "ps", "970" ], [ "Panama (Panamá)", "pa", "507" ], [ "Papua New Guinea", "pg", "675" ], [ "Paraguay", "py", "595" ], [ "Peru (Perú)", "pe", "51" ], [ "Philippines", "ph", "63" ], [ "Poland (Polska)", "pl", "48" ], [ "Portugal", "pt", "351" ], [ "Puerto Rico", "pr", "1", 3, [ "787", "939" ] ], [ "Qatar (‫قطر‬‎)", "qa", "974" ], [ "Réunion (La Réunion)", "re", "262" ], [ "Romania (România)", "ro", "40" ], [ "Russia (Россия)", "ru", "7", 0 ], [ "Rwanda", "rw", "250" ], [ "Saint Barthélemy (Saint-Barthélemy)", "bl", "590", 1 ], [ "Saint Helena", "sh", "290" ], [ "Saint Kitts and Nevis", "kn", "1869" ], [ "Saint Lucia", "lc", "1758" ], [ "Saint Martin (Saint-Martin (partie française))", "mf", "590", 2 ], [ "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "pm", "508" ], [ "Saint Vincent and the Grenadines", "vc", "1784" ], [ "Samoa", "ws", "685" ], [ "San Marino", "sm", "378" ], [ "São Tomé and Príncipe (São Tomé e Príncipe)", "st", "239" ], [ "Saudi Arabia (‫المملكة العربية السعودية‬‎)", "sa", "966" ], [ "Senegal (Sénégal)", "sn", "221" ], [ "Serbia (Србија)", "rs", "381" ], [ "Seychelles", "sc", "248" ], [ "Sierra Leone", "sl", "232" ], [ "Singapore", "sg", "65" ], [ "Sint Maarten", "sx", "1721" ], [ "Slovakia (Slovensko)", "sk", "421" ], [ "Slovenia (Slovenija)", "si", "386" ], [ "Solomon Islands", "sb", "677" ], [ "Somalia (Soomaaliya)", "so", "252" ], [ "South Africa", "za", "27" ], [ "South Korea (대한민국)", "kr", "82" ], [ "South Sudan (‫جنوب السودان‬‎)", "ss", "211" ], [ "Spain (España)", "es", "34" ], [ "Sri Lanka (ශ්‍රී ලංකාව)", "lk", "94" ], [ "Sudan (‫السودان‬‎)", "sd", "249" ], [ "Suriname", "sr", "597" ], [ "Swaziland", "sz", "268" ], [ "Sweden (Sverige)", "se", "46" ], [ "Switzerland (Schweiz)", "ch", "41" ], [ "Syria (‫سوريا‬‎)", "sy", "963" ], [ "Taiwan (台灣)", "tw", "886" ], [ "Tajikistan", "tj", "992" ], [ "Tanzania", "tz", "255" ], [ "Thailand (ไทย)", "th", "66" ], [ "Timor-Leste", "tl", "670" ], [ "Togo", "tg", "228" ], [ "Tokelau", "tk", "690" ], [ "Tonga", "to", "676" ], [ "Trinidad and Tobago", "tt", "1868" ], [ "Tunisia (‫تونس‬‎)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks and Caicos Islands", "tc", "1649" ], [ "Tuvalu", "tv", "688" ], [ "U.S. Virgin Islands", "vi", "1340" ], [ "Uganda", "ug", "256" ], [ "Ukraine (Україна)", "ua", "380" ], [ "United Arab Emirates (‫الإمارات العربية المتحدة‬‎)", "ae", "971" ], [ "United Kingdom", "gb", "44" ], [ "United States", "us", "1", 0 ], [ "Uruguay", "uy", "598" ], [ "Uzbekistan (Oʻzbekiston)", "uz", "998" ], [ "Vanuatu", "vu", "678" ], [ "Vatican City (Città del Vaticano)", "va", "39", 1 ], [ "Venezuela", "ve", "58" ], [ "Vietnam (Việt Nam)", "vn", "84" ], [ "Wallis and Futuna", "wf", "681" ], [ "Yemen (‫اليمن‬‎)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ] ];
952
+ // loop over all of the countries above
953
+ for (var i = 0; i < allCountries.length; i++) {
954
+ var c = allCountries[i];
955
+ allCountries[i] = {
956
+ name: c[0],
957
+ iso2: c[1],
958
+ dialCode: c[2],
959
+ priority: c[3] || 0,
960
+ areaCodes: c[4] || null
961
+ };
962
+ }
963
+ });