123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- /* ------------------------------------------------------------------------------
- *
- * # Alpaca - Advanced examples
- *
- * Demo JS code for alpaca_advanced.html page
- *
- * ---------------------------------------------------------------------------- */
- // Setup module
- // ------------------------------
- var AlpacaAdvanced = function() {
- //
- // Setup module components
- //
- // Alpaca examples
- var _componentAlpacaAdvanced = function() {
- if (!$().alpaca) {
- console.warn('Warning - alpaca.min.js is not loaded.');
- return;
- }
- // Option trees
- // ------------------------------
- // Option tree field
- $('#alpaca-option-tree').alpaca({
- schema: {
- type: 'number',
- title: 'What number would like for your sports jersey?'
- },
- options: {
- type: 'optiontree',
- tree: {
- selectors: {
- sport: {
- schema: {
- type: 'string'
- },
- options: {
- type: 'select',
- noneLabel: 'Pick a Sport...'
- }
- },
- team: {
- schema: {
- type: 'string'
- },
- options: {
- type: 'select',
- noneLabel: 'Pick a Team...'
- }
- },
- player: {
- schema: {
- type: 'string'
- },
- options: {
- type: 'select',
- noneLabel: 'Pick a Player...'
- }
- }
- },
- order: ['sport', 'team', 'player'],
- data: [{
- value: 23,
- attributes: {
- sport: 'Basketball',
- team: 'Chicago Bulls',
- player: 'Michael Jordan'
- }
- }, {
- value: 33,
- attributes: {
- sport: 'Basketball',
- team: 'Chicago Bulls',
- player: 'Scotty Pippen'
- }
- }, {
- value: 4,
- attributes: {
- sport: 'Football',
- team: 'Green Bay Packers',
- player: 'Brett Favre'
- }
- }, {
- value: 19,
- attributes: {
- sport: 'Baseball',
- team: 'Milwaukee Brewers',
- player: 'Robin Yount'
- }
- }, {
- value: 99,
- attributes: {
- sport: 'Hockey',
- player: 'Wayne Gretzky'
- }
- }],
- horizontal: true
- },
- focus: false
- }
- });
- // Using connector
- $('#alpaca-option-tree-connector').alpaca({
- schemaSource: '../../../../global_assets/demo_data/alpaca/optiontree-custom-schema.json',
- optionsSource: '../../../../global_assets/demo_data/alpaca/optiontree-custom-options.json',
- options: {
- focus: false
- }
- });
- // Input types
- // ------------------------------
- // Lowercase
- $('#alpaca-lowercase').alpaca({
- data: 'Ice cream is wonderful.',
- schema: {
- format: 'lowercase'
- },
- options: {
- focus: false
- }
- });
- // Uppercase
- $('#alpaca-uppercase').alpaca({
- data: 'Ice cream is wonderful.',
- schema: {
- format: 'uppercase'
- },
- options: {
- focus: false
- }
- });
- // Search type
- $('#alpaca-search').alpaca({
- data: 'Where for art thou Romeo?',
- schema: {
- type: 'string'
- },
- options: {
- type: 'search',
- focus: false,
- label: 'Search'
- }
- });
- // Integer type
- $('#alpaca-integer').alpaca({
- data: 20,
- options: {
- type: 'integer',
- label: 'Age:',
- focus: false
- },
- schema: {
- minimum: 18,
- maximum: 25,
- exclusiveMinimum: true,
- exclusiveMaximum: true,
- divisibleBy: 2
- }
- });
- // Password type
- $('#alpaca-password').alpaca({
- data: 'password',
- schema: {
- format: 'password'
- },
- options: {
- focus: false
- }
- });
- // Email type
- $('#alpaca-email').alpaca({
- data: 'support',
- schema: {
- format: 'email'
- },
- options: {
- focus: false
- }
- });
- // IP address type
- $('#alpaca-ipv4').alpaca({
- data: '100.60',
- schema: {
- format: 'ip-address'
- },
- options: {
- focus: false
- }
- });
- // URL type
- $('#alpaca-url').alpaca({
- data: 'http://www.alpacajs.org',
- options: {
- type: 'url',
- focus: false
- },
- schema: {
- format: 'uri'
- }
- });
- // Currency type
- $('#alpaca-currency').alpaca({
- options: {
- type: 'currency',
- focus: false
- }
- });
- // Personal name type
- $('#alpaca-name').alpaca({
- data: 'Oscar Zoroaster Phadrig Isaac Norman Henkel Emmannuel Ambroise Diggs',
- options: {
- type: 'personalname',
- focus: false
- }
- });
- // File inputs
- // ------------------------------
- // Basic file input
- $('#alpaca-file').alpaca({
- data: '',
- options: {
- type: 'file',
- label: 'Ice Cream Photo:',
- helper: 'Pick your favorite ice cream picture.',
- focus: false
- },
- schema: {
- type: 'string',
- format: 'uri'
- }
- });
- // Static mode
- $('#alpaca-file-static').alpaca({
- data: '/abc.html',
- options: {
- type: 'file',
- label: 'Ice Cream Photo:',
- helper: 'Pick your favorite ice cream picture.',
- focus: false
- },
- schema: {
- type: 'string',
- format: 'uri'
- },
- view: 'bootstrap-display'
- });
- // Selector helpers
- // ------------------------------
- // Country selector
- $('#alpaca-country').alpaca({
- options: {
- type: 'country',
- focus: false
- }
- });
- // State selector
- $('#alpaca-state').alpaca({
- options: {
- type: 'state',
- focus: false
- }
- });
- // CKEditor
- // ------------------------------
- // DOM elements
- var $alpacaEditorLTR = $('#alpaca-ckeditor-full'),
- $alpacaEditorRTL = $('#alpaca-ckeditor-full-rtl');
- // Full featured CKEditor
- if (!$alpacaEditorLTR.length == 0) {
- $alpacaEditorLTR.alpaca({
- 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.',
- options: {
- type: 'ckeditor'
- }
- });
- }
- // [RTL] Full featured CKEditor
- if (!$alpacaEditorRTL.length == 0) {
- $alpacaEditorRTL.alpaca({
- 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.',
- options: {
- type: 'ckeditor',
- ckeditor: {
- customConfig: 'config_rtl.js'
- }
- }
- });
- }
- };
- // Alpaca with Select2
- var _componentAlpacaAdvancedSelect2 = function() {
- if (!$().alpaca || !$().select2) {
- console.warn('Warning - alpaca.min.js and/or select2.min.js is not loaded.');
- return;
- }
- // Searchable country selector
- $('#alpaca-country-search').alpaca({
- options: {
- type: 'country',
- id: 'country-search',
- focus: false
- },
- postRender: function() {
- $('#country-search').select2();
- }
- });
- // Searchable state selector
- $('#alpaca-state-search').alpaca({
- options: {
- type: 'state',
- id: 'state-search',
- focus: false
- },
- postRender: function() {
- $('#state-search').select2();
- }
- });
- };
- // Alpaca with Uniform
- var _componentAlpacaAdvancedUniform = function() {
- if (!$().alpaca || !$().uniform) {
- console.warn('Warning - alpaca.min.js and/or uniform.min.js is not loaded.');
- return;
- }
- // Styled file input
- $('#alpaca-file-styled').alpaca({
- data: '',
- options: {
- type: 'file',
- label: 'Ice Cream Photo:',
- helper: 'Pick your favorite ice cream picture.',
- id: 'file-styled',
- focus: false
- },
- schema: {
- type: 'string',
- format: 'uri'
- },
- postRender: function() {
- $('#file-styled').uniform({
- fileButtonClass: 'action btn bg-blue'
- });
- }
- });
- // Disabled file input
- $('#alpaca-file-disabled').alpaca({
- data: '',
- options: {
- type: 'file',
- label: 'Ice Cream Photo:',
- helper: 'Pick your favorite ice cream picture.',
- disabled: true,
- id: 'file-styled-disabled',
- focus: false
- },
- schema: {
- type: 'string',
- format: 'uri'
- },
- postRender: function() {
- $('#file-styled-disabled').uniform({
- fileButtonClass: 'action btn bg-blue'
- });
- }
- });
- };
- //
- // Return objects assigned to module
- //
- return {
- init: function() {
- _componentAlpacaAdvanced();
- _componentAlpacaAdvancedSelect2();
- _componentAlpacaAdvancedUniform();
- }
- }
- }();
- // Initialize module
- // ------------------------------
- document.addEventListener('DOMContentLoaded', function() {
- AlpacaAdvanced.init();
- });
|