helios 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +50 -21
  3. data/README.md +27 -2
  4. data/helios.gemspec +10 -6
  5. data/lib/helios.rb +10 -4
  6. data/lib/helios/backend.rb +29 -22
  7. data/lib/helios/backend/data.rb +10 -5
  8. data/lib/helios/backend/in-app-purchase.rb +4 -2
  9. data/lib/helios/backend/newsstand.rb +97 -0
  10. data/lib/helios/backend/passbook.rb +8 -2
  11. data/lib/helios/backend/push-notification.rb +25 -12
  12. data/lib/helios/commands/console.rb +4 -10
  13. data/lib/helios/commands/new.rb +0 -1
  14. data/lib/helios/commands/server.rb +4 -1
  15. data/lib/helios/frontend.rb +6 -14
  16. data/lib/helios/frontend/images/helios.svg +33 -0
  17. data/lib/helios/frontend/javascripts/helios.coffee +39 -3
  18. data/lib/helios/frontend/javascripts/helios/collections.coffee +10 -2
  19. data/lib/helios/frontend/javascripts/helios/models.coffee +4 -1
  20. data/lib/helios/frontend/javascripts/helios/router.coffee +13 -1
  21. data/lib/helios/frontend/javascripts/helios/views.coffee +82 -8
  22. data/lib/helios/frontend/javascripts/vendor/jquery/jquery.fileupload-ui.js +807 -0
  23. data/lib/helios/frontend/javascripts/vendor/jquery/jquery.fileupload.js +1201 -0
  24. data/lib/helios/frontend/javascripts/vendor/jquery/jquery.ui.widget.js +530 -0
  25. data/lib/helios/frontend/javascripts/vendor/linkheaders.js +117 -0
  26. data/lib/helios/frontend/stylesheets/_iphone.sass +1 -1
  27. data/lib/helios/frontend/stylesheets/screen.sass +2 -6
  28. data/lib/helios/frontend/templates/{entities.jst.tpl → data/entities.jst.tpl} +0 -0
  29. data/lib/helios/frontend/templates/{receipts.jst.tpl → in-app-purchase/receipts.jst.tpl} +0 -0
  30. data/lib/helios/frontend/templates/navigation.jst.tpl +31 -0
  31. data/lib/helios/frontend/templates/newsstand/issues.jst.tpl +16 -0
  32. data/lib/helios/frontend/templates/newsstand/new.jst.tpl +28 -0
  33. data/lib/helios/frontend/templates/{passes.jst.tpl → passbook/passes.jst.tpl} +0 -0
  34. data/lib/helios/frontend/templates/{compose.jst.tpl → push-notification/compose.jst.tpl} +0 -0
  35. data/lib/helios/frontend/templates/{devices.jst.tpl → push-notification/devices.jst.tpl} +0 -0
  36. data/lib/helios/frontend/views/index.haml +4 -28
  37. data/lib/helios/templates/.env.erb +1 -0
  38. data/lib/helios/templates/.gitignore +3 -0
  39. data/lib/helios/version.rb +1 -1
  40. metadata +86 -20
  41. data/lib/helios/frontend/stylesheets/_bariol.scss +0 -41
