redde 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +3 -3
  5. data/LICIENSE.md +21 -0
  6. data/README.md +53 -14
  7. data/lib/generators/redde/layout/layout_generator.rb +7 -4
  8. data/lib/generators/redde/layout/templates/assets/images/admin/error-label-triangle.png +0 -0
  9. data/lib/generators/redde/layout/templates/assets/images/admin/favicon.png +0 -0
  10. data/lib/generators/redde/layout/templates/assets/javascripts/admin.js +9 -76
  11. data/lib/generators/redde/layout/templates/assets/redactor/images/.keep +0 -0
  12. data/lib/generators/redde/layout/templates/assets/redactor/images/redactor/icons.png +0 -0
  13. data/lib/generators/redde/layout/templates/assets/redactor/javascripts/jquery-migrate-1.2.1.js +521 -0
  14. data/lib/generators/redde/layout/templates/assets/{images/admin → redactor/javascripts}/redactor/redactor.js.erb +9 -21
  15. data/lib/generators/redde/layout/templates/assets/{images/admin/redactor/css/redactor.css → redactor/stylesheets/redactor/redactor.css.scss} +1 -1
  16. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/error-msg.sass +47 -0
  17. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/paginate.sass +28 -0
  18. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/pagination.scss +28 -0
  19. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/phead-tabs.sass +27 -0
  20. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/default.scss +0 -0
  21. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/defaults/input.sass +35 -0
  22. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/header.sass +50 -0
  23. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/launchbar.sass +23 -0
  24. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/main.sass +39 -0
  25. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/page-header.sass +19 -0
  26. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/page-sidebar.sass +22 -0
  27. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/sidebar.sass +30 -0
  28. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/reset.sass +33 -0
  29. data/lib/generators/redde/layout/templates/assets/stylesheets/admin.scss +9 -9
  30. data/lib/generators/redde/layout/templates/base/_header.html.haml +12 -0
  31. data/lib/generators/redde/layout/templates/base/_launchbar.html.haml +11 -0
  32. data/lib/generators/redde/layout/templates/base/_sidebar.html.haml +15 -0
  33. data/lib/generators/redde/layout/templates/base/_validate.haml +8 -0
  34. data/lib/generators/redde/layout/templates/base/welcome.haml +2 -0
  35. data/lib/generators/redde/layout/templates/controllers/base_controller.rb +5 -0
  36. data/lib/generators/redde/layout/templates/layouts/admin.html.haml +14 -15
  37. data/lib/generators/redde/scaffold/scaffold_generator.rb +8 -0
  38. data/lib/generators/redde/scaffold/templates/edit.html.haml +2 -6
  39. data/lib/generators/redde/scaffold/templates/index.html.haml +1 -1
  40. data/lib/redde/version.rb +1 -1
  41. data/lib/redde.rb +3 -0
  42. data/redde.gemspec +11 -10
  43. data/spec/dummy/.rspec +1 -0
  44. data/spec/dummy/README.rdoc +28 -0
  45. data/spec/dummy/Rakefile +6 -0
  46. data/spec/dummy/app/assets/images/.keep +0 -0
  47. data/spec/dummy/app/assets/javascripts/application.js +14 -0
  48. data/spec/dummy/app/assets/stylesheets/application.css.scss +0 -0
  49. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  50. data/spec/dummy/app/controllers/articles_controller.rb +12 -0
  51. data/spec/dummy/app/models/.keep +0 -0
  52. data/spec/dummy/app/models/article.rb +3 -0
  53. data/spec/dummy/app/models/article_category.rb +2 -0
  54. data/spec/dummy/app/views/articles/show.html.haml +2 -0
  55. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  56. data/spec/dummy/bin/bundle +3 -0
  57. data/spec/dummy/bin/rails +4 -0
  58. data/spec/dummy/bin/rake +4 -0
  59. data/spec/dummy/config/application.rb +33 -0
  60. data/spec/dummy/config/boot.rb +5 -0
  61. data/spec/dummy/config/database.yml +25 -0
  62. data/spec/dummy/config/environment.rb +5 -0
  63. data/spec/dummy/config/environments/development.rb +29 -0
  64. data/spec/dummy/config/environments/production.rb +80 -0
  65. data/spec/dummy/config/environments/test.rb +36 -0
  66. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  67. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  68. data/spec/dummy/config/initializers/inflections.rb +16 -0
  69. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  70. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  71. data/spec/dummy/config/initializers/session_store.rb +3 -0
  72. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  73. data/spec/dummy/config/locales/en.yml +36 -0
  74. data/spec/dummy/config/routes.rb +3 -0
  75. data/spec/dummy/config.ru +4 -0
  76. data/spec/dummy/db/development.sqlite3 +0 -0
  77. data/spec/dummy/db/migrate/20130908123351_create_articles.rb +9 -0
  78. data/spec/dummy/db/migrate/20140128152208_create_article_categories.rb +11 -0
  79. data/spec/dummy/db/schema.rb +29 -0
  80. data/spec/dummy/db/test.sqlite3 +0 -0
  81. data/spec/dummy/lib/assets/.keep +0 -0
  82. data/spec/dummy/log/.keep +0 -0
  83. data/spec/dummy/log/development.log +26606 -0
  84. data/spec/dummy/log/test.log +53411 -0
  85. data/spec/dummy/public/404.html +58 -0
  86. data/spec/dummy/public/422.html +58 -0
  87. data/spec/dummy/public/500.html +57 -0
  88. data/spec/dummy/public/favicon.ico +0 -0
  89. data/spec/{deploy_generator_spec.rb → generators/deploy_generator_spec.rb} +1 -1
  90. data/spec/{layout_generator_spec.rb → generators/layout_generator_spec.rb} +5 -5
  91. data/spec/generators/scaffold_generator_spec.rb +59 -0
  92. data/spec/spec_helper.rb +53 -4
  93. metadata +187 -155
  94. data/LICENSE +0 -22
  95. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/css/docstyle.css +0 -123
  96. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/css/style.css +0 -119
  97. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/img/icons.png +0 -0
  98. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/by.js +0 -72
  99. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/de.js +0 -75
  100. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/es.js +0 -76
  101. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/fr.js +0 -74
  102. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/hu.js +0 -76
  103. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/it.js +0 -76
  104. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/ja.js +0 -76
  105. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/lv.js +0 -74
  106. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/nl.js +0 -76
  107. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/pl.js +0 -75
  108. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/pt_br.js +0 -81
  109. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/sq.js +0 -76
  110. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/tr.js +0 -76
  111. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/ua.js +0 -75
  112. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/zh_cn.js +0 -77
  113. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/redactor.min.js +0 -1
  114. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/toolbars/mini.js +0 -103
  115. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/_jquery.reddebox.js.erb +0 -214
  116. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/close.png +0 -0
  117. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/jquery.reddebox.js.erb +0 -246
  118. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/jquery.reddebox.scss +0 -31
  119. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/next.png +0 -0
  120. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/prev.png +0 -0
  121. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/change-log.txt +0 -19
  122. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/check-exists.php +0 -15
  123. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/index.php +0 -50
  124. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/jquery.uploadifive.js +0 -888
  125. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/jquery.uploadifive.min.js +0 -6
  126. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/license-standard.txt +0 -71
  127. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive-cancel.png +0 -0
  128. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive-image-only.php +0 -66
  129. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive.css +0 -100
  130. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive.php +0 -33
  131. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/#swfobject.js +0 -4
  132. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/cancel.png +0 -0
  133. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/jquery.uploadify.min.js +0 -315
  134. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/uploadify-cancel.png +0 -0
  135. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/uploadify.css +0 -66
  136. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/uploadify.swf +0 -0
  137. data/lib/generators/redde/layout/templates/assets/javascripts/admin/swfobject.js +0 -4
  138. data/lib/generators/redde/layout/templates/assets/javascripts/admin/zen_textarea.min.js +0 -17
  139. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/_reset.scss +0 -32
  140. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/defaults/_input.scss +0 -43
  141. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_header.scss +0 -57
  142. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_launchbar.scss +0 -35
  143. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_main.scss +0 -59
  144. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_sidebar.scss +0 -35
  145. data/lib/generators/redde/layout/templates/shared/_header.html.haml +0 -13
  146. data/lib/generators/redde/layout/templates/shared/_launchbar.html.haml +0 -9
  147. data/lib/generators/redde/layout/templates/shared/_sidebar.html.haml +0 -9
  148. data/spec/scaffold_generator_spec.rb +0 -25
  149. /data/lib/generators/redde/layout/templates/assets/{images/admin → redactor/images}/redactor/plugins/file.html +0 -0
  150. /data/lib/generators/redde/layout/templates/assets/{images/admin → redactor/images}/redactor/plugins/image.html +0 -0
  151. /data/lib/generators/redde/layout/templates/assets/{images/admin → redactor/images}/redactor/plugins/image_edit.html +0 -0
  152. /data/lib/generators/redde/layout/templates/assets/{images/admin → redactor/images}/redactor/plugins/link.html +0 -0
  153. /data/lib/generators/redde/layout/templates/assets/{images/admin → redactor/images}/redactor/plugins/table.html +0 -0
  154. /data/lib/generators/redde/layout/templates/assets/{images/admin → redactor/images}/redactor/plugins/video.html +0 -0
  155. /data/lib/generators/redde/layout/templates/assets/{images/admin → redactor/javascripts}/redactor/langs/en.js +0 -0
  156. /data/lib/generators/redde/layout/templates/assets/{images/admin → redactor/javascripts}/redactor/langs/ru.js +0 -0
  157. /data/lib/generators/redde/layout/templates/assets/{images/admin → redactor/javascripts}/redactor/toolbars/default.js +0 -0
  158. /data/lib/generators/redde/layout/templates/assets/{images/admin/redactor/css → redactor/stylesheets/redactor}/wym.css +0 -0
  159. /data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/{_list.scss → list.scss} +0 -0
  160. /data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/{_notice.scss → notice.scss} +0 -0
  161. /data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/{_orders.scss → orders.scss} +0 -0
  162. /data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/{_partners.scss → partners.scss} +0 -0
  163. /data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/{_photos.scss → photos.scss} +0 -0
  164. /data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/{_sortable.scss → sortable.scss} +0 -0
  165. /data/lib/generators/redde/layout/templates/assets/stylesheets/admin/defaults/{_table.scss → table.scss} +0 -0
  166. /data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/{_login.scss → login.scss} +0 -0
