c80_contest 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d8a3b15d6fb1d31fca19f00fbe01e4ac31ea4d1
4
- data.tar.gz: bffa9d4f37dcd1896513664f46b2b102eff3ec97
3
+ metadata.gz: a8589be081b886f52a64155f93fd213212bdb464
4
+ data.tar.gz: 0f520526b5c616e128d99cebad12fe29176d629e
5
5
  SHA512:
6
- metadata.gz: 649796c9086fcf6ea4fc67efab0157b7c4cc6413eabe377e0f63222b0346b66c7b146c47948d4abb335cd81bbb7ff7232fc1b23a1bc0736d1100495450d4ec75
7
- data.tar.gz: 55feae3396d6ee27b9a436f9a91487e5713cd0c1daedd1b57231d264e125ddde538681d24644423660645396ee0c7f7fbc3fc9fba5704b254a3f16bcd85c6281
6
+ metadata.gz: 54652353065ecc637623af8f306769d15392ee352461f3843a146c937ed52a80cdcb69f35dd0528db276701465bfffa98c5d55357c6edbd58027cd5ed8d32ea9
7
+ data.tar.gz: ac0b82549ed7284a26b7fe29c851614ef0d7a7beca11ac8ec56ae51ec9298389440332dc76593dfe19c65cee292659f31fb6c5ca6c8d0f42e28b8744ea8d31f1
@@ -1,3 +1,4 @@
1
1
  #= require_directory ./lib/fileinput
2
- #= require_directory ./lib/jqx
2
+ # require_directory ./lib/jqx
3
+ #= require_directory ./lib/numbered
3
4
  #= require c80_contest/frontend/ajax_bid_form
@@ -106,8 +106,14 @@ $(function () {
106
106
  });
107
107
 
108
108
  //noinspection JSUnresolvedFunction
