lato_view 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/lato_view/icons/_artist.svg +0 -0
  3. data/app/assets/images/lato_view/icons/_artwork.svg +0 -0
  4. data/app/assets/images/lato_view/icons/_calendar.svg +0 -0
  5. data/app/assets/images/lato_view/icons/_clients.svg +0 -0
  6. data/app/assets/images/lato_view/icons/_home.svg +0 -0
  7. data/app/assets/images/lato_view/icons/_list.svg +0 -0
  8. data/app/assets/images/lato_view/icons/_magni-glass.svg +0 -0
  9. data/app/assets/images/lato_view/icons/_percentage.svg +0 -0
  10. data/app/assets/images/lato_view/icons/_sweet.svg +0 -0
  11. data/app/assets/images/lato_view/icons/_users.svg +0 -0
  12. data/app/assets/javascripts/lato_view/application.js +8 -6
  13. data/app/assets/javascripts/lato_view/build/ActionBar.js +0 -0
  14. data/app/assets/javascripts/lato_view/build/ConfirmationPopup.js +52 -0
  15. data/app/assets/javascripts/lato_view/build/Dropdown.js +0 -0
  16. data/app/assets/javascripts/lato_view/build/FormManager.js +170 -50
  17. data/app/assets/javascripts/lato_view/build/Step.js +169 -0
  18. data/app/assets/javascripts/lato_view/build/Util.js +25 -9
  19. data/app/assets/javascripts/lato_view/build/Validator.js +70 -48
  20. data/app/assets/stylesheets/lato_view/config/_config.scss +4 -4
  21. data/app/assets/stylesheets/lato_view/config/templates/_base-template.scss +22 -0
  22. data/app/assets/stylesheets/lato_view/config/templates/_black-template.scss +26 -6
  23. data/app/assets/stylesheets/lato_view/config/templates/_feral-template.scss +190 -0
  24. data/app/assets/stylesheets/lato_view/config/templates/_mauve-template.scss +178 -0
  25. data/app/assets/stylesheets/lato_view/config/templates/_orange-template.scss +184 -0
  26. data/app/assets/stylesheets/lato_view/modules/_arranger.scss +0 -0
  27. data/app/assets/stylesheets/lato_view/modules/_button-group.scss +0 -0
  28. data/app/assets/stylesheets/lato_view/modules/_buttons.scss +13 -7
  29. data/app/assets/stylesheets/lato_view/modules/_confirmation-popup.scss +63 -0
  30. data/app/assets/stylesheets/lato_view/modules/_dropdown.scss +0 -0
  31. data/app/assets/stylesheets/lato_view/modules/_form-controls.scss +11 -2
  32. data/app/assets/stylesheets/lato_view/modules/_modules.scss +2 -0
  33. data/app/assets/stylesheets/lato_view/modules/_pagination.scss +0 -0
  34. data/app/assets/stylesheets/lato_view/modules/_sidebar.scss +2 -2
  35. data/app/assets/stylesheets/lato_view/modules/_status.scss +0 -0
  36. data/app/assets/stylesheets/lato_view/modules/_step.scss +53 -0
  37. data/app/assets/stylesheets/lato_view/modules/_wyswyg.scss +4 -0
  38. data/app/assets/stylesheets/lato_view/views/_admin.scss +4 -1
  39. data/app/assets/stylesheets/lato_view/views/_login.scss +5 -4
  40. data/app/cells/lato_view/cells_v1/buttongroup/cell.rb +0 -0
  41. data/app/cells/lato_view/cells_v1/buttongroup/views/show.html.erb +0 -0
  42. data/app/cells/lato_view/cells_v1/dropdown/cell.rb +0 -0
  43. data/app/cells/lato_view/cells_v1/dropdown/views/show.html.erb +0 -0
  44. data/app/cells/lato_view/cells_v1/input/cell.rb +21 -1
  45. data/app/cells/lato_view/cells_v1/input/views/date.html.erb +1 -1
  46. data/app/cells/lato_view/cells_v1/input/views/number.html.erb +8 -3
  47. data/app/cells/lato_view/cells_v1/input/views/select.html.erb +1 -1
  48. data/app/cells/lato_view/cells_v1/input/views/time.html.erb +0 -0
  49. data/app/cells/lato_view/component/button/cell.rb +4 -2
  50. data/app/cells/lato_view/component/button/views/show.html.erb +1 -1
  51. data/app/cells/lato_view/component/buttongroup/cell.rb +0 -0
  52. data/app/cells/lato_view/component/buttongroup/views/show.html.erb +0 -0
  53. data/app/cells/lato_view/component/buttonprompt/cell.rb +38 -0
  54. data/app/cells/lato_view/component/buttonprompt/views/show.html.erb +2 -0
  55. data/app/cells/lato_view/component/dropdown/cell.rb +0 -0
  56. data/app/cells/lato_view/component/dropdown/views/show.html.erb +0 -0
  57. data/app/cells/lato_view/component/form/cell.rb +0 -0
  58. data/app/cells/lato_view/component/form/views/open.html.erb +0 -0
  59. data/app/cells/lato_view/component/form/views/show.html.erb +0 -0
  60. data/app/cells/lato_view/component/searchbar/cell.rb +0 -0
  61. data/app/cells/lato_view/component/searchbar/views/show.html.erb +0 -0
  62. data/app/cells/lato_view/input/checkbox/cell.rb +7 -2
  63. data/app/cells/lato_view/input/checkbox/views/show.html.erb +2 -2
  64. data/app/cells/lato_view/input/date/cell.rb +4 -2
  65. data/app/cells/lato_view/input/date/views/show.html.erb +1 -1
  66. data/app/cells/lato_view/input/doubleselect/cell.rb +72 -0
  67. data/app/cells/lato_view/input/doubleselect/views/show.html.erb +90 -0
  68. data/app/cells/lato_view/input/editor/cell.rb +0 -0
  69. data/app/cells/lato_view/input/editor/views/show.html.erb +0 -0
  70. data/app/cells/lato_view/input/email/cell.rb +0 -0
  71. data/app/cells/lato_view/input/email/views/show.html.erb +0 -0
  72. data/app/cells/lato_view/input/file/cell.rb +0 -0
  73. data/app/cells/lato_view/input/file/views/show.html.erb +0 -0
  74. data/app/cells/lato_view/input/map/cell.rb +54 -0
  75. data/app/cells/lato_view/input/map/views/show.html.erb +103 -0
  76. data/app/cells/lato_view/input/nselect/cell.rb +47 -0
  77. data/app/cells/lato_view/input/nselect/views/show.html.erb +15 -0
  78. data/app/cells/lato_view/input/number/cell.rb +4 -2
  79. data/app/cells/lato_view/input/number/views/show.html.erb +6 -8
  80. data/app/cells/lato_view/input/password/cell.rb +0 -0
  81. data/app/cells/lato_view/input/password/views/show.html.erb +0 -0
  82. data/app/cells/lato_view/input/radio/cell.rb +0 -0
  83. data/app/cells/lato_view/input/radio/views/show.html.erb +0 -0
  84. data/app/cells/lato_view/input/select/cell.rb +3 -2
  85. data/app/cells/lato_view/input/select/views/show.html.erb +2 -2
  86. data/app/cells/lato_view/input/text/cell.rb +1 -1
  87. data/app/cells/lato_view/input/text/views/show.html.erb +3 -3
  88. data/app/cells/lato_view/input/textarea/cell.rb +0 -0
  89. data/app/cells/lato_view/input/textarea/views/show.html.erb +1 -4
  90. data/app/cells/lato_view/input/time/cell.rb +0 -0
  91. data/app/cells/lato_view/input/time/views/show.html.erb +0 -0
  92. data/app/cells/lato_view/layout/actionbar/cell.rb +0 -0
  93. data/app/cells/lato_view/layout/actionbar/views/show.html.erb +0 -0
  94. data/app/cells/lato_view/layout/block/cell.rb +0 -0
  95. data/app/cells/lato_view/layout/index/cell.rb +0 -0
  96. data/app/cells/lato_view/layout/index/views/head.html.erb +0 -0
  97. data/app/cells/lato_view/layout/index/views/rows.html.erb +29 -17
  98. data/app/cells/lato_view/layout/step/cell.rb +50 -0
  99. data/app/cells/lato_view/layout/tablerows/cell.rb +23 -0
  100. data/app/cells/lato_view/layout/tablerows/views/show.html.erb +13 -0
  101. data/app/controllers/lato_view/assets_controller.rb +0 -0
  102. data/app/views/lato_view/develop/home.html.erb +74 -0
  103. data/app/views/lato_view/icons/_artist.svg +0 -0
  104. data/app/views/lato_view/icons/_artwork.svg +0 -0
  105. data/app/views/lato_view/icons/_calendar.svg +0 -0
  106. data/app/views/lato_view/icons/_clients.svg +0 -0
  107. data/app/views/lato_view/icons/_home.svg +0 -0
  108. data/app/views/lato_view/icons/_list.svg +0 -0
  109. data/app/views/lato_view/icons/_magni-glass.svg +0 -0
  110. data/app/views/lato_view/icons/_percentage.svg +0 -0
  111. data/app/views/lato_view/icons/_sweet.svg +0 -0
  112. data/app/views/lato_view/icons/_users.svg +0 -0
  113. data/app/views/lato_view/layout/_prompt.html.erb +11 -0
  114. data/app/views/layouts/lato_layout.html.erb +12 -6
  115. data/config/example.yml +4 -0
  116. data/config/initializers/lists.rb +1 -1
  117. data/config/initializers/ram.rb +1 -0
  118. data/lang/default.yml +3 -0
  119. data/lang/en.yml +3 -0
  120. data/lib/lato_view/interface/assets.rb +16 -0
  121. data/lib/lato_view/interface/images.rb +0 -0
  122. data/lib/lato_view/interface/themes.rb +0 -0
  123. metadata +22 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84fe9458f67c6a7d42884bc6878c3e1b29f57f9d
