advanced.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define("/forms/advanced", ["jquery", "Site"], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory(require("jquery"), require("Site"));
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory(global.jQuery, global.Site);
  11. global.formsAdvanced = mod.exports;
  12. }
  13. })(this, function (_jquery, _Site) {
  14. "use strict";
  15. _jquery = babelHelpers.interopRequireDefault(_jquery);
  16. (0, _jquery.default)(document).ready(function ($$$1) {
  17. (0, _Site.run)();
  18. }); // Example Reset Current
  19. // ---------------------
  20. (function () {
  21. // Reset Current
  22. (0, _jquery.default)('#exampleTimeButton').on('click', function () {
  23. (0, _jquery.default)('#inputTextCurrent').timepicker('setTime', new Date());
  24. });
  25. })(); // Example inline datepicker
  26. // ---------------------
  27. (function () {
  28. // Reset Current
  29. (0, _jquery.default)('#inlineDatepicker').datepicker();
  30. (0, _jquery.default)("#inlineDatepicker").on("changeDate", function (event) {
  31. (0, _jquery.default)("#inputHiddenInline").val((0, _jquery.default)("#inlineDatepicker").datepicker('getFormattedDate'));
  32. });
  33. })(); // Example Tokenfield With Typeahead
  34. // ---------------------------------
  35. (function () {
  36. var engine = new Bloodhound({
  37. local: [{
  38. value: 'red'
  39. }, {
  40. value: 'blue'
  41. }, {
  42. value: 'green'
  43. }, {
  44. value: 'yellow'
  45. }, {
  46. value: 'violet'
  47. }, {
  48. value: 'brown'
  49. }, {
  50. value: 'purple'
  51. }, {
  52. value: 'black'
  53. }, {
  54. value: 'white'
  55. }],
  56. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
  57. queryTokenizer: Bloodhound.tokenizers.whitespace
  58. }); // engine.initialize();
  59. (0, _jquery.default)('#inputTokenfieldTypeahead').tokenfield({
  60. typeahead: [null, {
  61. name: 'engine',
  62. displayKey: 'value',
  63. source: engine.ttAdapter()
  64. }]
  65. });
  66. })(); // Example Tokenfield Events
  67. // -------------------------
  68. (function () {
  69. (0, _jquery.default)('#inputTokenfieldEvents').on('tokenfield:createtoken', function (e) {
  70. var data = e.attrs.value.split('|');
  71. e.attrs.value = data[1] || data[0];
  72. e.attrs.label = data[1] ? data[0] + ' (' + data[1] + ')' : data[0];
  73. }).on('tokenfield:createdtoken', function (e) {
  74. // Über-simplistic e-mail validation
  75. var re = /\S+@\S+\.\S+/;
  76. var valid = re.test(e.attrs.value);
  77. if (!valid) {
  78. (0, _jquery.default)(e.relatedTarget).addClass('invalid');
  79. }
  80. }).on('tokenfield:edittoken', function (e) {
  81. if (e.attrs.label !== e.attrs.value) {
  82. var label = e.attrs.label.split(' (');
  83. e.attrs.value = label[0] + '|' + e.attrs.value;
  84. }
  85. }).on('tokenfield:removedtoken', function (e) {
  86. if (e.attrs.length > 1) {
  87. var values = _jquery.default.map(e.attrs, function (attrs) {
  88. return attrs.value;
  89. });
  90. alert(e.attrs.length + ' tokens removed! Token values were: ' + values.join(', '));
  91. } else {
  92. alert('Token removed! Token value was: ' + e.attrs.value);
  93. }
  94. }).tokenfield();
  95. })(); // Example Tags Input Objects as tags
  96. // ----------------------------------
  97. (function () {
  98. var cities = new Bloodhound({
  99. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'),
  100. queryTokenizer: Bloodhound.tokenizers.whitespace,
  101. prefetch: '../../assets/data/cities.json'
  102. });
  103. cities.initialize();
  104. var options = _jquery.default.extend(true, {}, Plugin.getDefaults("tagsinput"), {
  105. itemValue: 'value',
  106. itemText: 'text',
  107. typeaheadjs: [{
  108. hint: true,
  109. highlight: true,
  110. minLength: 1
  111. }, {
  112. name: 'cities',
  113. displayKey: 'text',
  114. source: cities.ttAdapter()
  115. }]
  116. });
  117. var $input = (0, _jquery.default)('#inputTagsObject');
  118. $input.tagsinput(options);
  119. $input.tagsinput('add', {
  120. "value": 1,
  121. "text": "Amsterdam",
  122. "continent": "Europe"
  123. });
  124. $input.tagsinput('add', {
  125. "value": 4,
  126. "text": "Washington",
  127. "continent": "America"
  128. });
  129. $input.tagsinput('add', {
  130. "value": 7,
  131. "text": "Sydney",
  132. "continent": "Australia"
  133. });
  134. $input.tagsinput('add', {
  135. "value": 10,
  136. "text": "Beijing",
  137. "continent": "Asia"
  138. });
  139. $input.tagsinput('add', {
  140. "value": 13,
  141. "text": "Cairo",
  142. "continent": "Africa"
  143. });
  144. })(); // Example Tags Input Categorizing
  145. // -------------------------------
  146. (function () {
  147. var cities = new Bloodhound({
  148. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'),
  149. queryTokenizer: Bloodhound.tokenizers.whitespace,
  150. prefetch: '../../assets/data/cities.json'
  151. });
  152. cities.initialize();
  153. var options = _jquery.default.extend(true, {}, Plugin.getDefaults("tagsinput"), {
  154. tagClass: function tagClass(item) {
  155. switch (item.continent) {
  156. case 'Europe':
  157. return 'badge badge-primary';
  158. case 'America':
  159. return 'badge badge-danger';
  160. case 'Australia':
  161. return 'badge badge-success';
  162. case 'Africa':
  163. return 'badge badge-default';
  164. case 'Asia':
  165. return 'badge badge-warning';
  166. }
  167. },
  168. itemValue: 'value',
  169. itemText: 'text',
  170. typeaheadjs: [{
  171. hint: true,
  172. highlight: true,
  173. minLength: 1
  174. }, {
  175. name: 'cities',
  176. displayKey: 'text',
  177. source: cities.ttAdapter()
  178. }]
  179. });
  180. var $input = (0, _jquery.default)('#inputTagsCategorizing');
  181. $input.tagsinput(options);
  182. $input.tagsinput('add', {
  183. "value": 1,
  184. "text": "Amsterdam",
  185. "continent": "Europe"
  186. });
  187. $input.tagsinput('add', {
  188. "value": 4,
  189. "text": "Washington",
  190. "continent": "America"
  191. });
  192. $input.tagsinput('add', {
  193. "value": 7,
  194. "text": "Sydney",
  195. "continent": "Australia"
  196. });
  197. $input.tagsinput('add', {
  198. "value": 10,
  199. "text": "Beijing",
  200. "continent": "Asia"
  201. });
  202. $input.tagsinput('add', {
  203. "value": 13,
  204. "text": "Cairo",
  205. "continent": "Africa"
  206. });
  207. })(); // Example AsSpinner
  208. // -----------------
  209. (function () {
  210. // Custom Format
  211. var options = _jquery.default.extend({}, Plugin.getDefaults("asSpinner"), {
  212. format: function format(value) {
  213. return value + '%';
  214. }
  215. });
  216. (0, _jquery.default)('#inputSpinnerCustomFormat').asSpinner(options);
  217. })(); // Example Multi-Select
  218. // --------------------
  219. (function () {
  220. // for multi-select public methods example
  221. (0, _jquery.default)('.multi-select-methods').multiSelect();
  222. (0, _jquery.default)('#buttonSelectAll').click(function () {
  223. (0, _jquery.default)('.multi-select-methods').multiSelect('select_all');
  224. return false;
  225. });
  226. (0, _jquery.default)('#buttonDeselectAll').click(function () {
  227. (0, _jquery.default)('.multi-select-methods').multiSelect('deselect_all');
  228. return false;
  229. });
  230. (0, _jquery.default)('#buttonSelectSome').click(function () {
  231. (0, _jquery.default)('.multi-select-methods').multiSelect('select', ['Idaho', 'Montana', 'Arkansas']);
  232. return false;
  233. });
  234. (0, _jquery.default)('#buttonDeselectSome').click(function () {
  235. (0, _jquery.default)('.multi-select-methods').multiSelect('select', ['Idaho', 'Montana', 'Arkansas']);
  236. return false;
  237. });
  238. (0, _jquery.default)('#buttonRefresh').on('click', function () {
  239. (0, _jquery.default)('.multi-select-methods').multiSelect('refresh');
  240. return false;
  241. });
  242. (0, _jquery.default)('#buttonAdd').on('click', function () {
  243. (0, _jquery.default)('.multi-select-methods').multiSelect('addOption', {
  244. value: 42,
  245. text: 'test 42',
  246. index: 0
  247. });
  248. return false;
  249. });
  250. })(); // Example Typeahead
  251. // -----------------
  252. (function () {
  253. var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']; // basic & Styled
  254. // --------------
  255. (function () {
  256. var substringMatcher = function substringMatcher(strs) {
  257. return function findMatches(q, cb) {
  258. var matches, substrRegex; // an array that will be populated with substring matches
  259. matches = []; // regex used to determine if a string contains the substring `q`
  260. substrRegex = new RegExp(q, 'i'); // iterate through the pool of strings and for any string that
  261. // contains the substring `q`, add it to the `matches` array
  262. _jquery.default.each(strs, function (i, str) {
  263. if (substrRegex.test(str)) {
  264. matches.push(str);
  265. }
  266. });
  267. cb(matches);
  268. };
  269. };
  270. (0, _jquery.default)('#exampleTypeaheadBasic, #exampleTypeaheadStyle').typeahead({
  271. hint: true,
  272. highlight: true,
  273. minLength: 1
  274. }, {
  275. name: 'states',
  276. source: substringMatcher(states)
  277. });
  278. })(); // bloodhound
  279. // ----------
  280. (function () {
  281. var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']; // constructs the suggestion engine
  282. var state = new Bloodhound({
  283. datumTokenizer: Bloodhound.tokenizers.whitespace,
  284. queryTokenizer: Bloodhound.tokenizers.whitespace,
  285. // `states` is an array of state names defined in "The Basics"
  286. local: states
  287. });
  288. (0, _jquery.default)('#exampleTypeaheadBloodhound').typeahead({
  289. hint: true,
  290. highlight: true,
  291. minLength: 1
  292. }, {
  293. name: 'states',
  294. source: state
  295. });
  296. })(); // Prefetch typeahead
  297. // ----------------
  298. (function () {
  299. var countries = new Bloodhound({
  300. datumTokenizer: Bloodhound.tokenizers.whitespace,
  301. queryTokenizer: Bloodhound.tokenizers.whitespace,
  302. // url points to a json file that contains an array of country names, see
  303. // https://github.com/twitter/typeahead.js/blob/gh-pages/data/countries.json
  304. prefetch: '../../assets/data/countries.json'
  305. }); // passing in `null` for the `options` arguments will result in the default
  306. // options being used
  307. (0, _jquery.default)('#exampleTypeaheadPrefetch').typeahead(null, {
  308. name: 'countries',
  309. source: countries
  310. });
  311. })();
  312. })();
  313. });