binda 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +83 -25
  3. data/app/assets/javascripts/binda/application.js +3 -3
  4. data/app/assets/javascripts/binda/components/bootstrap.js +3 -4
  5. data/app/assets/javascripts/binda/components/field_group_editor.js +10 -10
  6. data/app/assets/javascripts/binda/components/field_setting_choices.js +61 -49
  7. data/app/assets/javascripts/binda/components/fileupload.js +135 -118
  8. data/app/assets/javascripts/binda/components/form_item.js +65 -65
  9. data/app/assets/javascripts/binda/components/form_item_editor.js +19 -19
  10. data/app/assets/javascripts/binda/components/form_item_image.js +11 -13
  11. data/app/assets/javascripts/binda/components/form_item_repeater.js +77 -71
  12. data/app/assets/javascripts/binda/components/login-shader.js +171 -164
  13. data/app/assets/javascripts/binda/components/login_form.js +65 -73
  14. data/app/assets/javascripts/binda/components/radio-toggle.js +8 -12
  15. data/app/assets/javascripts/binda/components/select2.js +19 -14
  16. data/app/assets/javascripts/binda/components/sortable.js +76 -71
  17. data/app/assets/javascripts/binda/dist/binda.bundle.js +735 -727
  18. data/app/assets/javascripts/binda/index.js +49 -35
  19. data/app/assets/stylesheets/binda/components/assets_manager.scss +13 -22
  20. data/app/assets/stylesheets/binda/components/b-alert.scss +18 -14
  21. data/app/assets/stylesheets/binda/components/b-btn.scss +24 -43
  22. data/app/assets/stylesheets/binda/components/field_setting_choices.scss +16 -31
  23. data/app/assets/stylesheets/binda/components/fileupload.scss +25 -42
  24. data/app/assets/stylesheets/binda/components/form_item.scss +51 -93
  25. data/app/assets/stylesheets/binda/components/form_item_choices.scss +7 -10
  26. data/app/assets/stylesheets/binda/components/login.scss +2 -2
  27. data/app/assets/stylesheets/binda/components/main_header.scss +5 -10
  28. data/app/assets/stylesheets/binda/components/main_sidebar.scss +42 -46
  29. data/app/assets/stylesheets/binda/components/main_sortable_table.scss +12 -21
  30. data/app/assets/stylesheets/binda/components/main_table.scss +18 -35
  31. data/app/assets/stylesheets/binda/components/popup_warning.scss +14 -27
  32. data/app/assets/stylesheets/binda/components/select2.scss +46 -48
  33. data/app/assets/stylesheets/binda/components/sortable.scss +25 -45
  34. data/app/assets/stylesheets/binda/components/standard-form.scss +43 -73
  35. data/app/assets/stylesheets/binda/controllers/users_sessions_new.scss +52 -89
  36. data/app/assets/stylesheets/binda/index.scss +0 -1
  37. data/app/assets/stylesheets/binda/settings/buttons.scss +9 -10
  38. data/app/assets/stylesheets/binda/settings/common.scss +17 -22
  39. data/app/assets/stylesheets/binda/settings/fonts.scss +112 -67
  40. data/app/assets/stylesheets/binda/settings/tiny_mce_overrides.scss +20 -36
  41. data/app/assets/stylesheets/binda/settings/variables.scss +38 -43
  42. data/app/controllers/binda/choices_controller.rb +14 -11
  43. data/app/controllers/binda/components_controller.rb +6 -4
  44. data/app/controllers/binda/structures_controller.rb +7 -3
  45. data/app/helpers/binda/components_helper.rb +69 -3
  46. data/app/helpers/binda/field_groups_helper.rb +16 -6
  47. data/app/helpers/binda/structures_helper.rb +1 -4
  48. data/app/models/binda/application_record.rb +4 -1
  49. data/app/models/binda/asset.rb +3 -1
  50. data/app/models/binda/b.rb +1 -0
  51. data/app/models/binda/category.rb +1 -0
  52. data/app/models/binda/checkbox.rb +2 -0
  53. data/app/models/binda/choice.rb +74 -41
  54. data/app/models/binda/component.rb +1 -1
  55. data/app/models/binda/date.rb +4 -0
  56. data/app/models/binda/deprecation.rb +7 -0
  57. data/app/models/binda/field_group.rb +16 -3
  58. data/app/models/binda/field_setting.rb +168 -41
  59. data/app/models/binda/image.rb +1 -0
  60. data/app/models/binda/radio.rb +2 -0
  61. data/app/models/binda/relation.rb +3 -0
  62. data/app/models/binda/repeater.rb +3 -0
  63. data/app/models/binda/selection.rb +237 -0
  64. data/app/models/binda/string.rb +4 -0
  65. data/app/models/binda/structure.rb +25 -14
  66. data/app/models/binda/text.rb +9 -0
  67. data/app/models/binda/video.rb +1 -0
  68. data/app/models/concerns/binda/default_helpers.rb +40 -31
  69. data/app/models/concerns/binda/deprecations.rb +6 -0
  70. data/app/models/concerns/binda/fieldable_association_helpers.rb +366 -0
  71. data/app/models/concerns/binda/fieldable_associations.rb +32 -369
  72. data/app/views/binda/boards/edit.html.erb +15 -2
  73. data/app/views/binda/categories/_form.html.erb +24 -51
  74. data/app/views/binda/categories/edit.html.erb +23 -3
  75. data/app/views/binda/categories/index.html.erb +49 -25
  76. data/app/views/binda/categories/new.html.erb +21 -2
  77. data/app/views/binda/components/edit.html.erb +27 -4
  78. data/app/views/binda/components/index.html.erb +47 -50
  79. data/app/views/binda/components/new.html.erb +12 -2
  80. data/app/views/binda/components/sort_index.html.erb +28 -13
  81. data/app/views/binda/field_groups/_form_body.html.erb +43 -82
  82. data/app/views/binda/field_groups/_form_item.html.erb +3 -120
  83. data/app/views/binda/field_groups/_form_section.html.erb +11 -16
  84. data/app/views/binda/field_groups/_form_section_repeater.html.erb +7 -15
  85. data/app/views/binda/field_groups/edit.html.erb +14 -2
  86. data/app/views/binda/field_groups/form_item/_form_item_choice_editor.html.erb +11 -0
  87. data/app/views/binda/field_groups/form_item/_form_item_editor.html.erb +14 -0
  88. data/app/views/binda/field_groups/form_item/_form_item_header.html.erb +25 -0
  89. data/app/views/binda/field_groups/form_item/_form_item_new_editor.html.erb +8 -0
  90. data/app/views/binda/field_groups/form_item/_form_item_persisted_editor.html.erb +27 -0
  91. data/app/views/binda/field_groups/form_item/form_item_choice/_form_item_allow_null_choice.html.erb +11 -0
  92. data/app/views/binda/field_groups/form_item/form_item_choice/_form_item_choice_header.html.erb +11 -0
  93. data/app/views/binda/field_groups/form_item/form_item_choice/_form_item_default_choice.html.erb +11 -0
  94. data/app/views/binda/field_groups/form_item/form_item_choice/_form_item_new_choice.html.erb +16 -0
  95. data/app/views/binda/field_groups/form_item/form_item_choice/_form_item_persisted_choices.html.erb +16 -0
  96. data/app/views/binda/field_groups/new.html.erb +14 -2
  97. data/app/views/binda/field_settings/_form_body.html.erb +1 -3
  98. data/app/views/binda/field_settings/edit.html.erb +1 -1
  99. data/app/views/binda/field_settings/new.html.erb +1 -1
  100. data/app/views/binda/fieldable/_form_body.html.erb +24 -72
  101. data/app/views/binda/fieldable/_form_item_date.html.erb +1 -4
  102. data/app/views/binda/fieldable/_form_item_image.html.erb +3 -7
  103. data/app/views/binda/fieldable/_form_item_new_repeater.html.erb +0 -13
  104. data/app/views/binda/fieldable/_form_item_selections.html.erb +20 -112
  105. data/app/views/binda/fieldable/form_item_selections/_form_item_checkbox.html.erb +34 -0
  106. data/app/views/binda/fieldable/form_item_selections/_form_item_radio.html.erb +28 -0
  107. data/app/views/binda/fieldable/form_item_selections/_form_item_selection.html.erb +30 -0
  108. data/app/views/binda/manage/users/_form_body.html.erb +1 -31
  109. data/app/views/binda/manage/users/edit.html.erb +12 -2
  110. data/app/views/binda/manage/users/index.html.erb +36 -19
  111. data/app/views/binda/manage/users/new.html.erb +14 -3
  112. data/app/views/binda/structures/_form_body.html.erb +2 -25
  113. data/app/views/binda/structures/_form_section.html.erb +43 -65
  114. data/app/views/binda/structures/_form_sidebar.html.erb +19 -12
  115. data/app/views/binda/structures/edit.html.erb +20 -3
  116. data/app/views/binda/structures/index.html.erb +46 -26
  117. data/app/views/binda/structures/new.html.erb +13 -2
  118. data/app/views/binda/structures/sort_index.html.erb +37 -17
  119. data/app/views/binda/users/sessions/new.html.erb +25 -20
  120. data/app/views/layouts/binda/_form_errors.html.erb +10 -0
  121. data/app/views/layouts/binda/_sidebar.html.erb +6 -6
  122. data/app/views/layouts/binda/application.html.erb +1 -1
  123. data/config/initializers/carrierwave.rb +3 -2
  124. data/config/locales/en.yml +56 -12
  125. data/config/tinymce.yml +2 -2
  126. data/db/migrate/1_create_binda_tables.rb +1 -1
  127. data/lib/binda/version.rb +1 -1
  128. data/lib/generators/binda/setup/setup_generator.rb +2 -2
  129. data/lib/tasks/add_default_choice_to_all_selections_with_no_choices_task.rake +6 -0
  130. metadata +58 -8
  131. data/app/assets/stylesheets/binda/components/form_item_image.scss +0 -0
  132. data/app/views/binda/field_groups/_form_item_choice.erb +0 -104