4
- data.tar.gz: 2cc251a98d9955684311112a1b85aa19a38b2a59
3
+ metadata.gz: 7de827c8effaf615e2e52a32fedd15769c1ab11c
4
+ data.tar.gz: b120b8cc929c762d8d4d6279feb474734df757cc
5
5
  SHA512:
6
- metadata.gz: 4c64a97ece2ca62bb977c5630cb4e9b77ba20c9dedb08095427ae4339ad1eb56a14008528dedc3c472ac66e59604b0f370381fdeb2d3ddf59d2f49be241adddb
7
- data.tar.gz: 475f29ca8304ca7f424853cde250346458d3d2638bc45d3c3b1ebfc0bb185af5e993768083fcfd721cb64673a360b68c41e660fd917d56736413c9ab636c0d27
6
+ metadata.gz: 5acfec86c023097390ee87356968c7a9950be7ab6820bf0b1ca763bc4dc093cac2bbb5ebac3e2e02659a24dc8887b8b0f695f2aca882a1f23c07a38905ec345e
7
+ data.tar.gz: 6f7398e0ef507222e6be9abc0f606f7e4ebd9dbcae8ff4c34fb592755e0b7a226217f6581813912eba71be7abb6e26913235ce99ff9925ab31f6cc4c71c2fa42
@@ -29,14 +29,14 @@
29
29
  //= require lato_view/build/Navigation