@@ -0,0 +1,807 @@
1
+ /*
2
+ * jQuery File Upload User Interface Plugin 7.4.1
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2010, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /*jslint nomen: true, unparam: true, regexp: true */
13
+ /*global define, window, URL, webkitURL, FileReader */
14
+
15
+ (function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define([
20
+ 'jquery',
21
+ 'tmpl',
22
+ 'load-image',
23
+ './jquery.fileupload-fp'
24
+ ], factory);
25
+ } else {
26
+ // Browser globals:
27
+ factory(
28
+ window.jQuery,
29
+ window.tmpl,
30
+ window.loadImage
31
+ );
32
+ }
33
+ }(function ($, tmpl, loadImage) {
34
+ 'use strict';
35
+
36
+ // The UI version extends the file upload widget
37
+ // and adds complete user interface interaction:
38
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
39
+
40
+ options: {
41
+ // By default, files added to the widget are uploaded as soon
42
+ // as the user clicks on the start buttons. To enable automatic
43
+ // uploads, set the following option to true:
44
+ autoUpload: false,
45
+ // The following option limits the number of files that are
46
+ // allowed to be uploaded using this widget:
47
+ maxNumberOfFiles: undefined,
48
+ // The maximum allowed file size:
49
+ maxFileSize: undefined,
50
+ // The minimum allowed file size:
51
+ minFileSize: undefined,
52
+ // The regular expression for allowed file types, matches
53
+ // against either file type or file name:
54
+ acceptFileTypes: /.+$/i,
55
+ // The regular expression to define for which files a preview
56
+ // image is shown, matched against the file type:
57
+ previewSourceFileTypes: /^image\/(gif|jpeg|png)$/,
58
+ // The maximum file size of images that are to be displayed as preview:
59
+ previewSourceMaxFileSize: 5000000, // 5MB
60
+ // The maximum width of the preview images:
61
+ previewMaxWidth: 80,
62
+ // The maximum height of the preview images:
63
+ previewMaxHeight: 80,
64
+ // By default, preview images are displayed as canvas elements
65
+ // if supported by the browser. Set the following option to false
66
+ // to always display preview images as img elements:
67
+ previewAsCanvas: true,
68
+ // The ID of the upload template:
69
+ uploadTemplateId: 'template-upload',
70
+ // The ID of the download template:
71
+ downloadTemplateId: 'template-download',
72
+ // The container for the list of files. If undefined, it is set to
73
+ // an element with class "files" inside of the widget element:
74
+ filesContainer: undefined,
75
+ // By default, files are appended to the files container.
76
+ // Set the following option to true, to prepend files instead:
77
+ prependFiles: false,
78
+ // The expected data type of the upload response, sets the dataType
79
+ // option of the $.ajax upload requests:
80
+ dataType: 'json',
81
+
82
+ // The add callback is invoked as soon as files are added to the fileupload
83
+ // widget (via file input selection, drag & drop or add API call).
84
+ // See the basic file upload widget for more information:
85
+ add: function (e, data) {
86
+ var that = $(this).data('blueimp-fileupload') ||
87
+ $(this).data('fileupload'),
88
+ options = that.options,
89
+ files = data.files;
90
+ $(this).fileupload('process', data).done(function () {
91
+ that._adjustMaxNumberOfFiles(-files.length);
92
+ data.maxNumberOfFilesAdjusted = true;
93
+ data.files.valid = data.isValidated = that._validate(files);
94
+ data.context = that._renderUpload(files).data('data', data);
95
+ options.filesContainer[
96
+ options.prependFiles ? 'prepend' : 'append'
97
+ ](data.context);
98
+ that._renderPreviews(data);
99
+ that._forceReflow(data.context);
100
+ that._transition(data.context).done(
101
+ function () {
102
+ if ((that._trigger('added', e, data) !== false) &&
103
+ (options.autoUpload || data.autoUpload) &&
104
+ data.autoUpload !== false && data.isValidated) {
105
+ data.submit();
106
+ }
107
+ }
108
+ );
109
+ });
110
+ },
111
+ // Callback for the start of each file upload request:
112
+ send: function (e, data) {
113
+ var that = $(this).data('blueimp-fileupload') ||
114
+ $(this).data('fileupload');
115
+ if (!data.isValidated) {
116
+ if (!data.maxNumberOfFilesAdjusted) {
117
+ that._adjustMaxNumberOfFiles(-data.files.length);
118
+ data.maxNumberOfFilesAdjusted = true;
119
+ }
120
+ if (!that._validate(data.files)) {
121
+ return false;
122
+ }
123
+ }
124
+ if (data.context && data.dataType &&
125
+ data.dataType.substr(0, 6) === 'iframe') {
126
+ // Iframe Transport does not support progress events.
127
+ // In lack of an indeterminate progress bar, we set
128
+ // the progress to 100%, showing the full animated bar:
129
+ data.context
130
+ .find('.progress').addClass(
131
+ !$.support.transition && 'progress-animated'
132
+ )
133
+ .attr('aria-valuenow', 100)
134
+ .find('.bar').css(
135
+ 'width',
136
+ '100%'
137
+ );
138
+ }
139
+ return that._trigger('sent', e, data);
140
+ },
141
+ // Callback for successful uploads:
142
+ done: function (e, data) {
143
+ var that = $(this).data('blueimp-fileupload') ||
144
+ $(this).data('fileupload'),
145
+ files = that._getFilesFromResponse(data),
146
+ template,
147
+ deferred;
148
+ if (data.context) {
149
+ data.context.each(function (index) {
150
+ var file = files[index] ||
151
+ {error: 'Empty file upload result'},
152
+ deferred = that._addFinishedDeferreds();
153
+ if (file.error) {
154
+ that._adjustMaxNumberOfFiles(1);
155
+ }
156
+ that._transition($(this)).done(
157
+ function () {
158
+ var node = $(this);
159
+ template = that._renderDownload([file])
160
+ .replaceAll(node);
161
+ that._forceReflow(template);
162
+ that._transition(template).done(
163
+ function () {
164
+ data.context = $(this);
165
+ that._trigger('completed', e, data);
166
+ that._trigger('finished', e, data);
167
+ deferred.resolve();
168
+ }
169
+ );
170
+ }
171
+ );
172
+ });
173
+ } else {
174
+ if (files.length) {
175
+ $.each(files, function (index, file) {
176
+ if (data.maxNumberOfFilesAdjusted && file.error) {
177
+ that._adjustMaxNumberOfFiles(1);
178
+ } else if (!data.maxNumberOfFilesAdjusted &&
179
+ !file.error) {
180
+ that._adjustMaxNumberOfFiles(-1);
181
+ }
182
+ });
183
+ data.maxNumberOfFilesAdjusted = true;
184
+ }
185
+ template = that._renderDownload(files)
186
+ .appendTo(that.options.filesContainer);
187
+ that._forceReflow(template);
188
+ deferred = that._addFinishedDeferreds();
189
+ that._transition(template).done(
190
+ function () {
191
+ data.context = $(this);
192
+ that._trigger('completed', e, data);
193
+ that._trigger('finished', e, data);
194
+ deferred.resolve();
195
+ }
196
+ );
197
+ }
198
+ },
199
+ // Callback for failed (abort or error) uploads:
200
+ fail: function (e, data) {
201
+ var that = $(this).data('blueimp-fileupload') ||
202
+ $(this).data('fileupload'),
203
+ template,
204
+ deferred;
205
+ if (data.maxNumberOfFilesAdjusted) {
206
+ that._adjustMaxNumberOfFiles(data.files.length);
207
+ }
208
+ if (data.context) {
209
+ data.context.each(function (index) {
210
+ if (data.errorThrown !== 'abort') {
211
+ var file = data.files[index];
212
+ file.error = file.error || data.errorThrown ||
213
+ true;
214
+ deferred = that._addFinishedDeferreds();
215
+ that._transition($(this)).done(
216
+ function () {
217
+ var node = $(this);
218
+ template = that._renderDownload([file])
219
+ .replaceAll(node);
220
+ that._forceReflow(template);
221
+ that._transition(template).done(
222
+ function () {
223
+ data.context = $(this);
224
+ that._trigger('failed', e, data);
225
+ that._trigger('finished', e, data);
226
+ deferred.resolve();
227
+ }
228
+ );
229
+ }
230
+ );
231
+ } else {
232
+ deferred = that._addFinishedDeferreds();
233
+ that._transition($(this)).done(
234
+ function () {
235
+ $(this).remove();
236
+ that._trigger('failed', e, data);
237
+ that._trigger('finished', e, data);
238
+ deferred.resolve();
239
+ }
240
+ );
241
+ }
242
+ });
243
+ } else if (data.errorThrown !== 'abort') {
244
+ data.context = that._renderUpload(data.files)
245
+ .appendTo(that.options.filesContainer)
246
+ .data('data', data);
247
+ that._forceReflow(data.context);
248
+ deferred = that._addFinishedDeferreds();
249
+ that._transition(data.context).done(
250
+ function () {
251
+ data.context = $(this);
252
+ that._trigger('failed', e, data);
253
+ that._trigger('finished', e, data);
254
+ deferred.resolve();
255
+ }
256
+ );
257
+ } else {
258
+ that._trigger('failed', e, data);
259
+ that._trigger('finished', e, data);
260
+ that._addFinishedDeferreds().resolve();
261
+ }
262
+ },
263
+ // Callback for upload progress events:
264
+ progress: function (e, data) {
265
+ if (data.context) {
266
+ var progress = Math.floor(data.loaded / data.total * 100);
267
+ data.context.find('.progress')
268
+ .attr('aria-valuenow', progress)
269
+ .find('.bar').css(
270
+ 'width',
271
+ progress + '%'
272
+ );
273
+ }
274
+ },
275
+ // Callback for global upload progress events:
276
+ progressall: function (e, data) {
277
+ var $this = $(this),
278
+ progress = Math.floor(data.loaded / data.total * 100),
279
+ globalProgressNode = $this.find('.fileupload-progress'),
280
+ extendedProgressNode = globalProgressNode
281
+ .find('.progress-extended');
282
+ if (extendedProgressNode.length) {
283
+ extendedProgressNode.html(
284
+ ($this.data('blueimp-fileupload') || $this.data('fileupload'))
285
+ ._renderExtendedProgress(data)
286
+ );
287
+ }
288
+ globalProgressNode
289
+ .find('.progress')
290
+ .attr('aria-valuenow', progress)
291
+ .find('.bar').css(
292
+ 'width',
293
+ progress + '%'
294
+ );
295
+ },
296
+ // Callback for uploads start, equivalent to the global ajaxStart event:
297
+ start: function (e) {
298
+ var that = $(this).data('blueimp-fileupload') ||
299
+ $(this).data('fileupload');
300
+ that._resetFinishedDeferreds();
301
+ that._transition($(this).find('.fileupload-progress')).done(
302
+ function () {
303
+ that._trigger('started', e);
304
+ }
305
+ );
306
+ },
307
+ // Callback for uploads stop, equivalent to the global ajaxStop event:
308
+ stop: function (e) {
309
+ var that = $(this).data('blueimp-fileupload') ||
310
+ $(this).data('fileupload'),
311
+ deferred = that._addFinishedDeferreds();
312
+ $.when.apply($, that._getFinishedDeferreds())
313
+ .done(function () {
314
+ that._trigger('stopped', e);
315
+ });
316
+ that._transition($(this).find('.fileupload-progress')).done(
317
+ function () {
318
+ $(this).find('.progress')
319
+ .attr('aria-valuenow', '0')
320
+ .find('.bar').css('width', '0%');
321
+ $(this).find('.progress-extended').html(' ');
322
+ deferred.resolve();
323
+ }
324
+ );
325
+ },
326
+ // Callback for file deletion:
327
+ destroy: function (e, data) {
328
+ var that = $(this).data('blueimp-fileupload') ||
329
+ $(this).data('fileupload');
330
+ if (data.url) {
331
+ $.ajax(data);
332
+ that._adjustMaxNumberOfFiles(1);
333
+ }
334
+ that._transition(data.context).done(
335
+ function () {
336
+ $(this).remove();
337
+ that._trigger('destroyed', e, data);
338
+ }
339
+ );
340
+ }
341
+ },
342
+
343
+ _resetFinishedDeferreds: function () {
344
+ this._finishedUploads = [];
345
+ },
346
+
347
+ _addFinishedDeferreds: function (deferred) {
348
+ if (!deferred) {
349
+ deferred = $.Deferred();
350
+ }
351
+ this._finishedUploads.push(deferred);
352
+ return deferred;
353
+ },
354
+
355
+ _getFinishedDeferreds: function () {
356
+ return this._finishedUploads;
357
+ },
358
+
359
+ _getFilesFromResponse: function (data) {
360
+ if (data.result && $.isArray(data.result.files)) {
361
+ return data.result.files;
362
+ }
363
+ return [];
364
+ },
365
+
366
+ // Link handler, that allows to download files
367
+ // by drag & drop of the links to the desktop:
368
+ _enableDragToDesktop: function () {
369
+ var link = $(this),
370
+ url = link.prop('href'),
371
+ name = link.prop('download'),
372
+ type = 'application/octet-stream';
373
+ link.bind('dragstart', function (e) {
374
+ try {
375
+ e.originalEvent.dataTransfer.setData(
376
+ 'DownloadURL',
377
+ [type, name, url].join(':')
378
+ );
379
+ } catch (err) {}
380
+ });
381
+ },
382
+
383
+ _adjustMaxNumberOfFiles: function (operand) {
384
+ if (typeof this.options.maxNumberOfFiles === 'number') {
385
+ this.options.maxNumberOfFiles += operand;
386
+ if (this.options.maxNumberOfFiles < 1) {
387
+ this._disableFileInputButton();
388
+ } else {
389
+ this._enableFileInputButton();
390
+ }
391
+ }
392
+ },
393
+
394
+ _formatFileSize: function (bytes) {
395
+ if (typeof bytes !== 'number') {
396
+ return '';
397
+ }
398
+ if (bytes >= 1000000000) {
399
+ return (bytes / 1000000000).toFixed(2) + ' GB';
400
+ }
401
+ if (bytes >= 1000000) {
402
+ return (bytes / 1000000).toFixed(2) + ' MB';
403
+ }
404
+ return (bytes / 1000).toFixed(2) + ' KB';
405
+ },
406
+
407
+ _formatBitrate: function (bits) {
408
+ if (typeof bits !== 'number') {
409
+ return '';
410
+ }
411
+ if (bits >= 1000000000) {
412
+ return (bits / 1000000000).toFixed(2) + ' Gbit/s';
413
+ }
414
+ if (bits >= 1000000) {
415
+ return (bits / 1000000).toFixed(2) + ' Mbit/s';
416
+ }
417
+ if (bits >= 1000) {
418
+ return (bits / 1000).toFixed(2) + ' kbit/s';
419
+ }
420
+ return bits.toFixed(2) + ' bit/s';
421
+ },
422
+
423
+ _formatTime: function (seconds) {
424
+ var date = new Date(seconds * 1000),
425
+ days = Math.floor(seconds / 86400);
426
+ days = days ? days + 'd ' : '';
427
+ return days +
428
+ ('0' + date.getUTCHours()).slice(-2) + ':' +
429
+ ('0' + date.getUTCMinutes()).slice(-2) + ':' +
430
+ ('0' + date.getUTCSeconds()).slice(-2);
431
+ },
432
+
433
+ _formatPercentage: function (floatValue) {
434
+ return (floatValue * 100).toFixed(2) + ' %';
435
+ },
436
+
437
+ _renderExtendedProgress: function (data) {
438
+ return this._formatBitrate(data.bitrate) + ' | ' +
439
+ this._formatTime(
440
+ (data.total - data.loaded) * 8 / data.bitrate
441
+ ) + ' | ' +
442
+ this._formatPercentage(
443
+ data.loaded / data.total
444
+ ) + ' | ' +
445
+ this._formatFileSize(data.loaded) + ' / ' +
446
+ this._formatFileSize(data.total);
447
+ },
448
+
449
+ _hasError: function (file) {
450
+ if (file.error) {
451
+ return file.error;
452
+ }
453
+ // The number of added files is subtracted from
454
+ // maxNumberOfFiles before validation, so we check if
455
+ // maxNumberOfFiles is below 0 (instead of below 1):
456
+ if (this.options.maxNumberOfFiles < 0) {
457
+ return 'Maximum number of files exceeded';
458
+ }
459
+ // Files are accepted if either the file type or the file name
460
+ // matches against the acceptFileTypes regular expression, as
461
+ // only browsers with support for the File API report the type:
462
+ if (!(this.options.acceptFileTypes.test(file.type) ||
463
+ this.options.acceptFileTypes.test(file.name))) {
464
+ return 'Filetype not allowed';
465
+ }
466
+ if (this.options.maxFileSize &&
467
+ file.size > this.options.maxFileSize) {
468
+ return 'File is too big';
469
+ }
470
+ if (typeof file.size === 'number' &&
471
+ file.size < this.options.minFileSize) {
472
+ return 'File is too small';
473
+ }
474
+ return null;
475
+ },
476
+
477
+ _validate: function (files) {
478
+ var that = this,
479
+ valid = !!files.length;
480
+ $.each(files, function (index, file) {
481
+ file.error = that._hasError(file);
482
+ if (file.error) {
483
+ valid = false;
484
+ }
485
+ });
486
+ return valid;
487
+ },
488
+
489
+ _renderTemplate: function (func, files) {
490
+ if (!func) {
491
+ return $();
492
+ }
493
+ var result = func({
494
+ files: files,
495
+ formatFileSize: this._formatFileSize,
496
+ options: this.options
497
+ });
498
+ if (result instanceof $) {
499
+ return result;
500
+ }
501
+ return $(this.options.templatesContainer).html(result).children();
502
+ },
503
+
504
+ _renderPreview: function (file, node) {
505
+ var that = this,
506
+ options = this.options,
507
+ dfd = $.Deferred();
508
+ return ((loadImage && loadImage(
509
+ file,
510
+ function (img) {
511
+ node.append(img);
512
+ that._forceReflow(node);
513
+ that._transition(node).done(function () {
514
+ dfd.resolveWith(node);
515
+ });
516
+ if (!$.contains(that.document[0].body, node[0])) {
517
+ // If the element is not part of the DOM,
518
+ // transition events are not triggered,
519
+ // so we have to resolve manually:
520
+ dfd.resolveWith(node);
521
+ }
522
+ node.on('remove', function () {
523
+ // If the element is removed before the
524
+ // transition finishes, transition events are
525
+ // not triggered, resolve manually:
526
+ dfd.resolveWith(node);
527
+ });
528
+ },
529
+ {
530
+ maxWidth: options.previewMaxWidth,
531
+ maxHeight: options.previewMaxHeight,
532
+ canvas: options.previewAsCanvas
533
+ }
534
+ )) || dfd.resolveWith(node)) && dfd;
535
+ },
536
+
537
+ _renderPreviews: function (data) {
538
+ var that = this,
539
+ options = this.options;
540
+ data.context.find('.preview span').each(function (index, element) {
541
+ var file = data.files[index];
542
+ if (options.previewSourceFileTypes.test(file.type) &&
543
+ ($.type(options.previewSourceMaxFileSize) !== 'number' ||
544
+ file.size < options.previewSourceMaxFileSize)) {
545
+ that._processingQueue = that._processingQueue.pipe(function () {
546
+ var dfd = $.Deferred(),
547
+ ev = $.Event('previewdone', {
548
+ target: element
549
+ });
550
+ that._renderPreview(file, $(element)).done(
551
+ function () {
552
+ that._trigger(ev.type, ev, data);
553
+ dfd.resolveWith(that);
554
+ }
555
+ );
556
+ return dfd.promise();
557
+ });
558
+ }
559
+ });
560
+ return this._processingQueue;
561
+ },
562
+
563
+ _renderUpload: function (files) {
564
+ return this._renderTemplate(
565
+ this.options.uploadTemplate,
566
+ files
567
+ );
568
+ },
569
+
570
+ _renderDownload: function (files) {
571
+ return this._renderTemplate(
572
+ this.options.downloadTemplate,
573
+ files
574
+ ).find('a[download]').each(this._enableDragToDesktop).end();
575
+ },
576
+
577
+ _startHandler: function (e) {
578
+ e.preventDefault();
579
+ var button = $(e.currentTarget),
580
+ template = button.closest('.template-upload'),
581
+ data = template.data('data');
582
+ if (data && data.submit && !data.jqXHR && data.submit()) {
583
+ button.prop('disabled', true);
584
+ }
585
+ },
586
+
587
+ _cancelHandler: function (e) {
588
+ e.preventDefault();
589
+ var template = $(e.currentTarget).closest('.template-upload'),
590
+ data = template.data('data') || {};
591
+ if (!data.jqXHR) {
592
+ data.errorThrown = 'abort';
593
+ this._trigger('fail', e, data);
594
+ } else {
595
+ data.jqXHR.abort();
596
+ }
597
+ },
598
+
599
+ _deleteHandler: function (e) {
600
+ e.preventDefault();
601
+ var button = $(e.currentTarget);
602
+ this._trigger('destroy', e, $.extend({
603
+ context: button.closest('.template-download'),
604
+ type: 'DELETE',
605
+ dataType: this.options.dataType
606
+ }, button.data()));
607
+ },
608
+
609
+ _forceReflow: function (node) {
610
+ return $.support.transition && node.length &&
611
+ node[0].offsetWidth;
612
+ },
613
+
614
+ _transition: function (node) {
615
+ var dfd = $.Deferred();
616
+ if ($.support.transition && node.hasClass('fade') && node.is(':visible')) {
617
+ node.bind(
618
+ $.support.transition.end,
619
+ function (e) {
620
+ // Make sure we don't respond to other transitions events
621
+ // in the container element, e.g. from button elements:
622
+ if (e.target === node[0]) {
623
+ node.unbind($.support.transition.end);
624
+ dfd.resolveWith(node);
625
+ }
626
+ }
627
+ ).toggleClass('in');
628
+ } else {
629
+ node.toggleClass('in');
630
+ dfd.resolveWith(node);
631
+ }
632
+ return dfd;
633
+ },
634
+
635
+ _initButtonBarEventHandlers: function () {
636
+ var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
637
+ filesList = this.options.filesContainer;
638
+ this._on(fileUploadButtonBar.find('.start'), {
639
+ click: function (e) {
640
+ e.preventDefault();
641
+ filesList.find('.start').click();
642
+ }
643
+ });
644
+ this._on(fileUploadButtonBar.find('.cancel'), {
645
+ click: function (e) {
646
+ e.preventDefault();
647
+ filesList.find('.cancel').click();
648
+ }
649
+ });
650
+ this._on(fileUploadButtonBar.find('.delete'), {
651
+ click: function (e) {
652
+ e.preventDefault();
653
+ filesList.find('.toggle:checked')
654
+ .closest('.template-download')
655
+ .find('.delete').click();
656
+ fileUploadButtonBar.find('.toggle')
657
+ .prop('checked', false);
658
+ }
659
+ });
660
+ this._on(fileUploadButtonBar.find('.toggle'), {
661
+ change: function (e) {
662
+ filesList.find('.toggle').prop(
663
+ 'checked',
664
+ $(e.currentTarget).is(':checked')
665
+ );
666
+ }
667
+ });
668
+ },
669
+
670
+ _destroyButtonBarEventHandlers: function () {
671
+ this._off(
672
+ this.element.find('.fileupload-buttonbar')
673
+ .find('.start, .cancel, .delete'),
674
+ 'click'
675
+ );
676
+ this._off(
677
+ this.element.find('.fileupload-buttonbar .toggle'),
678
+ 'change.'
679
+ );
680
+ },
681
+
682
+ _initEventHandlers: function () {
683
+ this._super();
684
+ this._on(this.options.filesContainer, {
685
+ 'click .start': this._startHandler,
686
+ 'click .cancel': this._cancelHandler,
687
+ 'click .delete': this._deleteHandler
688
+ });
689
+ this._initButtonBarEventHandlers();
690
+ },
691
+
692
+ _destroyEventHandlers: function () {
693
+ this._destroyButtonBarEventHandlers();
694
+ this._off(this.options.filesContainer, 'click');
695
+ this._super();
696
+ },
697
+
698
+ _enableFileInputButton: function () {
699
+ this.element.find('.fileinput-button input')
700
+ .prop('disabled', false)
701
+ .parent().removeClass('disabled');
702
+ },
703
+
704
+ _disableFileInputButton: function () {
705
+ this.element.find('.fileinput-button input')
706
+ .prop('disabled', true)
707
+ .parent().addClass('disabled');
708
+ },
709
+
710
+ _initTemplates: function () {
711
+ var options = this.options;
712
+ options.templatesContainer = this.document[0].createElement(
713
+ options.filesContainer.prop('nodeName')
714
+ );
715
+ if (tmpl) {
716
+ if (options.uploadTemplateId) {
717
+ options.uploadTemplate = tmpl(options.uploadTemplateId);
718
+ }
719
+ if (options.downloadTemplateId) {
720
+ options.downloadTemplate = tmpl(options.downloadTemplateId);
721
+ }
722
+ }
723
+ },
724
+
725
+ _initFilesContainer: function () {
726
+ var options = this.options;
727
+ if (options.filesContainer === undefined) {
728
+ options.filesContainer = this.element.find('.files');
729
+ } else if (!(options.filesContainer instanceof $)) {
730
+ options.filesContainer = $(options.filesContainer);
731
+ }
732
+ },
733
+
734
+ _stringToRegExp: function (str) {
735
+ var parts = str.split('/'),
736
+ modifiers = parts.pop();
737
+ parts.shift();
738
+ return new RegExp(parts.join('/'), modifiers);
739
+ },
740
+
741
+ _initRegExpOptions: function () {
742
+ var options = this.options;
743
+ if ($.type(options.acceptFileTypes) === 'string') {
744
+ options.acceptFileTypes = this._stringToRegExp(
745
+ options.acceptFileTypes
746
+ );
747
+ }
748
+ if ($.type(options.previewSourceFileTypes) === 'string') {
749
+ options.previewSourceFileTypes = this._stringToRegExp(
750
+ options.previewSourceFileTypes
751
+ );
752
+ }
753
+ },
754
+
755
+ _initSpecialOptions: function () {
756
+ this._super();
757
+ this._initFilesContainer();
758
+ this._initTemplates();
759
+ this._initRegExpOptions();
760
+ },
761
+
762
+ _setOption: function (key, value) {
763
+ this._super(key, value);
764
+ if (key === 'maxNumberOfFiles') {
765
+ this._adjustMaxNumberOfFiles(0);
766
+ }
767
+ },
768
+
769
+ _create: function () {
770
+ this._super();
771
+ this._refreshOptionsList.push(
772
+ 'filesContainer',
773
+ 'uploadTemplateId',
774
+ 'downloadTemplateId'
775
+ );
776
+ if (!this._processingQueue) {
777
+ this._processingQueue = $.Deferred().resolveWith(this).promise();
778
+ this.process = function () {
779
+ return this._processingQueue;
780
+ };
781
+ }
782
+ this._resetFinishedDeferreds();
783
+ },
784
+
785
+ enable: function () {
786
+ var wasDisabled = false;
787
+ if (this.options.disabled) {
788
+ wasDisabled = true;
789
+ }
790
+ this._super();
791
+ if (wasDisabled) {
792
+ this.element.find('input, button').prop('disabled', false);
793
+ this._enableFileInputButton();
794
+ }
795
+ },
796
+
797
+ disable: function () {
798
+ if (!this.options.disabled) {
799
+ this.element.find('input, button').prop('disabled', true);
800
+ this._disableFileInputButton();
801
+ }
802
+ this._super();
803
+ }
804
+
805
+ });
806
+
807
+ }));