alpaca_advanced.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Alpaca - Advanced examples
  4. *
  5. * Demo JS code for alpaca_advanced.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var AlpacaAdvanced = function() {
  11. //
  12. // Setup module components
  13. //
  14. // Alpaca examples
  15. var _componentAlpacaAdvanced = function() {
  16. if (!$().alpaca) {
  17. console.warn('Warning - alpaca.min.js is not loaded.');
  18. return;
  19. }
  20. // Option trees
  21. // ------------------------------
  22. // Option tree field
  23. $('#alpaca-option-tree').alpaca({
  24. schema: {
  25. type: 'number',
  26. title: 'What number would like for your sports jersey?'
  27. },
  28. options: {
  29. type: 'optiontree',
  30. tree: {
  31. selectors: {
  32. sport: {
  33. schema: {
  34. type: 'string'
  35. },
  36. options: {
  37. type: 'select',
  38. noneLabel: 'Pick a Sport...'
  39. }
  40. },
  41. team: {
  42. schema: {
  43. type: 'string'
  44. },
  45. options: {
  46. type: 'select',
  47. noneLabel: 'Pick a Team...'
  48. }
  49. },
  50. player: {
  51. schema: {
  52. type: 'string'
  53. },
  54. options: {
  55. type: 'select',
  56. noneLabel: 'Pick a Player...'
  57. }
  58. }
  59. },
  60. order: ['sport', 'team', 'player'],
  61. data: [{
  62. value: 23,
  63. attributes: {
  64. sport: 'Basketball',
  65. team: 'Chicago Bulls',
  66. player: 'Michael Jordan'
  67. }
  68. }, {
  69. value: 33,
  70. attributes: {
  71. sport: 'Basketball',
  72. team: 'Chicago Bulls',
  73. player: 'Scotty Pippen'
  74. }
  75. }, {
  76. value: 4,
  77. attributes: {
  78. sport: 'Football',
  79. team: 'Green Bay Packers',
  80. player: 'Brett Favre'
  81. }
  82. }, {
  83. value: 19,
  84. attributes: {
  85. sport: 'Baseball',
  86. team: 'Milwaukee Brewers',
  87. player: 'Robin Yount'
  88. }
  89. }, {
  90. value: 99,
  91. attributes: {
  92. sport: 'Hockey',
  93. player: 'Wayne Gretzky'
  94. }
  95. }],
  96. horizontal: true
  97. },
  98. focus: false
  99. }
  100. });
  101. // Using connector
  102. $('#alpaca-option-tree-connector').alpaca({
  103. schemaSource: '../../../../global_assets/demo_data/alpaca/optiontree-custom-schema.json',
  104. optionsSource: '../../../../global_assets/demo_data/alpaca/optiontree-custom-options.json',
  105. options: {
  106. focus: false
  107. }
  108. });
  109. // Input types
  110. // ------------------------------
  111. // Lowercase
  112. $('#alpaca-lowercase').alpaca({
  113. data: 'Ice cream is wonderful.',
  114. schema: {
  115. format: 'lowercase'
  116. },
  117. options: {
  118. focus: false
  119. }
  120. });
  121. // Uppercase
  122. $('#alpaca-uppercase').alpaca({
  123. data: 'Ice cream is wonderful.',
  124. schema: {
  125. format: 'uppercase'
  126. },
  127. options: {
  128. focus: false
  129. }
  130. });
  131. // Search type
  132. $('#alpaca-search').alpaca({
  133. data: 'Where for art thou Romeo?',
  134. schema: {
  135. type: 'string'
  136. },
  137. options: {
  138. type: 'search',
  139. focus: false,
  140. label: 'Search'
  141. }
  142. });
  143. // Integer type
  144. $('#alpaca-integer').alpaca({
  145. data: 20,
  146. options: {
  147. type: 'integer',
  148. label: 'Age:',
  149. focus: false
  150. },
  151. schema: {
  152. minimum: 18,
  153. maximum: 25,
  154. exclusiveMinimum: true,
  155. exclusiveMaximum: true,
  156. divisibleBy: 2
  157. }
  158. });
  159. // Password type
  160. $('#alpaca-password').alpaca({
  161. data: 'password',
  162. schema: {
  163. format: 'password'
  164. },
  165. options: {
  166. focus: false
  167. }
  168. });
  169. // Email type
  170. $('#alpaca-email').alpaca({
  171. data: 'support',
  172. schema: {
  173. format: 'email'
  174. },
  175. options: {
  176. focus: false
  177. }
  178. });
  179. // IP address type
  180. $('#alpaca-ipv4').alpaca({
  181. data: '100.60',
  182. schema: {
  183. format: 'ip-address'
  184. },
  185. options: {
  186. focus: false
  187. }
  188. });
  189. // URL type
  190. $('#alpaca-url').alpaca({
  191. data: 'http://www.alpacajs.org',
  192. options: {
  193. type: 'url',
  194. focus: false
  195. },
  196. schema: {
  197. format: 'uri'
  198. }
  199. });
  200. // Currency type
  201. $('#alpaca-currency').alpaca({
  202. options: {
  203. type: 'currency',
  204. focus: false
  205. }
  206. });
  207. // Personal name type
  208. $('#alpaca-name').alpaca({
  209. data: 'Oscar Zoroaster Phadrig Isaac Norman Henkel Emmannuel Ambroise Diggs',
  210. options: {
  211. type: 'personalname',
  212. focus: false
  213. }
  214. });
  215. // File inputs
  216. // ------------------------------
  217. // Basic file input
  218. $('#alpaca-file').alpaca({
  219. data: '',
  220. options: {
  221. type: 'file',
  222. label: 'Ice Cream Photo:',
  223. helper: 'Pick your favorite ice cream picture.',
  224. focus: false
  225. },
  226. schema: {
  227. type: 'string',
  228. format: 'uri'
  229. }
  230. });
  231. // Static mode
  232. $('#alpaca-file-static').alpaca({
  233. data: '/abc.html',
  234. options: {
  235. type: 'file',
  236. label: 'Ice Cream Photo:',
  237. helper: 'Pick your favorite ice cream picture.',
  238. focus: false
  239. },
  240. schema: {
  241. type: 'string',
  242. format: 'uri'
  243. },
  244. view: 'bootstrap-display'
  245. });
  246. // Selector helpers
  247. // ------------------------------
  248. // Country selector
  249. $('#alpaca-country').alpaca({
  250. options: {
  251. type: 'country',
  252. focus: false
  253. }
  254. });
  255. // State selector
  256. $('#alpaca-state').alpaca({
  257. options: {
  258. type: 'state',
  259. focus: false
  260. }
  261. });
  262. // CKEditor
  263. // ------------------------------
  264. // DOM elements
  265. var $alpacaEditorLTR = $('#alpaca-ckeditor-full'),
  266. $alpacaEditorRTL = $('#alpaca-ckeditor-full-rtl');
  267. // Full featured CKEditor
  268. if (!$alpacaEditorLTR.length == 0) {
  269. $alpacaEditorLTR.alpaca({
  270. data: 'Ice cream is a <b>frozen</b> dessert usually made from <i>dairy products</i>, such as milk and cream, and often combined with fruits or other ingredients and flavors.',
  271. options: {
  272. type: 'ckeditor'
  273. }
  274. });
  275. }
  276. // [RTL] Full featured CKEditor
  277. if (!$alpacaEditorRTL.length == 0) {
  278. $alpacaEditorRTL.alpaca({
  279. data: 'Ice cream is a <b>frozen</b> dessert usually made from <i>dairy products</i>, such as milk and cream, and often combined with fruits or other ingredients and flavors.',
  280. options: {
  281. type: 'ckeditor',
  282. ckeditor: {
  283. customConfig: 'config_rtl.js'
  284. }
  285. }
  286. });
  287. }
  288. };
  289. // Alpaca with Select2
  290. var _componentAlpacaAdvancedSelect2 = function() {
  291. if (!$().alpaca || !$().select2) {
  292. console.warn('Warning - alpaca.min.js and/or select2.min.js is not loaded.');
  293. return;
  294. }
  295. // Searchable country selector
  296. $('#alpaca-country-search').alpaca({
  297. options: {
  298. type: 'country',
  299. id: 'country-search',
  300. focus: false
  301. },
  302. postRender: function() {
  303. $('#country-search').select2();
  304. }
  305. });
  306. // Searchable state selector
  307. $('#alpaca-state-search').alpaca({
  308. options: {
  309. type: 'state',
  310. id: 'state-search',
  311. focus: false
  312. },
  313. postRender: function() {
  314. $('#state-search').select2();
  315. }
  316. });
  317. };
  318. // Alpaca with Uniform
  319. var _componentAlpacaAdvancedUniform = function() {
  320. if (!$().alpaca || !$().uniform) {
  321. console.warn('Warning - alpaca.min.js and/or uniform.min.js is not loaded.');
  322. return;
  323. }
  324. // Styled file input
  325. $('#alpaca-file-styled').alpaca({
  326. data: '',
  327. options: {
  328. type: 'file',
  329. label: 'Ice Cream Photo:',
  330. helper: 'Pick your favorite ice cream picture.',
  331. id: 'file-styled',
  332. focus: false
  333. },
  334. schema: {
  335. type: 'string',
  336. format: 'uri'
  337. },
  338. postRender: function() {
  339. $('#file-styled').uniform({
  340. fileButtonClass: 'action btn bg-blue'
  341. });
  342. }
  343. });
  344. // Disabled file input
  345. $('#alpaca-file-disabled').alpaca({
  346. data: '',
  347. options: {
  348. type: 'file',
  349. label: 'Ice Cream Photo:',
  350. helper: 'Pick your favorite ice cream picture.',
  351. disabled: true,
  352. id: 'file-styled-disabled',
  353. focus: false
  354. },
  355. schema: {
  356. type: 'string',
  357. format: 'uri'
  358. },
  359. postRender: function() {
  360. $('#file-styled-disabled').uniform({
  361. fileButtonClass: 'action btn bg-blue'
  362. });
  363. }
  364. });
  365. };
  366. //
  367. // Return objects assigned to module
  368. //
  369. return {
  370. init: function() {
  371. _componentAlpacaAdvanced();
  372. _componentAlpacaAdvancedSelect2();
  373. _componentAlpacaAdvancedUniform();
  374. }
  375. }
  376. }();
  377. // Initialize module
  378. // ------------------------------
  379. document.addEventListener('DOMContentLoaded', function() {
  380. AlpacaAdvanced.init();
  381. });