30
30
  //= require lato_view/build/ActionBar
31
31
  //= require lato_view/build/Flash
32
+ //= require lato_view/build/ConfirmationPopup
33
+ //= require lato_view/build/Step
32
34
 
33
35
  var Application = (function($) {
34
36
 
35
- var onResize = function() {
36
- $(window).on('resize', function() {
37
- Navigation.manageSidebarDropdown();
38
- });
39
- };
37
+ var onResize = Util.debounce(function() {
38
+ Navigation.manageSidebarDropdown();
39
+ }, 250);
40
40
 
41
41
  var init = function() {
42
42
  $(document).on('ready', function() {
@@ -49,13 +49,15 @@ var Application = (function($) {
49
49
  Navigation.init();
50
50
  //ActionBar.init();
51
51
  Flash.init();
52
+ Step.init();
52
53
  FormManager.init();
54
+ ConfirmationPopup.init();
53
55
  $('.editor').trumbowyg({
54
56
  svgPath: '/ui/icons.svg'
55
57
  });
56
58
 
57
59
  // Functions executed on resize
58
- onResize();
60
+ $(window).on('resize', onResize());
59
61
  });
60
62
  };
61
63
 
@@ -0,0 +1,52 @@
1
+ var ConfirmationPopup = (function($) {
2
+ 'use strict';
3
+
4
+ var _manageConfirmationPopup = function() {
5
+ $(document).on('click', '.js-confirmation-popup-trigger', function(event) {
6
+ var $this = $('.js-confirmation-popup-trigger');
7
+
8
+ var $confirmationPopup = $('.js-confirmation-popup');
9
+ var $confirmationPopupQuestion = $confirmationPopup.find('.js-confirmation-popup-question');
10
+ var $confirmationPopupAnswerOk = $confirmationPopup.find('.js-confirmation-popup-answer-success');
11
+ var $confirmationPopupAnswerNope = $confirmationPopup.find('.js-confirmation-popup-answer-nope');
12
+
13
+ var location = $this.attr('href');
14
+ var data_method = $this.data( "fake-method");
15
+
16
+ var messageOk = $this.data('popup-ok');
17
+ var messageNo = $this.data('popup-no');
18
+ var messageText = $this.data('popup-text');
19
+
20
+ // Set property data
21
+ $confirmationPopupQuestion.text(messageText);
22
+ $confirmationPopupAnswerOk.text(messageOk);
23
+ $confirmationPopupAnswerOk.attr('href', location);
24
+ $confirmationPopupAnswerOk.attr( "data-method", data_method);
25
+ $confirmationPopupAnswerNope.text(messageNo);
26
+
27
+ event.preventDefault();
28
+
29
+
30
+ setTimeout(function() {
31
+ $('body').addClass('is-confirmation-popup-open');
32
+ }, 300);
33
+
34
+ });
35
+ };
36
+
37
+ var _nopePopup = function() {
38
+ $(document).on('click', '.js-confirmation-popup-answer-nope', function() {
39
+ $('body').removeClass('is-confirmation-popup-open');
40
+ });
41
+ };
42
+
43
+ var init = function() {
44
+ _manageConfirmationPopup();
45
+ _nopePopup();
46
+ };
47
+
48
+ return {
49
+ init: init
50
+ };
51
+
52
+ })(jQuery);
@@ -3,20 +3,129 @@ var FormManager = (function($) {
3
3
 
4
4
  // Activate selectize.js module
5
5
  var _manageSelect = function() {
6
- $('.select').selectize({
7
- hideSelected: 'true' // for multiple-select working
6
+
7
+ var $inputNSelects = $('.input-nselect');
8
+ var $select = $('.select');
9
+ var $selectCreate = $('.select-create');
10
+
11
+ $select.selectize({
12
+ hideSelected: 'true'
8
13
  });
14
+
15
+ $selectCreate.selectize({
16
+ hideSelected: 'true',
17
+ create: function(input) {
18
+ return {
19
+ value: input,
20
+ text: input
21
+ }
22
+ }
23
+ });
24
+
25
+ $inputNSelects.each(function (index, inputNSelect) {
26
+ _manageInputNSelect(inputNSelect);
27
+ });
9
28
  };
10
29
 
30
+ // Main function for each cell
31
+ var _manageInputNSelect = function(inputNSelect) {
32
+ var selectInputs = $(inputNSelect).find('.form-control');
33
+
34
+ // init selectize
35
+ selectInputs.each(function(index) {
36
+ _initSelectize(index, selectInputs);
37
+ });
38
+
39
+ // load options for first selectize
40
+ _loadOptions(null, 0, selectInputs);
41
+ };
42
+
43
+ // Function to init a select with the call of the api
44
+ var _loadOptions = function (filterId, selectInputPosition, selectInputs) {
45
+ var selectInput = selectInputs[selectInputPosition];
46
+ if (!selectInput) { return }
47
+ var apiUrl = $(selectInput).attr('data-api-url');
48
+ $.ajax({
49
+ url: apiUrl,
50
+ cache: false,
51
+ data: (filterId ? {filter_id: filterId} : null),
52
+ success: function (response) {
53
+ _updateSelectize(response, selectInputPosition, selectInputs);
54
+ }
55
+ });
56
+ };
57
+
58
+ // Function to init an empty input to become a selectize
59
+ var _initSelectize = function (selectInputPosition, selectInputs) {
60
+ var selectInput = selectInputs[selectInputPosition];
61
+ var input = $(selectInput).find('.select-nselect');
62
+ var valueField = $(selectInput).attr('data-value-field');
63
+ var labelField = $(selectInput).attr('data-label-field');
64
+ var initialVal = $(input).val();
65
+ var id = $(selectInput).attr('data-value-id');
66
+
67
+ input.selectize({
68
+ maxItems: 1,
69
+ valueField: valueField,
70
+ labelField: labelField,
71
+ searchField: labelField,
72
+ options: [],
73
+ onChange: function (value) {
74
+ _loadOptions(value, parseInt(id) + 1, selectInputs);
75
+ },
76
+ onInitialize: function() {
77
+ if (initialVal) {
78
+ this.setValue(initialVal);
79
+ _loadOptions(initialVal, parseInt(id) + 1, selectInputs);
80
+ }
81
+ }
82
+ });
83
+ };
84
+
85
+ // Function to update a selectize with correct options
86
+ var _updateSelectize = function (options, selectInputPosition, selectInputs) {
87
+ var selectInput = selectInputs[selectInputPosition];
88
+ var input = $(selectInput).find('.select-nselect');
89
+ var id = $(selectInput).attr('data-value-id');
90
+ var initialVal = $(input).val();
91
+
92
+ var selectize = $(input)[0].selectize;
93
+
94
+ if (selectize) {
95
+ selectize.clear();
96
+ selectize.clearOptions();
97
+ selectize.load(function(callback) {
98
+ callback(options);
99
+ });
100
+ if (initialVal) {
101
+ selectize.setValue(initialVal);
102
+ _loadOptions(initialVal, parseInt(id) + 1, selectInputs);
103
+ }
104
+ }
105
+ };
106
+
11
107
  // Activate pikaday.js module
12
108
  var _manageDatePicker = function() {
13
109
  var $datepicker = $('.date-picker').pickadate({
14
110
  firstDay: 1,
15
111
  min: new Date(1900, 0, 1),
16
112
  max: new Date(3000, 12, 31),
113
+ selectYears: true,
17
114
  format: 'dd/mm/yyyy',
18
115
  hiddenPrefix: '',
19
- hiddenSuffix: ''
116
+ hiddenSuffix: '',
117
+ selectMonths: true
118
+ });
119
+
120
+ var $datepicker = $('.birthdate-picker').pickadate({
121
+ firstDay: 1,
122
+ selectYears: true,
123
+ format: 'dd/mm/yyyy',
124
+ hiddenPrefix: '',
125
+ hiddenSuffix: '',
126
+ selectMonths: true,
127
+ selectYears: 80,
128
+ max: true
20
129
  });
21
130
  };
22
131
 
@@ -24,7 +133,8 @@ var FormManager = (function($) {
24
133
  var $timePicker = $('.time-picker').pickatime({
25
134
  format: 'H:i',
26
135
  hiddenPrefix: '',
27
- hiddenSuffix: ''
136
+ hiddenSuffix: '',
137
+ interval: 5
28
138
  });
29
139
  };
30
140
 
@@ -58,13 +168,12 @@ var FormManager = (function($) {
58
168
  } else {
59
169
  $label.html(labelVal);
60
170
  }
61
-
62
171
  });
63
172
 
64
173
  // Firefox bug fix
65
174
  $input
66
- .on('focus', function(){ $input.addClass( 'has-focus' ); })
67
- .on('blur', function(){ $input.removeClass( 'has-focus' ); });
175
+ .on('focus', function() { $input.addClass( 'has-focus' ); })
176
+ .on('blur', function() { $input.removeClass( 'has-focus' ); });
68
177
  });
69
178
  }
70
179
  };
@@ -83,7 +192,7 @@ var FormManager = (function($) {
83
192
 
84
193
  // Activate email data-list autocomplete
85
194
  var _insertSuggestions = function() {
86
- if($('.email-suggestion').length) {
195
+ if ($('.email-suggestion').length) {
87
196
  var domains = ['yahoo.com', 'gmail.com', 'google.com', 'hotmail.com', 'me.com', 'libero.it', 'live.it', 'live.com'];
88
197
 
89
198
  $('.email-suggestion').emailautocomplete({
@@ -93,57 +202,68 @@ var FormManager = (function($) {
93
202
  };
94
203
 
95
204
  /*
96
- * Manage form submission/validation
205
+ * Manage form elements' submit
97
206
  * @return: undefined or boolean
98
207
  */
99
208
  var _manageFormSubmit = function() {
100
- $('.lato-form').on('submit', function(event) {
101
-
102
- var tests = {
103
- "number": Validator.controlNumber('.input-number'),
104
- "required": Validator.controlRequired('data-input="required"'),
105
- "email": Validator.controlEmail('.input-email'),
106
- "password": Validator.controlPasswordEquality('.input-password', '.confirm-password'),
107
- "length": Validator.controlInputLength('.input-length'),
108
- "radiobox": Validator.controlRadiobox('data-input="radio"')
109
- };
110
-
111
- // Basta che uno dei test fallisca per generare un errore
112
- $.each(tests, function(index, val) {
113
- if(val === false) {
114
- event.preventDefault();
115
- return false;
116
- }
117
- });
209
+ $('.lato-form').not('.login-form').each(function(i, el) {
210
+ $(el).on('submit', function(event) {
211
+
212
+ var $requiredControls = $(el).find('.form-control[data-input="required"]');
213
+ var $emailControls = $(el).find('.input-email');
214
+ var $lengthControls = $(el).find('.input-length');
215
+ var $radioControls = $(el).find('.form-control[data-input="radio"]');
216
+ var $passwordControl = $(el).find('.input-password');
217
+ var $passwordConfirm = $(el).find('.confirm-password');
218
+ var $numberControls = $(el).find('.input-number');
118
219
 
220
+ var tests = {
221
+ //"number": Validator.controlNumber($numberControls),
222
+ // "required": Validator.controlRequired($requiredControls),
223
+ // "email": Validator.controlEmail($emailControls),
224
+ //"password": Validator.controlPasswordEquality($passwordControl, $passwordConfirm)
225
+ //"length": Validator.controlInputLength($lengthControls),
226
+ //"radiobox": Validator.controlRadiobox($radioControls)
227
+ };
228
+
229
+ // Basta che uno dei test fallisca per generare un errore
230
+ $.each(tests, function(index, val) {
231
+ // if(!val) {
232
+ // event.preventDefault();
233
+ // return false;
234
+ // }
235
+ });
236
+
237
+ console.log(event);
238
+ });
119
239
  });
120
240
  }
121
241
 
122
242
  // Manage form validation in semi-real-time.
123
243
  var _manageBlurValidation = function() {
124
- $('.lato-form').on('blur', '.input', function(event) {
125
- var type = $(this).parent('.form-control').data('input');
126
- var controlType = $(this).parent('.form-control').data('control');
127
-
128
- // Email suggestion case
129
- if($('.eac-input-wrap').length) {
130
- Validator.controlEmail('.input-email');
131
- }
132
-
133
- // Get input desired className.
134
- var tester = '.' + $(this).attr('class').split(' ')[1];
135
-
136
- // Manage data-control type
137
- switch(controlType) {
138
- case 'number':
139
- Validator.controlNumber(tester);
140
- break;
141
- case 'email':
142
- Validator.controlEmail(tester);
143
- break;
144
- }
145
-
146
- });
244
+ // $('.lato-form').on('blur', '.input', function(event) {
245
+ // var type = $(this).parent('.form-control').data('input');
246
+ // var controlType = $(this).parent('.form-control').data('control');
247
+ //
248
+ // // Email suggestion case
249
+ // if($('.eac-input-wrap').length) {
250
+ // Validator.controlEmail('.input-email');
251
+ // }
252
+ //
253
+ // // Get input desired className.
254
+ // var tester = '.' + $(this).attr('class').split(' ')[1];
255
+ //
256
+ // // Manage data-control type
257
+ // switch(controlType) {
258
+ // case 'number':
259
+ // Validator.controlNumber(tester);
260
+ // break;
261
+ // case 'email':
262
+ // Validator.controlEmail(tester);
263
+ // break;
264
+ // }
265
+ //
266
+ // });
147
267
  };
148
268
 
149
269
  var init = function() {
@@ -0,0 +1,169 @@
1
+ var Step = (function($) {
2
+ 'use strict';
3
+
4
+ var $stepElements = $('.element-step');
5
+ var $stepNavigator = $('.step-navigator');
6
+
7
+ var _stepExists = function() {
8
+ return $stepElements.length;
9
+ };
10
+
11
+ var _sameElementStep = function($elStep, $navigator) {
12
+ return $elStep.data('step-id') === $navigator.data('step-id');
13
+ };
14
+
15
+ var _setStepsSize = function(currentStepElement) {
16
+ var elW = $(currentStepElement).outerWidth();
17
+ var $stepScroller = $(currentStepElement).find('.step-scroller');
18
+ var $steps = $(currentStepElement).find('.step');
19
+ var stepsCount = $steps.length;
20
+
21
+ $steps.width(elW);
22
+ $stepScroller.width(elW * stepsCount);
23
+ };
24
+
25
+ var _buildNavigation = function(currentStepElement, currentSteps) {
26
+ var stepElementid = $(currentStepElement).data('step-id');
27
+ var stepNavigatorSelector = '.step-navigator[data-step-id=' + stepElementid + ']';
28
+ var fragment = $(document.createDocumentFragment());
29
+
30
+ $.each(currentSteps, function(i, el) {
31
+ if ((parseInt(i)+1) === 1) {
32
+ var li = $('<li class="step-paginate-index active">' + (parseInt(i) + 1) + '</li>');
33
+ } else {
34
+ var li = $('<li class="step-paginate-index">' + (parseInt(i) + 1) + '</li>');
35
+ }
36
+ fragment.append(li);
37
+ });
38
+
39
+ _disableNavigation('.step-prev', stepElementid);
40
+ $(stepNavigatorSelector).find('.step-paginate').append(fragment);
41
+ };
42
+
43
+ var _disableNavigation = function($navEl, stepId) {
44
+ var selector = '.step-navigator[data-step-id="' + stepId + '"]';
45
+ $(selector).find($navEl).addClass('step-disabled');
46
+ };
47
+
48
+ var _enableNavigation = function($navEl, stepId) {
49
+ var selector = '.step-navigator[data-step-id="' + stepId + '"]';
50
+ $(selector).find($navEl).removeClass('step-disabled');
51
+ };
52
+
53
+ var _setActiveStep = function(currentStepElement, id) {
54
+ var stepElementid = $(currentStepElement).data('step-id');
55
+ var $step = $(currentStepElement).find('.step');
56
+ var stepNavigatorSelector = '.step-navigator[data-step-id=' + stepElementid + ']';
57
+ var $stepPaginateIndex = $(stepNavigatorSelector).find('.step-paginate-index');
58
+
59
+ $stepPaginateIndex.removeClass('active');
60
+ $stepPaginateIndex.eq(id).addClass('active');
61
+
62
+ $step.removeClass('active');
63
+ $step.eq(id).addClass('active');
64
+ };
65
+
66
+ var moveStep = function(currentStepElement, direction) {
67
+ currentStepElement = currentStepElement || $('.element-step:first');
68
+ direction = direction || 'initial';
69
+ var transform = ['transform', 'msTransform', 'webkitTransform', 'mozTransform', 'oTransform'];
70
+ var transformProperty = Util.getSupportedPropertyName(transform);
71
+ var stepScroller = $(currentStepElement).find('.step-scroller')[0];
72
+ var muchScroll = $(currentStepElement).outerWidth();
73
+ var stepCount = parseInt($(currentStepElement).find('.step').length);
74
+ var currentIndex = parseInt($(currentStepElement).find('.step.active').index() + 1);
75
+ var stepElementid = $(currentStepElement).data('step-id');
76
+
77
+ if (transformProperty) {
78
+ if (typeof direction === 'string') {
79
+ switch (direction) {
80
+ case 'prev':
81
+ if (currentIndex !== 1) {
82
+ _setActiveStep(currentStepElement, currentIndex-2);
83
+ stepScroller.style[transformProperty] = 'translateX(-' + (muchScroll * (currentIndex - 2)) + 'px)';
84
+ }
85
+ break;
86
+ case 'next':
87
+ if (currentIndex !== stepCount) {
88
+ stepScroller.style[transformProperty] = 'translateX(-' + (muchScroll * currentIndex) + 'px)';
89
+ _setActiveStep(currentStepElement, currentIndex);
90
+ }
91
+ break;
92
+ case 'initial':
93
+
94
+ break;
95
+ default:
96
+ }
97
+
98
+ } else if (typeof direction === 'number') {
99
+ var index = direction-1;
100
+ stepScroller.style[transformProperty] = 'translateX(-' + (muchScroll * index) + 'px)';
101
+ _setActiveStep(currentStepElement, index);
102
+ //_updateNavigationControl(currentIndex, stepElementid, stepCount);
103
+ } else {
104
+ return false;
105
+ }
106
+ }
107
+ };
108
+
109
+ var prevStep = function(currentStepElement) {
110
+ $(document).on('click', '.step-prev', function() {
111
+ moveStep(currentStepElement, 'prev');
112
+ });
113
+ };
114
+
115
+ var nextStep = function(currentStepElement) {
116
+ $(document).on('click', '.step-next', function() {
117
+ moveStep(currentStepElement, 'next');
118
+ });
119
+ };
120
+
121
+ var resetStep = function() {
122
+ $(document).on('click', '.step-reset', function() {
123
+ moveStep(currentStepElement, 'initial');
124
+ });
125
+ };
126
+
127
+ var _indexNavigation = function() {
128
+ $(document).on('click', '.step-paginate-index', function() {
129
+ var stepElementid = $(this).parents('.step-navigator').data('step-id');
130
+ var paginateId = parseInt($(this).text());
131
+ var currentStepElementSelector = '.element-step[data-step-id=' + stepElementid + ']';
132
+ var $currentStepElement = $(currentStepElementSelector);
133
+
134
+ moveStep($currentStepElement, paginateId);
135
+ });
136
+ };
137
+
138
+ var updateStepsSize = function() {
139
+ if (_stepExists()) {
140
+ $.each($stepElements, function(i, el) {
141
+ _setStepsSize(el);
142
+ });
143
+ }
144
+ };
145
+
146
+ var init = function() {
147
+ if (_stepExists()) {
148
+ $.each($stepElements, function(i, el) {
149
+ var $elSteps = $(el).find('.step');
150
+
151
+ prevStep(el);
152
+ nextStep(el);
153
+ _setStepsSize(el);
154
+ _buildNavigation(el, $elSteps);
155
+ _indexNavigation();
156
+ });
157
+ }
158
+ };
159
+
160
+ return {
161
+ init: init,
162
+ move: moveStep,
163
+ prev: prevStep,
164
+ next: nextStep,
165
+ reset: resetStep,
166
+ update: updateStepsSize
167
+ };
168
+
169
+ })(jQuery);