PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/assets/js/pages/form_controls_extended.js

https://gitlab.com/Mustafiz.it12/Trainer_Registration
JavaScript | 489 lines | 261 code | 110 blank | 118 comment | 1 complexity | cb7caca168f8fa3304f9059db3a3cb0a MD5 | raw file
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Extended form controls
  4. *
  5. * Specific JS code additions for form_controls_extended.html page
  6. *
  7. * Version: 1.0
  8. * Latest update: Aug 1, 2015
  9. *
  10. * ---------------------------------------------------------------------------- */
  11. $(function() {
  12. // ========================================
  13. //
  14. // Components
  15. //
  16. // ========================================
  17. // Input formatter
  18. // ------------------------------
  19. // Date
  20. $('[name="format-date"]').formatter({
  21. pattern: '{{99}}/{{99}}/{{9999}}'
  22. });
  23. // Credit card
  24. $('[name="format-credit-card"]').formatter({
  25. pattern: '{{9999}} - {{9999}} - {{9999}} - {{9999}}'
  26. });
  27. // Phone #
  28. $('.format-phone-number').formatter({
  29. pattern: '({{999}}) {{999}} - {{9999}}'
  30. });
  31. // Phone ext
  32. $('[name="format-phone-ext"]').formatter({
  33. pattern: '({{999}}) {{999}} - {{9999}} / {{a999}}'
  34. });
  35. // Currency
  36. $('[name="format-currency"]').formatter({
  37. pattern: '${{999}}.{{99}}'
  38. });
  39. // International phone
  40. $('[name="format-international-phone"]').formatter({
  41. pattern: '+3{{9}} {{999}} {{999}} {{999}}'
  42. });
  43. // Tax id
  44. $('[name="format-tax-id"]').formatter({
  45. pattern: '{{99}} - {{9999999}}'
  46. });
  47. // SSN
  48. $('[name="format-ssn"]').formatter({
  49. pattern: '{{999}} - {{99}} - {{9999}}'
  50. });
  51. // Product key
  52. $('[name="format-product-key"]').formatter({
  53. pattern: '{{a*}} - {{999}} - {{a999}}'
  54. });
  55. // Order #
  56. $('[name="format-order-number"]').formatter({
  57. pattern: '{{aaa}} - {{999}} - {{***}}'
  58. });
  59. // ISBN
  60. $('[name="format-isbn"]').formatter({
  61. pattern: '{{999}} - {{99}} - {{999}} - {{9999}} - {{9}}'
  62. });
  63. // Persistent
  64. $('[name="format-persistent"]').formatter({
  65. pattern: '+3 ({{999}}) {{999}} - {{99}} - {{99}}'
  66. });
  67. // Elastic textarea
  68. // ------------------------------
  69. // Basic example
  70. $('.elastic').autosize();
  71. // Manual trigger
  72. $('.elastic-manual-trigger').on('click', function() {
  73. $('.elastic-manual').val('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sed ultricies nibh, sed faucibus eros. Vivamus tristique fringilla ante, vitae pellentesque quam porta vel. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nunc vehicula gravida nisl non imperdiet. Mauris felis odio, vehicula et laoreet non, tempor non enim. Cras convallis sapien hendrerit nibh sagittis sollicitudin. Fusce nec ultricies justo. Interdum et malesuada fames ac ante ipsum primis in faucibus. Fusce ac urna in dui consequat cursus vel sit amet mauris. Proin nec bibendum arcu. Aenean sit amet nisi mi. Sed non leo nisl. Mauris leo odio, ultricies interdum ornare ac, posuere eu risus. Suspendisse adipiscing sapien sit amet gravida sollicitudin. Maecenas laoreet velit in dui adipiscing, vel fermentum tellus ullamcorper. Nullam et mi rhoncus, tempus nulla sit amet, varius ipsum.').trigger('autosize.resize');
  74. });
  75. // Destroy method
  76. $('.elastic-destroy-trigger').on('click', function() {
  77. $('.elastic-destroy').trigger('autosize.destroy');
  78. });
  79. // Passy - password generator
  80. // ------------------------------
  81. // Input labels
  82. var $inputLabel = $('.label-indicator input');
  83. var $inputLabelAbsolute = $('.label-indicator-absolute input');
  84. var $inputGroup = $('.group-indicator input');
  85. // Output labels
  86. var $outputLabel = $('.label-indicator > span');
  87. var $outputLabelAbsolute = $('.label-indicator-absolute > span');
  88. var $outputGroup = $('.group-indicator > span');
  89. // Min input length
  90. $.passy.requirements.length.min = 4;
  91. // Strength meter
  92. var feedback = [
  93. {color: '#D55757', text: 'Weak', textColor: '#fff'},
  94. {color: '#EB7F5E', text: 'Normal', textColor: '#fff'},
  95. {color: '#3BA4CE', text: 'Good', textColor: '#fff'},
  96. {color: '#40B381', text: 'Strong', textColor: '#fff'}
  97. ];
  98. //
  99. // Setup strength meter
  100. //
  101. // Label indicator
  102. $inputLabel.passy(function(strength) {
  103. $outputLabel.text(feedback[strength].text);
  104. $outputLabel.css('background-color', feedback[strength].color).css('color', feedback[strength].textColor);
  105. });
  106. // Absolute positioned label
  107. $inputLabelAbsolute.passy(function(strength) {
  108. $outputLabelAbsolute.text(feedback[strength].text);
  109. $outputLabelAbsolute.css('background-color', feedback[strength].color).css('color', feedback[strength].textColor);
  110. });
  111. // Input group indicator
  112. $inputGroup.passy(function(strength) {
  113. $outputGroup.text(feedback[strength].text);
  114. $outputGroup.css('background-color', feedback[strength].color).css('border-color', feedback[strength].color).css('color', feedback[strength].textColor);
  115. });
  116. //
  117. // Initialize
  118. //
  119. // Label
  120. $('.generate-label').click(function() {
  121. $inputLabel.passy( 'generate', 12 );
  122. });
  123. // Absolute label
  124. $('.generate-label-absolute').click(function() {
  125. $inputLabelAbsolute.passy( 'generate', 10 );
  126. });
  127. // Group label
  128. $('.generate-group').click(function() {
  129. $inputGroup.passy( 'generate', 8 );
  130. });
  131. // Maxlength
  132. // ------------------------------
  133. // Basic example
  134. $('.maxlength').maxlength();
  135. // Threshold
  136. $('.maxlength-threshold').maxlength({
  137. threshold: 15
  138. });
  139. // Custom label color
  140. $('.maxlength-custom').maxlength({
  141. threshold: 10,
  142. warningClass: "label label-primary",
  143. limitReachedClass: "label label-danger"
  144. });
  145. // Options
  146. $('.maxlength-options').maxlength({
  147. alwaysShow: true,
  148. threshold: 10,
  149. warningClass: "label label-success",
  150. limitReachedClass: "label label-danger",
  151. separator: ' of ',
  152. preText: 'You have ',
  153. postText: ' chars remaining.',
  154. validate: true
  155. });
  156. // Always show label
  157. $('.maxlength-textarea').maxlength({
  158. alwaysShow: true
  159. });
  160. // Label position
  161. $('.maxlength-label-position').maxlength({
  162. alwaysShow: true,
  163. warningClass: "label label-danger",
  164. placement: 'top'
  165. });
  166. // ========================================
  167. //
  168. // Typeahead
  169. //
  170. // ========================================
  171. // Basic example
  172. // ------------------------------
  173. // Substring matches
  174. var substringMatcher = function(strs) {
  175. return function findMatches(q, cb) {
  176. var matches, substringRegex;
  177. // an array that will be populated with substring matches
  178. matches = [];
  179. // regex used to determine if a string contains the substring `q`
  180. substrRegex = new RegExp(q, 'i');
  181. // iterate through the pool of strings and for any string that
  182. // contains the substring `q`, add it to the `matches` array
  183. $.each(strs, function(i, str) {
  184. if (substrRegex.test(str)) {
  185. // the typeahead jQuery plugin expects suggestions to a
  186. // JavaScript object, refer to typeahead docs for more info
  187. matches.push({ value: str });
  188. }
  189. });
  190. cb(matches);
  191. };
  192. };
  193. // Add data
  194. var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
  195. 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
  196. 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
  197. 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
  198. 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
  199. 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
  200. 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
  201. 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
  202. 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
  203. ];
  204. // Initialize
  205. $('.typeahead-basic').typeahead(
  206. {
  207. hint: true,
  208. highlight: true,
  209. minLength: 1
  210. },
  211. {
  212. name: 'states',
  213. displayKey: 'value',
  214. source: substringMatcher(states)
  215. }
  216. );
  217. // Bloodhound engine
  218. // ------------------------------
  219. // Constructs the suggestion engine
  220. var states = new Bloodhound({
  221. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
  222. queryTokenizer: Bloodhound.tokenizers.whitespace,
  223. // `states` is an array of state names defined in "The Basics"
  224. local: $.map(states, function(state) { return { value: state }; })
  225. });
  226. // Initialize engine
  227. states.initialize();
  228. // Initialize
  229. $('.typeahead-bloodhound').typeahead(
  230. {
  231. hint: true,
  232. highlight: true,
  233. minLength: 1
  234. },
  235. {
  236. name: 'states',
  237. displayKey: 'value',
  238. // `ttAdapter` wraps the suggestion engine in an adapter that
  239. // is compatible with the typeahead jQuery plugin
  240. source: states.ttAdapter()
  241. }
  242. );
  243. // Prefetched data
  244. // ------------------------------
  245. // Constructs the suggestion engine
  246. var countries = new Bloodhound({
  247. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
  248. queryTokenizer: Bloodhound.tokenizers.whitespace,
  249. limit: 10,
  250. prefetch: {
  251. // url points to a json file that contains an array of country names, see
  252. // https://github.com/twitter/typeahead.js/blob/gh-pages/data/countries.json
  253. url: 'assets/demo_data/typeahead/countries.json',
  254. // the json file contains an array of strings, but the Bloodhound
  255. // suggestion engine expects JavaScript objects so this converts all of
  256. // those strings
  257. filter: function(list) {
  258. return $.map(list, function(country) { return { name: country }; });
  259. }
  260. }
  261. });
  262. // Initialize engine
  263. countries.initialize();
  264. // Passing in `null` for the `options` arguments will result in the default options being used
  265. $('.typeahead-prefetched').typeahead(null, {
  266. name: 'countries',
  267. displayKey: 'name',
  268. // `ttAdapter` wraps the suggestion engine in an adapter that
  269. // is compatible with the typeahead jQuery plugin
  270. source: countries.ttAdapter()
  271. });
  272. // Remote data
  273. // ------------------------------
  274. // Constructs the suggestion engine
  275. var bestPictures = new Bloodhound({
  276. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
  277. queryTokenizer: Bloodhound.tokenizers.whitespace,
  278. prefetch: 'assets/demo_data/typeahead/movies.json',
  279. remote: 'assets/json/queries/%QUERY.json'
  280. });
  281. // Initialize engine
  282. bestPictures.initialize();
  283. // Initialize
  284. $('.typeahead-remote').typeahead(null, {
  285. name: 'best-pictures',
  286. displayKey: 'value',
  287. source: bestPictures.ttAdapter()
  288. });
  289. // Custom templates
  290. // ------------------------------
  291. // Initialize with opitons
  292. $('.typeahead-custom-templates').typeahead(null, {
  293. name: 'best-pictures',
  294. displayKey: 'value',
  295. source: bestPictures.ttAdapter(),
  296. templates: {
  297. empty: [
  298. '<div class="empty-message">',
  299. 'unable to find any Best Picture winners that match the current query',
  300. '</div>'
  301. ].join('\n'),
  302. suggestion: Handlebars.compile('<p><strong>{{value}}</strong> – {{year}}</p>')
  303. }
  304. });
  305. // Multiple datasets
  306. // ------------------------------
  307. // Constructs the suggestion engine for 1st dataset
  308. var nbaTeams = new Bloodhound({
  309. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'),
  310. queryTokenizer: Bloodhound.tokenizers.whitespace,
  311. prefetch: 'assets/demo_data/typeahead/nba.json'
  312. });
  313. // Constructs the suggestion engine for 2nd dataset
  314. var nhlTeams = new Bloodhound({
  315. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'),
  316. queryTokenizer: Bloodhound.tokenizers.whitespace,
  317. prefetch: 'assets/demo_data/typeahead/nhl.json'
  318. });
  319. // Initialize engines
  320. nbaTeams.initialize();
  321. nhlTeams.initialize();
  322. // Initialize 1st dataset
  323. $('.typeahead-multiple-datasets').typeahead(
  324. {
  325. highlight: true
  326. },
  327. {
  328. name: 'group',
  329. displayKey: 'team',
  330. source: nbaTeams.ttAdapter(),
  331. templates: {
  332. header: '<span class="tt-heading">NBA Teams</span>'
  333. }
  334. },
  335. {
  336. name: 'group',
  337. displayKey: 'team',
  338. source: nhlTeams.ttAdapter(),
  339. templates: {
  340. header: '<span class="tt-heading">NHL Teams</span>'
  341. }
  342. }
  343. );
  344. // Dropdown height
  345. // ------------------------------
  346. // Initialize with options
  347. $('.typeahead-scrollable-menu').typeahead(null, {
  348. name: 'countries',
  349. displayKey: 'name',
  350. source: countries.ttAdapter()
  351. });
  352. // RTL support
  353. // ------------------------------
  354. // Constructs the suggestion engine
  355. var arabicPhrases = new Bloodhound({
  356. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('word'),
  357. queryTokenizer: Bloodhound.tokenizers.whitespace,
  358. local: [
  359. { word: "الإنجليزية" },
  360. { word: "نعم" },
  361. { word: "لا" },
  362. { word: "مرحبا" },
  363. { word: "أهلا" }
  364. ]
  365. });
  366. // Initialize engine
  367. arabicPhrases.initialize();
  368. // Initialize
  369. $('.typeahead-rtl-support').typeahead(
  370. {
  371. hint: false
  372. },
  373. {
  374. name: 'arabic-phrases',
  375. displayKey: 'word',
  376. source: arabicPhrases.ttAdapter()
  377. }
  378. );
  379. });