ezdz-rails 0.2.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 013b8a965d58d22120e8af0a4d77b99a0c0429da
4
- data.tar.gz: d0e8efc95f7a7a01e81ca84cc4a9ca79e4e6b442
3
+ metadata.gz: 11892a10ef2af7031c2d3aa65e589a2c450003e4
4
+ data.tar.gz: 92df16969845147fcb55f6fe5e9ed52a9d891a65
5
5
  SHA512:
6
- metadata.gz: a0306fd923cd419837fe46936c02e65ce678c9bc1370ebc6c92f4006bb08e6047d68ebf90f19a0ebe6caa26137219ffe1c077fbee072ff8224e0d0b5a0b62f94
7
- data.tar.gz: c8fac63273c88fb5c4a36c957573672f848c411c32a2f24341b28ada0d1c39529a497ae537e13ad4c098ff157398cc38bf8b7f2653406e90603ccbb0cc99de83
6
+ metadata.gz: b19e4b806e5cdafb579e1aaf8a9b04a8636a4b944633750517d002a5cd9493c201c716a4cbe06cc103a8b69b56097874b66663576feb737a907137e0a6d81e37
7
+ data.tar.gz: 73b78ca7dce27fbef6a5813bd2d6093ba0f6ac441ae754a8b80d606f9f679874a712f78aa268bedcf2138f8479fca2da96f271a6901ec48d537a34eb6479c94a
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ezdz-Rails
2
2
 