@@ -1,144 +1,148 @@
1
1
  class Shader {
2
- constructor(){}
3
-
4
- isSet()
5
- {
6
- if ( $('#background-shader').length > 0 ) { return true }
7
- else { return false }
8
- }
9
-
10
- // SETUP SHADER
11
- setup () {
12
-
13
- let Container = PIXI.Container,
14
- autoDetectRenderer = PIXI.autoDetectRenderer,
15
- loader = PIXI.loader,
16
- resources = PIXI.loader.resources,
17
- Sprite = PIXI.Sprite
18
-
19
- // Create a container object called the `stage`
20
- this.stage = new Container()
21
-
22
- // Create 'renderer'
23
- this.renderer = PIXI.autoDetectRenderer( window.innerWidth, window.innerHeight )
24
-
25
- // //Add the canvas to the HTML document
26
-
27
- document.getElementById('background-shader').appendChild(this.renderer.view)
28
-
29
-
30
- this.renderer.backgroundColor = 0xFF00FF
31
-
32
- // canvas full window
33
- this.renderer.view.style.position = "fixed"
34
- this.renderer.view.style.display = "block"
35
-
36
- let fragmentShader = document.getElementById("fragmentShader").innerHTML
37
-
38
- let currentTime = Math.sin( Date.now() ) + 0.5
39
-
40
- this.uniforms = {
41
- uTime : { type: '1f', value: 0.0 },
42
- uCurrentTime : { type: '1f', value: currentTime },
43
- uMouse : { type: '2f', value: [ window.innerWidth, window.innerHeight ] },
44
- uWindowSize : { type: '2f', value: [ window.innerWidth, window.innerHeight ] }
45
- }
46
-
47
- this.customShader = new PIXI.AbstractFilter(null, fragmentShader, this.uniforms)
48
- this.drawRectagle()
49
- }
50
-
51
-
52
- // DRAW RECTANGLE
53
- drawRectagle() {
54
-
55
- this.rectangle = new PIXI.Graphics()
56
-
57
- // Set the default background color wo if browser doesn't support the filter we still see the primary color
58
- let colorWithHash = '#FF00FF'
59
- const colorWith0x = '0x' + colorWithHash.slice( 1, 7 )
60
- this.rectangle.beginFill( colorWith0x )
61
-
62
- // Create the background rectanlge
63
- this.rectangle.drawRect( 0, 0, window.innerWidth, window.innerHeight )
64
- this.rectangle.endFill()
65
-
66
- // Setup the filter (shader)
67
- this.rectangle.filters = [ this.customShader ]
68
-
69
- // Add background to stage
70
- this.stage.addChild( this.rectangle )
71
- }
72
-
73
-
74
- // START ANIMATION
75
- start() { animate() }
76
-
77
-
78
- // MOUSE UPDATE
79
- mouseUpdate( event ) {
80
-
81
- // If uniforms haven't been set yet don't do anything and exit
82
- if ( typeof this.uniforms === 'undefined' ) return
83
-
84
- // udpate mouse coordinates for the shader
85
- this.customShader.uniforms.uMouse = [ event.pageX, event.pageY ]
86
- }
87
-
88
-
89
- // RESIZE
90
- resize() {
91
-
92
- // let scale = scaleToWindow( this.renderer.view )
93
- let prevWidth = this.renderer.view.style.width
94
- let prevHeight = this.renderer.view.style.height
95
- this.renderer.view.style.width = window.innerWidth + "px"
96
- this.renderer.view.style.height = window.innerHeight + "px"
97
- this.customShader.uniforms.uWindowSize = [ window.innerWidth, window.innerHeight ]
2
+ constructor() {
3
+ this.uniforms = {
4
+ uTime: { type: "1f", value: 0.0 },
5
+ uCurrentTime: { type: "1f", value: Math.sin(Date.now()) + 0.5 },
6
+ uMouse: {
7
+ type: "2f",
8
+ value: [window.innerWidth, window.innerHeight]
9
+ },
10
+ uWindowSize: {
11
+ type: "2f",
12
+ value: [window.innerWidth, window.innerHeight]
13
+ }
14
+ };
15
+ }
98
16
 
99
- // Plese check this out ↴↴↴
100
- // this.rectangle.scale.x = window.innerWidth / prevWidth
101
- // this.rectangle.scale.y = window.innerHeight / prevHeight
17
+ isSet() {
18
+ if ($("#background-shader").length > 0) {
19
+ return true;
20
+ } else {
21
+ return false;
102
22
  }
23
+ }
24
+
25
+ // SETUP SHADER
26
+ setup() {
27
+ // Create a container object called the `stage`
28
+ this.stage = new PIXI.Container();
29
+
30
+ // Create 'renderer'
31
+ this.renderer = PIXI.autoDetectRenderer(
32
+ window.innerWidth,
33
+ window.innerHeight
34
+ );
35
+
36
+ // //Add the canvas to the HTML document
37
+
38
+ document
39
+ .getElementById("background-shader")
40
+ .appendChild(this.renderer.view);
41
+
42
+ this.renderer.backgroundColor = 0xff00ff;
43
+
44
+ // canvas full window
45
+ this.renderer.view.style.position = "fixed";
46
+ this.renderer.view.style.display = "block";
47
+
48
+ let fragmentShader = document.getElementById("fragmentShader").innerHTML;
49
+
50
+ this.customShader = new PIXI.AbstractFilter(
51
+ null,
52
+ fragmentShader,
53
+ this.uniforms
54
+ );
55
+ this.drawRectagle();
56
+ }
57
+
58
+ // DRAW RECTANGLE
59
+ drawRectagle() {
60
+ this.rectangle = new PIXI.Graphics();
61
+
62
+ // Set the default background color wo if browser doesn't support the filter we still see the primary color
63
+ let colorWithHash = "#FF00FF";
64
+ const colorWith0x = "0x" + colorWithHash.slice(1, 7);
65
+ this.rectangle.beginFill(colorWith0x);
66
+
67
+ // Create the background rectanlge
68
+ this.rectangle.drawRect(0, 0, window.innerWidth, window.innerHeight);
69
+ this.rectangle.endFill();
70
+
71
+ // Setup the filter (shader)
72
+ this.rectangle.filters = [this.customShader];
73
+
74
+ // Add background to stage
75
+ this.stage.addChild(this.rectangle);
76
+ }
77
+
78
+ // START ANIMATION
79
+ start() {
80
+ animate();
81
+ }
82
+
83
+ // MOUSE UPDATE
84
+ mouseUpdate(event) {
85
+ // If uniforms haven't been set yet don't do anything and exit
86
+ if (typeof this.uniforms === "undefined") return;
87
+
88
+ // udpate mouse coordinates for the shader
89
+ this.customShader.uniforms.uMouse = [event.pageX, event.pageY];
90
+ }
91
+
92
+ // RESIZE
93
+ resize() {
94
+ // let scale = scaleToWindow( this.renderer.view )
95
+ let prevWidth = this.renderer.view.style.width;
96
+ let prevHeight = this.renderer.view.style.height;
97
+ this.renderer.view.style.width = window.innerWidth + "px";
98
+ this.renderer.view.style.height = window.innerHeight + "px";
99
+ this.customShader.uniforms.uWindowSize = [
100
+ window.innerWidth,
101
+ window.innerHeight
102
+ ];
103
+
104
+ // Plese check this out ↴↴↴
105
+ // this.rectangle.scale.x = window.innerWidth / prevWidth
106
+ // this.rectangle.scale.y = window.innerHeight / prevHeight
107
+ }
103
108
  }
104
109
 
105
-
106
- export let _Shader = new Shader()
107
-
110
+ export let _Shader = new Shader();
108
111
 
109
112
  // ANIMATE
110
113
  // -------
111
114
  function animate() {
112
-
113
- // start the timer for the next animation loop
114
- requestAnimationFrame( animate )
115
- _Shader.customShader.uniforms.uTime += 0.01
116
- // this is the main render call that makes pixi draw your container and its children.
117
- _Shader.renderer.render( _Shader.stage )
115
+ // start the timer for the next animation loop
116
+ requestAnimationFrame(animate);
117
+ _Shader.customShader.uniforms.uTime += 0.01;
118
+ // this is the main render call that makes pixi draw your container and its children.
119
+ _Shader.renderer.render(_Shader.stage);
118
120
  }
119
121
 
120
122
  // CONVERT HEX TO RGB COLORS
121
123
  // -------------------------
122
- function hexToShaderRgb( hex ) {
123
-
124
- // Precision of the float number
125
- var precision = 100
126
- // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
127
- var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i
128
- hex = hex.replace(shorthandRegex, function(m, r, g, b) {
129
- return r + r + g + g + b + b
130
- })
131
-
132
- var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
133
- return result ? {
134
- // Get a number between 0.00 and 1.00
135
- r: Math.round( parseInt(result[1], 16) * precision / 255 ) / precision,
136
- g: Math.round( parseInt(result[2], 16) * precision / 255 ) / precision,
137
- b: Math.round( parseInt(result[3], 16) * precision / 255 ) / precision
138
- } : null;
124
+ function hexToShaderRgb(hex) {
125
+ // Precision of the float number
126
+ var precision = 100;
127
+ // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
128
+ var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
129
+ hex = hex.replace(shorthandRegex, function(m, r, g, b) {
130
+ return r + r + g + g + b + b;
131
+ });
132
+
133
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
134
+ if (result) {
135
+ return {
136
+ // Get a number between 0.00 and 1.00
137
+ r: Math.round(parseInt(result[1], 16) * precision / 255) / precision,
138
+ g: Math.round(parseInt(result[2], 16) * precision / 255) / precision,
139
+ b: Math.round(parseInt(result[3], 16) * precision / 255) / precision
140
+ };
141
+ } else {
142
+ return null;
143
+ }
139
144
  }
140
145
 
141
-
142
146
  // REQUEST ANIMATION POLYFILL
143
147
  // --------------------------
144
148
  // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
@@ -146,48 +150,51 @@ function hexToShaderRgb( hex ) {
146
150
  // requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
147
151
  // MIT license
148
152
  (function() {
149
- var lastTime = 0;
150
- var vendors = ['ms', 'moz', 'webkit', 'o'];
151
- for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
152
- window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
153
- window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
154
- }
155
-
156
- if (!window.requestAnimationFrame)
157
- window.requestAnimationFrame = function(callback, element) {
158
- var currTime = new Date().getTime();
159
- var timeToCall = Math.max(0, 16 - (currTime - lastTime));
160
- var id = window.setTimeout(function() { callback(currTime + timeToCall); },
161
- timeToCall);
162
- lastTime = currTime + timeToCall;
163
- return id;
164
- };
165
-
166
- if (!window.cancelAnimationFrame)
167
- window.cancelAnimationFrame = function(id) {
168
- clearTimeout(id);
169
- };
170
- }());
153
+ var lastTime = 0;
154
+ var vendors = ["ms", "moz", "webkit", "o"];
155
+ for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
156
+ window.requestAnimationFrame = window[vendors[x] + "RequestAnimationFrame"];
157
+ window.cancelAnimationFrame =
158
+ window[vendors[x] + "CancelAnimationFrame"] ||
159
+ window[vendors[x] + "CancelRequestAnimationFrame"];
160
+ }
161
+
162
+ if (!window.requestAnimationFrame)
163
+ window.requestAnimationFrame = function(callback, element) {
164
+ var currTime = new Date().getTime();
165
+ var timeToCall = Math.max(0, 16 - (currTime - lastTime));
166
+ var id = window.setTimeout(function() {
167
+ callback(currTime + timeToCall);
168
+ }, timeToCall);
169
+ lastTime = currTime + timeToCall;
170
+ return id;
171
+ };
171
172
 
173
+ if (!window.cancelAnimationFrame)
174
+ window.cancelAnimationFrame = function(id) {
175
+ clearTimeout(id);
176
+ };
177
+ })();
172
178
 