109
- $form.find('input#bid_phone').jqxMaskedInput({
110
- mask: '+# (###) ###-##-##'
109
+ // $form.find('input#bid_phone').jqxMaskedInput({
110
+ // mask: '+# (###) ###-##-##'
111
+ // });
112
+
113
+ var numberedFromClass = new Numbered('form#form_bid input#bid_phone', {
114
+ mask: '+# (###) ###-##-##',
115
+ empty: '_',
116
+ placeholder: true
111
117
  });
112
118
 
113
119
  setTimeout(function () {
@@ -0,0 +1,240 @@
1
+ /*! numbered v1.0.2 | pavel-yagodin | MIT License | https://github.com/CSSSR/jquery.numbered */
2
+ (function (root, factory) {
3
+ if (typeof define === 'function' && define.amd) {
4
+ define([], factory);
5
+ } else if (typeof exports === 'object') {
6
+ module.exports = factory();
7
+ } else {
8
+ root.Numbered = factory();
9
+ }
10
+ }(this, function () {
11
+ 'use strict';
12
+
13
+ var defaults = {
14
+ mask: '+7 (###) ### - ## - ##',
15
+ numbered: '#',
16
+ empty: '_',
17
+ placeholder: false
18
+ };
19
+
20
+ var Numbered = function (target, params) {
21
+ var self = this;
22
+
23
+ if (typeof target !== 'object') {
24
+ self.inputs = document.querySelectorAll(target);
25
+ } else if (typeof target.length !== 'undefined') {
26
+ self.inputs = target;
27
+ } else {
28
+ self.inputs = [target];
29
+ }
30
+ self.inputs = Array.prototype.slice.call(self.inputs);
31
+
32
+ params = params || (typeof self.inputs[0].numbered !== 'undefined' ? self.inputs[0].numbered.params : {});
33
+
34
+ for (var def in defaults) {
35
+ if (typeof params[def] === 'undefined') {
36
+ params[def] = defaults[def];
37
+ }
38
+ }
39
+
40
+ self.params = params;
41
+ self.config = {};
42
+
43
+ self.config.placeholder = self.params.mask.replace(new RegExp(self.params.numbered, 'g'), self.params.empty);
44
+ self.config.numbered = self.params.numbered.replace(/([()[\]\.^\#$|?+-])/g, '\\\\$1');
45
+ self.config.numberedCol = self.params.mask.split(self.params.numbered).length -1;
46
+ self.config.empty = self.params.empty.replace(/([()[\]\.^\#$|?+-])/g, '\\$1');
47
+ self.config.mask = self.params.mask.replace(/([()[\]\.^\#$|?+-])/g, '\\$1').replace(new RegExp(self.config.numbered, 'g'), '(\\d)');
48
+ self.config.maskNums = self.params.mask.replace(/[^\d]/gi, '').split('');
49
+ self.config.maskNumsCol = self.config.maskNums.length;
50
+ self.config.regexp = new RegExp('^' + self.config.mask + '$');
51
+ self.config.events = ['input', 'change', 'click', 'focusin', 'blur'];
52
+
53
+
54
+
55
+ self._eventFire = function(el, etype){
56
+ if (el.fireEvent) {
57
+ el.fireEvent('on' + etype);
58
+ } else {
59
+ var evObj = document.createEvent('Events');
60
+ evObj.initEvent(etype, true, false);
61
+ el.dispatchEvent(evObj);
62
+ }
63
+ };
64
+
65
+ self._getSelectionRange = function (oElm) {
66
+ var r = { text: '', start: 0, end: 0, length: 0 };
67
+ if (oElm.setSelectionRange) {
68
+ r.start= oElm.selectionStart;
69
+ r.end = oElm.selectionEnd;
70
+ r.text = (r.start != r.end) ? oElm.value.substring(r.start, r.end): '';
71
+ } else if (document.selection) {
72
+ var oR;
73
+ if (oElm.tagName && oElm.tagName === 'TEXTAREA') {
74
+ var oS = document.selection.createRange().duplicate();
75
+ oR = oElm.createTextRange();
76
+ var sB = oS.getBookmark();
77
+ oR.moveToBookmark(sB);
78
+ } else {
79
+ oR = document.selection.createRange().duplicate();
80
+ }
81
+
82
+ r.text = oR.text;
83
+ for (; oR.moveStart('character', -1) !== 0; r.start++);
84
+ r.end = r.text.length + r.start;
85
+ }
86
+ r.length = r.text.length;
87
+ return r;
88
+ };
89
+
90
+
91
+ self.magic = function (event) {
92
+ var numbered = this.numbered;
93
+ var value = numbered.input.value || ' ';
94
+ var valueFormatted = value.replace(/[^\d]/gi, '').split('').join('');
95
+ var valueFormattedArr = valueFormatted.split('');
96
+ var valueFormattedCol = valueFormattedArr.length;
97
+ var valueFormattedIndex = 0;
98
+ var positionStart = -1;
99
+ var positionEnd = -1;
100
+ var positionOld = self._getSelectionRange(numbered.input);
101
+ var maskNumsIndex = 0;
102
+ var valueFormattedRes = [];
103
+ var maskSplit = numbered.params.mask.split('');
104
+
105
+ for (var key in maskSplit) {
106
+ var val = maskSplit[key];
107
+ key = parseInt(key);
108
+ if (maskNumsIndex <= numbered.config.maskNumsCol && val == numbered.config.maskNums[maskNumsIndex] && val == valueFormattedArr[valueFormattedIndex]) {
109
+ valueFormattedRes.push(val);
110
+ maskNumsIndex++;
111
+ valueFormattedIndex++;
112
+ } else if(val == numbered.params.numbered) {
113
+ if (positionStart < 0) {
114
+ positionStart = key;
115
+ }
116
+ if(valueFormattedIndex < valueFormattedCol) {
117
+ valueFormattedRes.push(valueFormattedArr[valueFormattedIndex]);
118
+ valueFormattedIndex++;
119
+ positionEnd = key;
120
+ } else {
121
+ valueFormattedRes.push(numbered.params.empty);
122
+ }
123
+ } else {
124
+ valueFormattedRes.push(val);
125
+ }
126
+ }
127
+ value = valueFormattedRes.join('');
128
+
129
+
130
+ var position = (positionEnd >= 0 ? positionEnd + 1 : positionStart);
131
+ if (event.type !== 'click') {
132
+ if ((event.type === 'blur' || event.type === 'change') && valueFormattedIndex - maskNumsIndex === 0 && !numbered.params.placeholder) {
133
+ this.value = '';
134
+ } else if (numbered.oldValue !== numbered.input.value || event.type === 'focusin') {
135
+ this.value = value;
136
+ }
137
+ }
138
+
139
+ if(event.type !== 'change' && event.type !== 'blur' && (event.type !== 'click' || (numbered.lastEvent === 'focusin' && event.type === 'click'))) {
140
+ if (numbered.input.setSelectionRange) {
141
+ numbered.input.setSelectionRange(position, position);
142
+ } else if (numbered.input.createTextRange) {
143
+ var range = numbered.input.createTextRange();
144
+ range.collapse(true);
145
+ range.moveEnd('character', position);
146
+ range.moveStart('character', position);
147
+ range.select();
148
+ }
149
+ }
150
+
151
+ numbered.oldValue = this.value;
152
+ numbered.lastEvent = event.type;
153
+ return event.target;
154
+ };
155
+
156
+ for (var index in self.inputs) {
157
+ var $input = self.inputs[index];
158
+ var is = false;
159
+ if (typeof $input.numbered === 'оbject' || typeof $input.numbered !== 'undefined') {
160
+ is = true;
161
+ }
162
+ $input.numbered = {
163
+ input: self.inputs[index],
164
+ config: self.config,
165
+ params: self.params,
166
+ oldValue: false
167
+ };
168
+
169
+ if (!is) {
170
+ for (var key in self.config.events) {
171
+ $input.addEventListener(self.config.events[key], self.magic);
172
+ }
173
+ self._eventFire($input, 'blur');
174
+ }
175
+ self.inputs[index] = $input;
176
+ }
177
+
178
+ self.destroy = function () {
179
+ var self = this;
180
+ for (var index in self.inputs) {
181
+ var $input = self.inputs[index];
182
+
183
+ for (var key in self.config.events) {
184
+ $input.removeEventListener(self.config.events[key], self.magic);
185
+ $input.numbered = null;
186
+ }
187
+ }
188
+ return null;
189
+ };
190
+
191
+ self.validate = function () {
192
+ var self = this;
193
+ var res = self.inputs.length > 1 ? [] : false;
194
+ for (var index in self.inputs) {
195
+ var $input = self.inputs[index];
196
+ var validate;
197
+
198
+ if (self.inputs[index].numbered.config.regexp.test(self.inputs[index].numbered.input.value)) {
199
+ validate = 1;
200
+ } else if (self.inputs[index].numbered.input.value === '' || self.inputs[index].numbered.input.value === self.inputs[index].numbered.config.placeholder) {
201
+ validate = 0;
202
+ } else {
203
+ validate = -1;
204
+ }
205
+
206
+ if (self.inputs.length > 1) {
207
+ res.push(validate);
208
+ } else {
209
+ res = validate;
210
+ }
211
+ }
212
+ return res;
213
+ };
214
+
215
+ self.reInit = function () {
216
+ var self = this;
217
+ var res = self.inputs.length > 1 ? [] : false;
218
+ for (var index in self.inputs) {
219
+ var $input = self.inputs[index];
220
+ self._eventFire($input, 'blur');
221
+ }
222
+ return res;
223
+ };
224
+
225
+ self.setVal = function (value) {
226
+ var self = this;
227
+ var res = self.inputs.length > 1 ? [] : false;
228
+ for (var index in self.inputs) {
229
+ var $input = self.inputs[index];
230
+ $input.value = value;
231
+ self._eventFire($input, 'blur');
232
+ }
233
+ return res;
234
+ };
235
+
236
+ return self;
237
+ };
238
+
239
+ return Numbered;
240
+ }));
@@ -1,3 +1,3 @@
1
1
  module C80Contest
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c80_contest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - C80609A
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-25 00:00:00.000000000 Z
11
+ date: 2017-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -265,6 +265,7 @@ files:
265
265
  - app/assets/javascripts/lib/fileinput/themes/gly/theme.js
266
266
  - app/assets/javascripts/lib/jqx/jqxcore.js
267
267
  - app/assets/javascripts/lib/jqx/jqxmaskedinput.js
268
+ - app/assets/javascripts/lib/numbered/numbered.js
268
269
  - app/assets/stylesheets/c80_contest.scss
269
270
  - app/assets/stylesheets/c80_contest/backend/bid_page.scss
270
271
  - app/assets/stylesheets/c80_contest/backend/settings_page.scss