3
- This Gem integrates [Jay Salvat's Ezdz](https://github.com/seiyria/bootstrap-slider)
3
+ This Gem integrates [Jay Salvat's Ezdz](https://github.com/jaysalvat/ezdz)
4
4
  to the Rails assets pipeline.
5
5
 
6
6
  ## Installation
@@ -39,15 +39,15 @@ In the case you'd like to create a new release when [Jay Salvat](https://github.
39
39
 
40
40
  ```
41
41
  $ ./make_new_release.sh
42
- Ensuring Docker image zedtux/bootstrap-slider-rails exists ...
43
- Updating library code to version 5.3.3 ...
44
- Downlading Bootstrap-slider 5.3.3 ...
42
+ Ensuring Docker image zedtux/ezdz-rails exists ...
43
+ Updating library code to version 0.2.0 ...
44
+ Downlading ezdz-slider 0.2.0 ...
45
45
  % Total % Received % Xferd Average Speed Time Time Time Current
46
46
  Dload Upload Total Spent Left Speed
47
- 100 51140 100 51140 0 0 124k 0 --:--:-- --:--:-- --:--:-- 124k
47
+ 100 11471 100 11471 0 0 1977 0 0:00:05 0:00:05 --:--:-- 2673
48
48
  % Total % Received % Xferd Average Speed Time Time Time Current
49
49
  Dload Upload Total Spent Left Speed
50
- 100 8238 100 8238 0 0 28698 0 --:--:-- --:--:-- --:--:-- 28703
50
+ 100 2100 100 2100 0 0 6389 0 --:--:-- --:--:-- --:--:-- 6382
51
51
  Done!
52
52
  Committing new version ...
53
53
  Releasing gem ...
@@ -1,5 +1,5 @@
1
1
  module Ezdz
2
2
  module Rails
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  /* ----------------------------------------------------------------------------
2
- // Ezdz [izy-dizy] jQuery plugin
3
- // v0.2.0 - released 2013-10-16 00:14
2
+ // Ezdz [izy-dizy]
3
+ // v0.2.1 - released 2013-10-16 00:41
4
4
  // Licensed under the MIT license.
5
5
  // https://github.com/jaysalvat/ezdz
6
6
  // ----------------------------------------------------------------------------
@@ -8,7 +8,15 @@
8
8
  // http://jaysalvat.com/
9
9
  // ---------------------------------------------------------------------------*/
10
10
 
11
- (function($) {
11
+ (function (factory) {
12
+ if (typeof define === 'function' && define.amd) {
13
+ define(['jquery'], factory);
14
+ } else if (typeof exports === 'object') {
15
+ factory(require('jquery'));
16
+ } else {
17
+ factory(jQuery);
18
+ }
19
+ }(function ($) {
12
20
  // Default settings
13
21
  var defaults = {
14
22
  className: '',
@@ -43,9 +51,12 @@
43
51
 
44
52
  // Main plugin
45
53
  $.ezdz = function(element, options) {
46
- var self = this,
47
- settings = $.extend(true, {}, defaults, $.ezdz.defaults, options),
48
- $input = $(element);
54
+ this.settings = $.extend(true, {}, defaults, $.ezdz.defaults, options);
55
+ this.$input = $(element);
56
+
57
+ var self = this,
58
+ settings = self.settings,
59
+ $input = self.$input;
49
60
 
50
61
  if (!$input.is('input[type="file"]')) {
51
62
  $.error('Ezdz error - Must be apply to inputs type file.');
@@ -57,48 +68,6 @@
57
68
  return;
58
69
  }
59
70
 
60
- // Public: Inject a file or image in the preview
61
- self.preview = function(path, callback) {
62
- var basename = path.replace(/\\/g,'/').replace( /.*\//, ''),
63
- formatted = settings.format(basename),
64
- $ezdz = $input.parent('.' + settings.classes.main);
65
-
66
- var img = new Image();
67
- img.src = path;
68
-
69
- // Is an image
70
- img.onload = function() {
71
- $ezdz.find('div').html($(img).fadeIn());
72
-
73
- if ($.isFunction(callback)) {
74
- callback.apply(this);
75
- }
76
- };
77
-
78
- // Is not an image
79
- img.onerror = function() {
80
- $ezdz.find('div').html('<span>' + formatted + '</span>');
81
-
82
- if ($.isFunction(callback)) {
83
- callback.apply(this);
84
- }
85
- };
86
-
87
- $ezdz.addClass(settings.classes.accept);
88
- };
89
-
90
- // Public: Destroy ezdz
91
- self.destroy = function() {
92
- $input.parent('.' + settings.classes.main).replaceWith($input);
93
- $input.off('*.ezdz');
94
- $input.data('ezdz', '');
95
- };
96
-
97
- // Public: Extend settings
98
- self.options = function(values) {
99
- $.extend(true, settings, values);
100
- };
101
-
102
71
  // private: Init the plugin
103
72
  var init = function() {
104
73
  var $ezdz, $container, value;
@@ -123,7 +92,7 @@
123
92
  })
124
93
 
125
94
  .addClass(settings.className);
126
-
95
+
127
96
  // Build the whole dropzone
128
97
  $input
129
98
  .wrap($container)
@@ -140,7 +109,7 @@
140
109
 
141
110
  // Trigger the init callback
142
111
  if ($.isFunction(settings.init)) {
143
- settings.init.apply($ezdz, [ value ]);
112
+ settings.init.apply($input, [ value ]);
144
113
  }
145
114
 
146
115
  // Events on the input
@@ -226,91 +195,95 @@
226
195
 
227
196
  // Trigger the reject callback
228
197
  if ($.isFunction(settings.reject)) {
229
- settings.reject.apply($ezdz, [ file, errors ]);
198
+ settings.reject.apply($input, [ file, errors ]);
230
199
  }
231
200
  return false;
232
201
  }
233
202
 
234
203
  // Read the added file
235
- var reader = new FileReader(file),
236
- img = new Image();
204
+ var reader = new FileReader(file);
237
205
 
238
206
  reader.readAsDataURL(file);
239
207
 
240
208
  reader.onload = function(e) {
209
+ var img = new Image(),
210
+ isImage;
211
+
241
212
  file.data = e.target.result;
242
213
  img.src = file.data;
243
214
 
244
- var isImage = (img.width && img.height);
215
+ setTimeout(function() {
216
+ isImage = (img.width && img.height);
245
217
 
246
- // Validator
247
- if (settings.validators.maxSize && file.size > settings.validators.maxSize) {
248
- valid = false;
249
- errors.maxSize = true;
250
- }
251
-
252
- if (isImage) {
253
- file.width = img.width;
254
- file.height = img.height;
255
-
256
- if (settings.validators.width && img.width != settings.validators.width) {
218
+ // Validator
219
+ if (settings.validators.maxSize && file.size > settings.validators.maxSize) {
257
220
  valid = false;
258
- errors.width = true;
221
+ errors.maxSize = true;
259
222
  }
260
223
 
261
- if (settings.validators.maxWidth && img.width > settings.validators.maxWidth) {
262
- valid = false;
263
- errors.maxWidth = true;
264
- }
224
+ if (isImage) {
225
+ file.width = img.width;
226
+ file.height = img.height;
265
227
 
266
- if (settings.validators.minWidth && img.width < settings.validators.minWidth) {
267
- valid = false;
268
- errors.minWidth = true;
269
- }
228
+ if (settings.validators.width && img.width != settings.validators.width) {
229
+ valid = false;
230
+ errors.width = true;
231
+ }
270
232
 
271
- if (settings.validators.height && img.height != settings.validators.height) {
272
- valid = false;
273
- errors.height = true;
274
- }
233
+ if (settings.validators.maxWidth && img.width > settings.validators.maxWidth) {
234
+ valid = false;
235
+ errors.maxWidth = true;
236
+ }
275
237
 
276
- if (settings.validators.maxHeight && img.height > settings.validators.maxHeight) {
277
- valid = false;
278
- errors.maxHeight = true;
279
- }
238
+ if (settings.validators.minWidth && img.width < settings.validators.minWidth) {
239
+ valid = false;
240
+ errors.minWidth = true;
241
+ }
280
242
 
281
- if (settings.validators.minHeight && img.height < settings.validators.minHeight) {
282
- valid = false;
283
- errors.minHeight = true;
284
- }
285
- }
243
+ if (settings.validators.height && img.height != settings.validators.height) {
244
+ valid = false;
245
+ errors.height = true;
246
+ }
286
247
 
287
- // The file is validated, so added to input
288
- if (valid === true) {
289
- $ezdz.find('img').remove();
248
+ if (settings.validators.maxHeight && img.height > settings.validators.maxHeight) {
249
+ valid = false;
250
+ errors.maxHeight = true;
251
+ }
290
252
 
291
- if (isImage && settings.previewImage === true) {
292
- $ezdz.find('div').html($(img).fadeIn());
293
- } else {
294
- $ezdz.find('div').html('<span>' + formatted + '</span>');
253
+ if (settings.validators.minHeight && img.height < settings.validators.minHeight) {
254
+ valid = false;
255
+ errors.minHeight = true;
256
+ }
295
257
  }
296
258
 
297
- $ezdz.addClass(settings.classes.accept);
259
+ // The file is validated, so added to input
260
+ if (valid === true) {
261
+ $ezdz.find('img').remove();
298
262
 
299
- // Trigger the accept callback
300
- if ($.isFunction(settings.accept)) {
301
- settings.accept.apply($ezdz, [ file ]);
302
- }
303
- // The file is invalidated, so rejected
304
- } else {
305
- $input.val('');
263
+ if (isImage && settings.previewImage === true) {
264
+ $ezdz.find('div').html($(img).fadeIn());
265
+ } else {
266
+ $ezdz.find('div').html('<span>' + formatted + '</span>');
267
+ }
268
+
269
+ $ezdz.addClass(settings.classes.accept);
306
270
 
307
- $ezdz.addClass(settings.classes.reject);
271
+ // Trigger the accept callback
272
+ if ($.isFunction(settings.accept)) {
273
+ settings.accept.apply($input, [ file ]);
274
+ }
275
+ // The file is invalidated, so rejected
276
+ } else {
277
+ $input.val('');
308
278
 
309
- // Trigger the reject callback
310
- if ($.isFunction(settings.reject)) {
311
- settings.reject.apply($ezdz, [ file, errors ]);
279
+ $ezdz.addClass(settings.classes.reject);
280
+
281
+ // Trigger the reject callback
282
+ if ($.isFunction(settings.reject)) {
283
+ settings.reject.apply($input, [ file, errors ]);
284
+ }
312
285
  }
313
- }
286
+ }, 1);
314
287
  };
315
288
  });
316
289
  };
@@ -318,22 +291,81 @@
318
291
  init();
319
292
  };
320
293
 
321
- $.fn.ezdz = function(options) {
322
- var args = arguments;
294
+ // Inject a file or image in the preview
295
+ $.ezdz.prototype.preview = function(path, callback) {
296
+ var settings = this.settings,
297
+ $input = this.$input,
298
+ $ezdz = $input.parent('.' + settings.classes.main);
299
+ basename = path.replace(/\\/g,'/').replace( /.*\//, ''),
300
+ formatted = settings.format(basename);
301
+
302
+ var img = new Image();
303
+ img.src = path;
304
+
305
+ // Is an image
306
+ img.onload = function() {
307
+ $ezdz.find('div').html($(img).fadeIn());
308
+
309
+ if ($.isFunction(callback)) {
310
+ callback.apply(this);
311
+ }
312
+ };
323
313
 
324
- return this.each(function() {
325
- var plugin = $(this).data('ezdz');
314
+ // Is not an image
315
+ img.onerror = function() {
316
+ $ezdz.find('div').html('<span>' + formatted + '</span>');
326
317
 
327
- if (!plugin) {
328
- return $(this).data('ezdz', new $.ezdz(this, options));
329
- } if (plugin[options]) {
330
- return plugin[options].apply(this, Array.prototype.slice.call(args, 1));
331
- } else {
332
- $.error('Ezdz error - Method ' + options + ' does not exist.');
318
+ if ($.isFunction(callback)) {
319
+ callback.apply(this);
333
320
  }
334
- });
321
+ };
322
+
323
+ $ezdz.addClass(settings.classes.accept);
335
324
  };
336
325
 
337
- $.ezdz.defaults = defaults;
326
+ // Destroy ezdz
327
+ $.ezdz.prototype.destroy = function() {
328
+ var settings = this.settings,
329
+ $input = this.$input;
330
+
331
+ $input.parent('.' + settings.classes.main).replaceWith($input);
332
+ $input.off('*.ezdz');
333
+ $input.data('ezdz', '');
334
+ };
338
335
 
339
- })(jQuery);
336
+ // Extend settings
337
+ $.ezdz.prototype.options = function(options) {
338
+ var settings = this.settings;
339
+
340
+ if (!options) {
341
+ return settings;
342
+ }
343
+
344
+ $.extend(true, this.settings, options);
345
+ };
346
+
347
+ // Get input container
348
+ $.ezdz.prototype.container = function() {
349
+ var settings = this.settings,
350
+ $input = this.$input;
351
+
352
+ return $input.parent('.' + settings.classes.main);
353
+ };
354
+
355
+ // Default options
356
+ $.ezdz.prototype.defaults = defaults;
357
+
358
+ // jQuery plugin
359
+ $.fn.ezdz = function(options) {
360
+ var args = arguments,
361
+ plugin = $(this).data('ezdz');
362
+
363
+ if (!plugin) {
364
+ return $(this).data('ezdz', new $.ezdz(this, options));
365
+ } if (plugin[options]) {
366
+ return plugin[options].apply(plugin, Array.prototype.slice.call(args, 1));
367
+ } else {
368
+ $.error('Ezdz error - Method ' + options + ' does not exist.');
369
+ }
370
+ };
371
+ }));
@@ -1,6 +1,6 @@
1
1
  /* ----------------------------------------------------------------------------
2
- // Ezdz [izy-dizy] jQuery plugin
3
- // v0.2.0 - released 2013-10-16 00:14
2
+ // Ezdz [izy-dizy]
3
+ // v0.2.1 - released 2013-10-16 00:41
4
4
  // Licensed under the MIT license.
5
5
  // https://github.com/jaysalvat/ezdz
6
6
  // ----------------------------------------------------------------------------
@@ -23,7 +23,7 @@
23
23
 
24
24
  .ezdz-dropzone div {
25
25
  /* */
26
- }
26
+ }
27
27
 
28
28
  .ezdz-dropzone span {
29
29
  border-radius: 20px;
@@ -68,7 +68,7 @@
68
68
  border: 10px dotted darkgray;
69
69
  color: darkgray;
70
70
  }
71
-
71
+
72
72
  .ezdz-enter {
73
73
  border: 10px solid black;
74
74
  color: black;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezdz-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedr Browne