173
179
  // Mozilla MDN optimized resize
174
180
  // https://developer.mozilla.org/en-US/docs/Web/Events/resize
175
181
  (function() {
176
- var throttle = function(type, name, obj) {
177
- obj = obj || window;
178
- var running = false;
179
- var func = function() {
180
- if (running) { return; }
181
- running = true;
182
- requestAnimationFrame(function() {
183
- obj.dispatchEvent(new CustomEvent(name));
184
- running = false;
185
- });
186
- };
187
- obj.addEventListener(type, func);
182
+ var throttle = function(type, name, obj) {
183
+ obj = obj || window;
184
+ var running = false;
185
+ var func = function() {
186
+ if (running) {
187
+ return;
188
+ }
189
+ running = true;
190
+ requestAnimationFrame(function() {
191
+ obj.dispatchEvent(new CustomEvent(name));
192
+ running = false;
193
+ });
188
194
  };
195
+ obj.addEventListener(type, func);
196
+ };
189
197
 
190
- /* init - you can init any event */
191
- throttle("resize", "optimizedResize");
192
- })();
193
-
198
+ /* init - you can init any event */
199
+ throttle("resize", "optimizedResize");
200
+ })();
@@ -1,116 +1,108 @@
1
1
  /**
2
2
  * LOGIN FORM
3
- *
3
+ *
4
4
  * https://tympanus.net/Development/MinimalForm/
5
5
  * https://github.com/codrops/MinimalForm/blob/master/js/stepsForm.js
6
6
  */