@@ -1,888 +0,0 @@
1
- /*
2
- UploadiFive 1.0.4
3
- Copyright (c) 2012 Reactive Apps, Ronnie Garcia
4
- Released under the UploadiFive Standard License <http://www.uploadify.com/uploadifive-standard-license>
5
- */
6
- ;(function($) {
7
-
8
- var methods = {
9
-
10
- init : function(options) {
11
-
12
- return this.each(function() {
13
-
14
- // Create a reference to the jQuery DOM object
15
- var $this = $(this);
16
- $this.data('uploadifive', {
17
- inputs : {}, // The object that contains all the file inputs
18
- inputCount : 0, // The total number of file inputs created
19
- fileID : 0,
20
- queue : {
21
- count : 0, // Total number of files in the queue
22
- selected : 0, // Number of files selected in the last select operation
23
- replaced : 0, // Number of files replaced in the last select operation
24
- errors : 0, // Number of files that returned an error in the last select operation
25
- queued : 0, // Number of files added to the queue in the last select operation
26
- cancelled : 0 // Total number of files that have been cancelled or removed from the queue
27
- },
28
- uploads : {
29
- current : 0, // Number of files currently being uploaded
30
- attempts : 0, // Number of file uploads attempted in the last upload operation
31
- successful : 0, // Number of files successfully uploaded in the last upload operation
32
- errors : 0, // Number of files returning errors in the last upload operation
33
- count : 0 // Total number of files uploaded successfully
34
- }
35
- });
36
- var $data = $this.data('uploadifive');
37
-
38
- // Set the default options
39
- var settings = $data.settings = $.extend({
40
- 'auto' : true, // Automatically upload a file when it's added to the queue
41
- 'buttonClass' : false, // A class to add to the UploadiFive button
42
- 'buttonText' : 'Загрузить файлы', // The text that appears on the UploadiFive button
43
- 'checkScript' : false, // Path to the script that checks for existing file names
44
- 'dnd' : true, // Allow drag and drop into the queue
45
- 'dropTarget' : false, // Selector for the drop target
46
- 'fileSizeLimit' : 0, // Maximum allowed size of files to upload
47
- 'fileType' : 'image', //false // Type of files allowed (image, etc)
48
- 'formData' : {}, // Additional data to send to the upload script
49
- 'height' : 30, // The height of the button
50
- 'method' : 'post', // The method to use when submitting the upload
51
- 'multi' : true, // Set to true to allow multiple file selections
52
- 'overrideEvents' : [], // An array of events to override
53
- 'queueID' : false, // The ID of the file queue
54
- 'queueSizeLimit' : 0, // The maximum number of files that can be in the queue
55
- 'removeCompleted' : false, // Set to true to remove files that have completed uploading
56
- 'simUploadLimit' : 0, // The maximum number of files to upload at once
57
- 'truncateLength' : 0, // The length to truncate the file names to
58
- 'uploadLimit' : 0, // The maximum number of files you can upload
59
- 'uploadScript' : 'uploadifive.php', // The path to the upload script
60
- 'width' : 160, // The width of the button
61
-
62
- /*
63
- // Events
64
- 'onAddQueueItem' : function(file) {}, // Triggered for each file that is added to the queue
65
- 'onCancel' : function(file) {}, // Triggered when a file is cancelled or removed from the queue
66
- 'onCheck' : function(file, exists) {}, // Triggered when the server is checked for an existing file
67
- 'onClearQueue' : function(queue) {}, // Triggered during the clearQueue function
68
- 'onDestroy' : function() {} // Triggered during the destroy function
69
- 'onDrop' : function(files, numberOfFilesDropped) {}, // Triggered when files are dropped into the file queue
70
- 'onError' : function(file, fileType, data) {}, // Triggered when an error occurs
71
- 'onFallback' : function() {}, // Triggered if the HTML5 File API is not supported by the browser
72
- 'onInit' : function() {}, // Triggered when UploadiFive if initialized
73
- 'onQueueComplete' : function() {}, // Triggered once when an upload queue is done
74
- 'onProgress' : function(file, event) {}, // Triggered during each progress update of an upload
75
- 'onSelect' : function() {}, // Triggered once when files are selected from a dialog box
76
- 'onUpload' : function(file) {}, // Triggered when an upload queue is started
77
- 'onUploadComplete' : function(file, data) {}, // Triggered when a file is successfully uploaded
78
- 'onUploadFile' : function(file) {}, // Triggered for each file being uploaded
79
- */
80
- }, options);
81
-
82
- // Calculate the file size limit
83
- if (isNaN(settings.fileSizeLimit)) {
84
- var fileSizeLimitBytes = parseInt(settings.fileSizeLimit) * 1.024
85
- if (settings.fileSizeLimit.indexOf('KB') > -1) {
86
- settings.fileSizeLimit = fileSizeLimitBytes * 1000;
87
- } else if (settings.fileSizeLimit.indexOf('MB') > -1) {
88
- settings.fileSizeLimit = fileSizeLimitBytes * 1000000;
89
- } else if (settings.fileSizeLimit.indexOf('GB') > -1) {
90
- settings.fileSizeLimit = fileSizeLimitBytes * 1000000000;
91
- }
92
- } else {
93
- settings.fileSizeLimit = settings.fileSizeLimit * 1024;
94
- }
95
-
96
- // Create a template for a file input
97
- $data.inputTemplate = $('<input type="file">')
98
- .css({
99
- 'opacity' : 0,
100
- 'position' : 'absolute',
101
- 'z-index' : 999
102
- });
103
-
104
- // Create a new input
105
- $data.createInput = function() {
106
-
107
- // Create a clone of the file input
108
- var input = $data.inputTemplate.clone();
109
- // Create a unique name for the input item
110
- var inputName = input.name = 'input' + $data.inputCount++;
111
- // Set the multiple attribute
112
- if (settings.multi) {
113
- input.attr('multiple', true);
114
- }
115
- // Set the onchange event for the input
116
- input.bind('change', function() {
117
- $data.queue.selected = 0;
118
- $data.queue.replaced = 0;
119
- $data.queue.errors = 0;
120
- $data.queue.queued = 0;
121
- // Add a queue item to the queue for each file
122
- var limit = this.files.length;
123
- $data.queue.selected = limit;
124
- if (($data.queue.count + limit) > settings.queueSizeLimit && settings.queueSizeLimit !== 0) {
125
- if ($.inArray('onError', settings.overrideEvents) < 0) {
126
- alert('The maximum number of queue items has been reached (' + settings.queueSizeLimit + '). Please select fewer files.');
127
- }
128
- // Trigger the error event
129
- if (typeof settings.onError === 'function') {
130
- settings.onError.call($this, 'QUEUE_LIMIT_EXCEEDED');
131
- }
132
- } else {
133
- for (var n = 0; n < limit; n++) {
134
- file = this.files[n];
135
- $data.addQueueItem(file);
136
- }
137
- $data.inputs[inputName] = this;
138
- $data.createInput();
139
- }
140
- // Upload the file if auto-uploads are enabled
141
- if (settings.auto) {
142
- methods.upload.call($this);
143
- }
144
- // Trigger the select event
145
- if (typeof settings.onSelect === 'function') {
146
- settings.onSelect.apply($this, $data.queue);
147
- }
148
- });
149
- // Hide the existing current item and add the new one
150
- if ($data.currentInput) {
151
- $data.currentInput.hide();
152
- }
153
- $data.button.append(input);
154
- $data.currentInput = input;
155
- }
156
-
157
- // Remove an input
158
- $data.destroyInput = function(key) {
159
- $($data.inputs[key]).remove();
160
- delete $data.inputs[key];
161
- $data.inputCount--;
162
- }
163
-
164
- // Drop a file into the queue
165
- $data.drop = function(e) {
166
- $data.queue.selected = 0;
167
- $data.queue.replaced = 0;
168
- $data.queue.errors = 0;
169
- $data.queue.queued = 0;
170
-
171
- var fileData = e.dataTransfer;
172
-
173
- var inputName = fileData.name = 'input' + $data.inputCount++;
174
- console.log(inputName)
175
- // Add a queue item to the queue for each file
176
- var limit = fileData.files.length;
177
- $data.queue.selected = limit;
178
- if (($data.queue.count + limit) > settings.queueSizeLimit && settings.queueSizeLimit !== 0) {
179
- // Check if the queueSizeLimit was reached
180
- if ($.inArray('onError', settings.overrideEvents) < 0) {
181
- alert('The maximum number of queue items has been reached (' + settings.queueSizeLimit + '). Please select fewer files.');
182
- }
183
- // Trigger the onError event
184
- if (typeof settings.onError === 'function') {
185
- settings.onError.call($this, 'QUEUE_LIMIT_EXCEEDED');
186
- }
187
- } else {
188
- // Add a queue item for each file
189
- for (var n = 0; n < limit; n++) {
190
- file = fileData.files[n];
191
- $data.addQueueItem(file);
192
- }
193
- // Save the data to the inputs object
194
- $data.inputs[inputName] = fileData;
195
- }
196
-
197
- // Upload the file if auto-uploads are enabled
198
- if (settings.auto) {
199
- methods.upload.call($this);
200
- }
201
-
202
- // Trigger the onDrop event
203
- if (typeof settings.onDrop === 'function') {
204
- settings.onDrop.call($this, fileData.files, fileData.files.length);
205
- }
206
-
207
- // Stop FireFox from opening the dropped file(s)
208
- e.preventDefault();
209
- e.stopPropagation();
210
- }
211
-
212
- // Check if a filename exists in the queue
213
- $data.fileExistsInQueue = function(file) {
214
- for (var key in $data.inputs) {
215
- input = $data.inputs[key];
216
- limit = input.files.length;
217
- for (var n = 0; n < limit; n++) {
218
- existingFile = input.files[n];
219
- // Check if the filename matches
220
- if (existingFile.name == file.name && !existingFile.complete) {
221
- return true;
222
- }
223
- }
224
- }
225
- return false;
226
- }
227
-
228
- // Remove an existing file in the queue
229
- $data.removeExistingFile = function(file) {
230
- for (var key in $data.inputs) {
231
- input = $data.inputs[key];
232
- limit = input.files.length;
233
- for (var n = 0; n < limit; n++) {
234
- existingFile = input.files[n];
235
- // Check if the filename matches
236
- if (existingFile.name == file.name && !existingFile.complete) {
237
- $data.queue.replaced++;
238
- methods.cancel.call($this, existingFile, true);
239
- }
240
- }
241
- }
242
- }
243
-
244
- // Queue item template
245
- $data.queueItem = $('<div class="uploadifive-queue-item">\
246
- <a class="close" href="#">X</a>\
247
- <div><span class="filename"></span><span class="fileinfo"></span></div>\
248
- <div class="progress">\
249
- <div class="progress-bar"></div>\
250
- </div>\
251
- </div>');
252
-
253
- // Add an item to the queue
254
- $data.addQueueItem = function(file) {
255
- if ($.inArray('onAddQueueItem', settings.overrideEvents) < 0) {
256
- // Check if the filename already exists in the queue
257
- $data.removeExistingFile(file);
258
- // Create a clone of the queue item template
259
- file.queueItem = $data.queueItem.clone();
260
- // Add an ID to the queue item
261
- file.queueItem.attr('id', settings.id + '-file-' + $data.fileID++);
262
- // Bind the close event to the close button
263
- file.queueItem.find('.close').bind('click', function() {
264
- methods.cancel.call($this, file);
265
- return false;
266
- });
267
- var fileName = file.name;
268
- if (fileName.length > settings.truncateLength && settings.truncateLength != 0) {
269
- fileName = fileName.substring(0, settings.truncateLength) + '...';
270
- }
271
- file.queueItem.find('.filename').html(fileName);
272
- // Add a reference to the file
273
- file.queueItem.data('file', file);
274
- $data.queueEl.append(file.queueItem);
275
- }
276
- // Trigger the addQueueItem event
277
- if (typeof settings.onAddQueueItem === 'function') {
278
- settings.onAddQueueItem.call($this, file);
279
- }
280
- // Check the filetype
281
- if (settings.fileType) {
282
- if ($.isArray(settings.fileType)) {
283
- var isValidFileType = false;
284
- for (var n = 0; n < settings.fileType.length; n++) {
285
- if (file.type.indexOf(settings.fileType[n]) > -1) {
286
- isValidFileType = true;
287
- }
288
- }
289
- if (!isValidFileType) {
290
- $data.error('FORBIDDEN_FILE_TYPE', file);
291
- }
292
- } else {
293
- if (file.type.indexOf(settings.fileType) < 0) {
294
- $data.error('FORBIDDEN_FILE_TYPE', file);
295
- }
296
- }
297
- }
298
- // Check the filesize
299
- if (file.size > settings.fileSizeLimit && settings.fileSizeLimit != 0) {
300
- $data.error('FILE_SIZE_LIMIT_EXCEEDED', file);
301
- } else {
302
- $data.queue.queued++;
303
- $data.queue.count++;
304
- }
305
- }
306
-
307
- // Remove an item from the queue
308
- $data.removeQueueItem = function(file, instant, delay) {
309
- // Set the default delay
310
- if (!delay) delay = 0;
311
- var fadeTime = instant ? 0 : 500;
312
- if (file.queueItem) {
313
- if (file.queueItem.find('.fileinfo').html() != ' - Completed') {
314
- file.queueItem.find('.fileinfo').html(' - Cancelled');
315
- }
316
- file.queueItem.find('.progress-bar').width(0);
317
- file.queueItem.delay(delay).fadeOut(fadeTime, function() {
318
- $(this).remove();
319
- });
320
- delete file.queueItem;
321
- $data.queue.count--;
322
- }
323
- }
324
-
325
- // Count the number of files that need to be uploaded
326
- $data.filesToUpload = function() {
327
- var filesToUpload = 0;
328
- for (var key in $data.inputs) {
329
- input = $data.inputs[key];
330
- limit = input.files.length;
331
- for (var n = 0; n < limit; n++) {
332
- file = input.files[n];
333
- if (!file.skip && !file.complete) {
334
- filesToUpload++;
335
- }
336
- }
337
- }
338
- return filesToUpload;
339
- }
340
-
341
- // Check if a file exists
342
- $data.checkExists = function(file) {
343
- if ($.inArray('onCheck', settings.overrideEvents) < 0) {
344
- // This request needs to be synchronous
345
- $.ajaxSetup({
346
- 'async' : false
347
- });
348
- // Send the filename to the check script
349
- var checkData = $.extend(settings.formData, {filename: file.name});
350
- $.post(settings.checkScript, checkData, function(fileExists) {
351
- file.exists = parseInt(fileExists);
352
- });
353
- if (file.exists) {
354
- if (!confirm('A file named ' + file.name + ' already exists in the upload folder.\nWould you like to replace it?')) {
355
- // If not replacing the file, cancel the upload
356
- methods.cancel.call($this, file);
357
- return true;
358
- }
359
- }
360
- }
361
- // Trigger the check event
362
- if (typeof settings.onCheck === 'function') {
363
- settings.onCheck.call($this, file, file.exists);
364
- }
365
- return false;
366
- }
367
-
368
- // Upload a single file
369
- $data.uploadFile = function(file, uploadAll) {
370
- if (!file.skip && !file.complete && !file.uploading) {
371
- file.uploading = true;
372
- $data.uploads.current++;
373
- $data.uploads.attempted++;
374
-
375
- // Create a new AJAX request
376
- xhr = file.xhr = new XMLHttpRequest();
377
-
378
- // Start the upload
379
- // Use the faster FormData if it exists
380
- if (typeof FormData === 'function' || typeof FormData === 'object') {
381
-
382
- // Create a new FormData object
383
- var formData = new FormData();
384
-
385
- // Add the form data
386
- formData.append('photo[src]', file);
387
-
388
- // Add the rest of the formData
389
- for (i in settings.formData) {
390
- formData.append(i, settings.formData[i]);
391
- }
392
-
393
- // Open the AJAX call
394
- xhr.open(settings.method, settings.uploadScript, true);
395
-
396
- // On progress function
397
- xhr.upload.addEventListener('progress', function(e) {
398
- if (e.lengthComputable) {
399
- $data.progress(e, file);
400
- }
401
- }, false);
402
-
403
- // On complete function
404
- xhr.addEventListener('load', function(e) {
405
- if (this.readyState == 4) {
406
- file.uploading = false;
407
- if (this.status == 200) {
408
- if (file.xhr.responseText !== 'Invalid file type.') {
409
- $data.uploadComplete(e, file, uploadAll);
410
- } else {
411
- $data.error(file.xhr.responseText, file, uploadAll);
412
- }
413
- } else if (this.status == 404) {
414
- $data.error('404_FILE_NOT_FOUND', file, uploadAll);
415
- } else if (this.status == 403) {
416
- $data.error('403_FORBIDDEN', file, uplaodAll);
417
- } else {
418
- $data.error('Unknown Error', file, uploadAll);
419
- }
420
- }
421
- });
422
-
423
- // Send the form data (multipart/form-data)
424
- xhr.send(formData);
425
-
426
- } else {
427
-
428
- // Send as binary
429
- var reader = new FileReader();
430
- reader.onload = function(e) {
431
-
432
- // Set some file builder variables
433
- var boundary = '-------------------------' + (new Date).getTime(),
434
- dashes = '--',
435
- eol = '\r\n',
436
- binFile = '';
437
-
438
- // Build an RFC2388 String
439
- binFile += dashes + boundary + eol;
440
- // Generate the headers
441
- binFile += 'Content-Disposition: form-data; name="Filedata"';
442
- if (file.name) {
443
- binFile += '; filename="' + file.name + '"';
444
- }
445
- binFile += eol;
446
- binFile += 'Content-Type: application/octet-stream' + eol + eol;
447
- binFile += e.target.result + eol;
448
-
449
- for (key in settings.formData) {
450
- binFile += dashes + boundary + eol;
451
- binFile += 'Content-Disposition: form-data; name="' + key + '"' + eol + eol;
452
- binFile += settings.formData[key] + eol;
453
- }
454
-
455
- binFile += dashes + boundary + dashes + eol;
456
-
457
- // On progress function
458
- xhr.upload.addEventListener('progress', function(e) {
459
- $data.progress(e, file);
460
- }, false);
461
-
462
- // On complete function
463
- xhr.addEventListener('load', function(e) {
464
- file.uploading = false;
465
- var status = this.status;
466
- if (status == 404) {
467
- $data.error('404_FILE_NOT_FOUND', file, uploadAll);
468
- } else {
469
- if (file.xhr.responseText != 'Invalid file type.') {
470
- $data.uploadComplete(e, file, uploadAll);
471
- } else {
472
- $data.error(file.xhr.responseText, file, uploadAll);
473
- }
474
- }
475
- }, false);
476
-
477
- // Open the ajax request
478
- var url = settings.uploadScript;
479
- if (settings.method == 'get') {
480
- var params = $(settings.formData).param();
481
- url += params;
482
- }
483
- xhr.open(settings.method, settings.uploadScript, true);
484
- xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
485
-
486
- // Trigger the uploadFile event
487
- if (typeof settings.onUploadFile === 'function') {
488
- settings.onUploadFile.call($this, file);
489
- }
490
-
491
- // Send the file for upload
492
- xhr.sendAsBinary(binFile);
493
- }
494
- reader.readAsBinaryString(file);
495
-
496
- }
497
- }
498
- }
499
-
500
- // Update a file upload's progress
501
- $data.progress = function(e, file) {
502
- if ($.inArray('onProgress', settings.overrideEvents) < 0) {
503
- if (e.lengthComputable) {
504
- var percent = Math.round((e.loaded / e.total) * 100);
505
- }
506
- file.queueItem.find('.fileinfo').html(' - ' + percent + '%');
507
- file.queueItem.find('.progress-bar').css('width', percent + '%');
508
- }
509
- // Trigger the progress event
510
- if (typeof settings.onProgress === 'function') {
511
- settings.onProgress.call($this, file, e);
512
- }
513
- }
514
-
515
- // Trigger an error
516
- $data.error = function(errorType, file, uploadAll) {
517
- if ($.inArray('onError', settings.overrideEvents) < 0) {
518
- // Get the error message
519
- switch(errorType) {
520
- case '404_FILE_NOT_FOUND':
521
- errorMsg = '404 Error';
522
- break;
523
- case '403_FORBIDDEN':
524
- errorMsg = '403 Forbidden';
525
- break;
526
- case 'FORBIDDEN_FILE_TYPE':
527
- errorMsg = 'Forbidden File Type';
528
- break;
529
- case 'FILE_SIZE_LIMIT_EXCEEDED':
530
- errorMsg = 'File Too Large';
531
- break;
532
- default:
533
- errorMsg = 'Unknown Error';
534
- break;
535
- }
536
-
537
- // Add the error class to the queue item
538
- file.queueItem.addClass('error')
539
- // Output the error in the queue item
540
- .find('.fileinfo').html(' - ' + errorMsg);
541
- // Hide the
542
- file.queueItem.find('.progress').remove();
543
- }
544
- // Trigger the error event
545
- if (typeof settings.onError === 'function') {
546
- settings.onError.call($this, errorType, file);
547
- }
548
- file.skip = true;
549
- if (errorType == '404_FILE_NOT_FOUND') {
550
- $data.uploads.errors++;
551
- } else {
552
- $data.queue.errors++;
553
- }
554
- if (uploadAll) {
555
- methods.upload.call($this, null, true);
556
- }
557
- }
558
-
559
- // Trigger when a single file upload is complete
560
- $data.uploadComplete = function(e, file, uploadAll) {
561
- if ($.inArray('onUploadComplete', settings.overrideEvents) < 0) {
562
- file.queueItem.find('.progress-bar').css('width', '100%');
563
- file.queueItem.find('.fileinfo').html(' - Completed');
564
- file.queueItem.find('.progress').slideUp(250);
565
- file.queueItem.addClass('complete');
566
- }
567
- // Trigger the complete event
568
- if (typeof settings.onUploadComplete === 'function') {
569
- settings.onUploadComplete.call($this, file, file.xhr.responseText);
570
- }
571
- if (settings.removeCompleted) {
572
- setTimeout(function() { methods.cancel.call($this, file); }, 3000);
573
- }
574
- file.complete = true;
575
- $data.uploads.successful++;
576
- $data.uploads.count++;
577
- $data.uploads.current--;
578
- delete file.xhr;
579
- if (uploadAll) {
580
- methods.upload.call($this, null, true);
581
- }
582
- }
583
-
584
- // Trigger when all the files are done uploading
585
- $data.queueComplete = function() {
586
- // Trigger the queueComplete event
587
- if (typeof settings.onQueueComplete === 'function') {
588
- settings.onQueueComplete.call($this, $data.uploads);
589
- }
590
- }
591
-
592
- // ----------------------
593
- // Initialize UploadiFive
594
- // ----------------------
595
-
596
- // Check if HTML5 is available
597
- if (window.File && window.FileList && window.Blob && (window.FileReader || window.FormData)) {
598
- // Assign an ID to the object
599
- settings.id = 'uploadifive-' + $this.attr('id');
600
-
601
- // Wrap the file input in a div with overflow set to hidden
602
- $data.button = $('<div id="' + settings.id + '" class="uploadifive-button">' + settings.buttonText + '</div>');
603
- if (settings.buttonClass) $data.button.addClass(settings.buttonClass);
604
-
605
- // Style the button wrapper
606
- $data.button.css({
607
- 'height' : settings.height,
608
- 'line-height' : settings.height + 'px',
609
- 'overflow' : 'hidden',
610
- 'position' : 'relative',
611
- 'text-align' : 'center',
612
- 'width' : settings.width
613
- });
614
-
615
- // Insert the button above the file input
616
- $this.before($data.button)
617
- // Add the file input to the button
618
- .appendTo($data.button)
619
- // Modify the styles of the file input
620
- .hide();
621
-
622
- // Create a new input
623
- $data.createInput.call($this);
624
-
625
- // Position the browse files button under the cursor
626
- $data.button.mousemove(function(e) {
627
- var offset = $data.button.offset();
628
- $data.currentInput.css({
629
- 'left' : e.pageX - offset.left - $this.width() + 10,
630
- 'top' : e.pageY - offset.top - $this.height() + 10
631
- });
632
- });
633
-
634
- // Create the queue container
635
- if (!settings.queueID) {
636
- settings.queueID = settings.id + '-queue';
637
- $data.queueEl = $('<div id="' + settings.queueID + '" class="uploadifive-queue" />');
638
- $data.button.after($data.queueEl);
639
- } else {
640
- $data.queueEl = $('#' + settings.queueID);
641
- }
642
-
643
- // Add drag and drop functionality
644
- if (settings.dnd) {
645
- var $dropTarget = settings.dropTarget ? $(settings.dropTarget) : $data.queueEl.get(0);
646
- $dropTarget.addEventListener('dragleave', function(e) {
647
- // Stop FireFox from opening the dropped file(s)
648
- e.preventDefault();
649
- e.stopPropagation();
650
- }, false);
651
- $dropTarget.addEventListener('dragenter', function(e) {
652
- // Stop FireFox from opening the dropped file(s)
653
- e.preventDefault();
654
- e.stopPropagation();
655
- }, false);
656
- $dropTarget.addEventListener('dragover', function(e) {
657
- // Stop FireFox from opening the dropped file(s)
658
- e.preventDefault();
659
- e.stopPropagation();
660
- }, false);
661
- $dropTarget.addEventListener('drop', $data.drop, false);
662
- }
663
-
664
- // Send as binary workaround for Chrome
665
- if (!XMLHttpRequest.prototype.sendAsBinary) {
666
- XMLHttpRequest.prototype.sendAsBinary = function(datastr) {
667
- function byteValue(x) {
668
- return x.charCodeAt(0) & 0xff;
669
- }
670
- var ords = Array.prototype.map.call(datastr, byteValue);
671
- var ui8a = new Uint8Array(ords);
672
- this.send(ui8a.buffer);
673
- }
674
- }
675
-
676
- // Trigger the oninit event
677
- if (typeof settings.onInit === 'function') {
678
- settings.onInit.call($this);
679
- }
680
-
681
- } else {
682
-
683
- // Trigger the fallback event
684
- if (typeof settings.onFallback === 'function') {
685
- settings.onFallback.call($this);
686
- }
687
- return false;
688
-
689
- }
690
-
691
- });
692
-
693
- },
694
-
695
-
696
- // Write some data to the console
697
- debug : function() {
698
-
699
- return this.each(function() {
700
-
701
- console.log($(this).data('uploadifive'));
702
-
703
- });
704
-
705
- },
706
-
707
- // Clear all the items from the queue
708
- clearQueue : function() {
709
-
710
- this.each(function() {
711
-
712
- var $this = $(this),
713
- $data = $this.data('uploadifive'),
714
- settings = $data.settings;
715
-
716
- for (var key in $data.inputs) {
717
- input = $data.inputs[key];
718
- limit = input.files.length;
719
- for (i = 0; i < limit; i++) {
720
- file = input.files[i];
721
- methods.cancel.call($this, file);
722
- }
723
- }
724
- // Trigger the onClearQueue event
725
- if (typeof settings.onClearQueue === 'function') {
726
- settings.onClearQueue.call($this, $('#' + $data.options.queueID));
727
- }
728
-
729
- });
730
-
731
- },
732
-
733
- // Cancel a file upload in progress or remove a file from the queue
734
- cancel : function(file, fast) {
735
-
736
- this.each(function() {
737
-
738
- var $this = $(this),
739
- $data = $this.data('uploadifive'),
740
- settings = $data.settings;
741
-
742
- // If user passed a queue item ID instead of file...
743
- if (typeof file === 'string') {
744
- if (!isNaN(file)) {
745
- fileID = 'uploadifive-' + $(this).attr('id') + '-file-' + file;
746
- }
747
- file = $('#' + fileID).data('file');
748
- }
749
-
750
- file.skip = true;
751
- $data.filesCancelled++;
752
- if (file.uploading) {
753
- $data.uploads.current--;
754
- file.uploading = false;
755
- file.xhr.abort();
756
- delete file.xhr;
757
- methods.upload.call($this);
758
- }
759
- if ($.inArray('onCancel', settings.overrideEvents) < 0) {
760
- $data.removeQueueItem(file, fast);
761
- }
762
-
763
- // Trigger the cancel event
764
- if (typeof settings.onCancel === 'function') {
765
- settings.onCancel.call($this, file);
766
- }
767
-
768
- });
769
-
770
- },
771
-
772
- // Upload the files in the queue
773
- upload : function(file, keepVars) {
774
-
775
- this.each(function() {
776
-
777
- var $this = $(this),
778
- $data = $this.data('uploadifive'),
779
- settings = $data.settings;
780
-
781
- if (file) {
782
-
783
- $data.uploadFile.call($this, file);
784
-
785
- } else {
786
-
787
- // Check if the upload limit was reached
788
- if (($data.uploads.count + $data.uploads.current) < settings.uploadLimit || settings.uploadLimit == 0) {
789
- if (!keepVars) {
790
- $data.uploads.attempted = 0;
791
- $data.uploads.successsful = 0;
792
- $data.uploads.errors = 0;
793
- var filesToUpload = $data.filesToUpload();
794
- // Trigger the onUpload event
795
- if (typeof settings.onUpload === 'function') {
796
- settings.onUpload.call($this, filesToUpload);
797
- }
798
- }
799
-
800
- // Loop through the files
801
- $('#' + settings.queueID).find('.uploadifive-queue-item').not('.error, .complete').each(function() {
802
- _file = $(this).data('file');
803
- // Check if the simUpload limit was reached
804
- if (($data.uploads.current >= settings.simUploadLimit && settings.simUploadLimit !== 0) || ($data.uploads.current >= settings.uploadLimit && settings.uploadLimit !== 0) || ($data.uploads.count >= settings.uploadLimit && settings.uploadLimit !== 0)) {
805
- return false;
806
- }
807
- if (settings.checkScript) {
808
- // Let the loop know that we're already processing this file
809
- _file.checking = true;
810
- skipFile = $data.checkExists(_file);
811
- _file.checking = false;
812
- if (!skipFile) {
813
- $data.uploadFile(_file, true);
814
- }
815
- } else {
816
- $data.uploadFile(_file, true);
817
- }
818
- });
819
- if ($('#' + settings.queueID).find('.uploadifive-queue-item').not('.error, .complete').size() == 0) {
820
- $data.queueComplete();
821
- }
822
- } else {
823
- if ($data.uploads.current == 0) {
824
- if ($.inArray('onError', settings.overrideEvents) < 0) {
825
- if ($data.filesToUpload() > 0 && settings.uploadLimit != 0) {
826
- alert('The maximum upload limit has been reached.');
827
- }
828
- }
829
- // Trigger the onError event
830
- if (typeof settings.onError === 'function') {
831
- settings.onError.call($this, 'UPLOAD_LIMIT_EXCEEDED', $data.filesToUpload());
832
- }
833
- }
834
- }
835
-
836
- }
837
-
838
- });
839
-
840
- },
841
-
842
- // Destroy an instance of UploadiFive
843
- destroy : function() {
844
-
845
- this.each(function() {
846
-
847
- var $this = $(this),
848
- $data = $this.data('uploadifive'),
849
- settings = $data.settings;
850
-
851
- // Clear the queue
852
- methods.clearQueue.call($this);
853
- // Destroy the queue if it was created
854
- if (!settings.queueID) $('#' + settings.queueID).remove();
855
- // Remove extra inputs
856
- $this.siblings('input').remove();
857
- // Show the original file input
858
- $this.show()
859
- // Move the file input out of the button
860
- .insertBefore($data.button);
861
- // Delete the button
862
- $data.button.remove();
863
- // Trigger the destroy event
864
- if (typeof settings.onDestroy === 'function') {
865
- settings.onDestroy.call($this);
866
- }
867
-
868
- });
869
-
870
- }
871
-
872
- }
873
-
874
- $.fn.uploadifive = function(method) {
875
-
876
- if (methods[method]) {
877
- return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
878
- } else if (typeof method === 'object' || !method) {
879
- return methods.init.apply(this, arguments);
880
- } else {
881
- $.error('The method ' + method + ' does not exist in $.uploadify');
882
- }
883
-
884
- }
885
-
886
- })(jQuery);
887
-
888
- /* I gave the queueItems IDs and they each have a reference to the file held in the 'data' obj. */