7
7
 
8
8
  class LoginForm {
9
+ constructor() {
10
+ this.current = 0;
11
+ this.isFilled = false;
12
+ }
13
+
14
+ isSet() {
15
+ if ($(".login--form").length > 0) {
16
+ return true;
17
+ } else {
18
+ return false;
19
+ }
20
+ }
9
21
 
10
- constructor()
11
- {
12
- this.current = 0
13
- this.isFilled = false
14
- }
15
-
16
- isSet()
17
- {
18
- if ( $('.login--form').length > 0 ) { return true }
19
- else { return false }
20
- }
21
-
22
- init()
23
- {
24
- this.$form = $('.login--form')
25
- this.$questions = $('ol.login--questions > li')
26
- this.questionsCount = this.$questions.length
27
- this.$nextButton = $('button.login--next')
22
+ init() {
23
+ this.$form = $(".login--form");
24
+ this.$questions = $("ol.login--questions > li");
25
+ this.questionsCount = this.$questions.length;
26
+ this.$nextButton = $("button.login--next");
28
27
 
29
28
  // Mark the first question as the current one
30
- this.$questions.first().addClass('login--current')
31
-
29
+ this.$questions.first().addClass("login--current");
30
+
32
31
  //disable form autocomplete
33
- this.$form.attr('autocomplete', 'off')
34
- this.setEvents()
32
+ this.$form.attr("autocomplete", "off");
33
+ this.setEvents();
35
34
  }
36
35
 
37
- setEvents()
38
- {
39
- let self = this
36
+ setEvents() {
37
+ let self = this;
40
38
 
41
39
  // first input
42
- let firstInput = this.$questions.get(this.current).querySelector( 'input, textarea, select' )
40
+ let firstInput = this.$questions
41
+ .get(this.current)
42
+ .querySelector("input, textarea, select");
43
43
 
44
44
  // focus
45
- let onFocusStart = function()
46
- {
47
- firstInput.removeEventListener( 'focus', onFocusStart )
48
- self.$nextButton.addClass('login--show')
49
- }
45
+ let onFocusStart = function() {
46
+ firstInput.removeEventListener("focus", onFocusStart);
47
+ self.$nextButton.addClass("login--show");
48
+ };
50
49
  // show the next question control first time the input gets focused
51
- firstInput.addEventListener('focus', onFocusStart )
50
+ firstInput.addEventListener("focus", onFocusStart);
52
51
 
53
52
  // show next question
54
- this.$nextButton.on('click', ( event )=>{
55
-
56
- event.preventDefault()
57
- this._nextQuestion()
58
- } )
53
+ this.$nextButton.on("click", event => {
54
+ event.preventDefault();
55
+ this._nextQuestion();
56
+ });
59
57
 
60
58
  // pressing enter will jump to next question
61
- this.$form.on('keydown', ( event )=>{
62
-
63
- let keyCode = event.keyCode || event.which
59
+ this.$form.on("keydown", event => {
60
+ let keyCode = event.keyCode || event.which;
64
61
  // enter
65
- if( keyCode === 13 )
66
- {
67
- event.preventDefault()
68
- this._nextQuestion()
62
+ if (keyCode === 13) {
63
+ event.preventDefault();
64
+ this._nextQuestion();
69
65
  }
70
- })
71
- }
66
+ });
67
+ }
72
68
 
73
- _nextQuestion()
74
- {
69
+ _nextQuestion() {
75
70
  // check if form is filled
76
- if( this.current === this.questionsCount - 1 ) { this.isFilled = true }
71
+ if (this.current === this.questionsCount - 1) {
72
+ this.isFilled = true;
73
+ }
77
74
 
78
- // current question
79
- let currentQuestion = this.$questions.get(this.current)
75
+ // current question
76
+ let currentQuestion = this.$questions.get(this.current);
80
77
 
81
78
  // increment current question iterator
82
- ++this.current
79
+ ++this.current;
83
80
 
84
- if( !this.isFilled )
85
- {
81
+ if (!this.isFilled) {
86
82
  // add class "show-next" to form element (start animations)
87
- this.$form.addClass('login--show-next')
83
+ this.$form.addClass("login--show-next");
88
84
 
89
85
  // remove class "current" from current question and add it to the next one
90
86
  // current question
91
- var nextQuestion = this.$questions.get(this.current)
92
- $(currentQuestion).removeClass('login--current')
93
- $(nextQuestion).addClass('login--current')
87
+ var nextQuestion = this.$questions.get(this.current);
88
+ $(currentQuestion).removeClass("login--current");
89
+ $(nextQuestion).addClass("login--current");
94
90
  }
95
91
 
96
92
  // after animation ends, remove class "show-next" from form element and change current question placeholder
97
- let self = this
98
- let onEndTransition = function()
99
- {
100
- if( self.isFilled )
101
- {
102
- self.$form.submit()
103
- }
104
- else
105
- {
106
- self.$form.removeClass('login--show-next')
93
+ let self = this;
94
+ let onEndTransition = function() {
95
+ if (self.isFilled) {
96
+ self.$form.submit();
97
+ } else {
98
+ self.$form.removeClass("login--show-next");
107
99
  // force the focus on the next input
108
- nextQuestion.querySelector( 'input, textarea, select' ).focus()
100
+ nextQuestion.querySelector("input, textarea, select").focus();
109
101
  }
110
- }
102
+ };
111
103
 
112
- setTimeout( onEndTransition, 400 ) // Wait for CSS transition to complete
104
+ setTimeout(onEndTransition, 400); // Wait for CSS transition to complete
113
105
  }
114
106
  }
115
107
 
116
- export let _LoginForm = new LoginForm()
108
+ export let _LoginForm = new LoginForm();