|
11 | 11 |
|
12 | 12 | var l10n;
|
13 | 13 |
|
14 |
| - redux.field_objects = redux.field_objects || {}; |
15 |
| - redux.field_objects.multi_media = redux.field_objects.multi_media || {}; |
16 |
| - redux.field_objects.multi_media.mainID = ''; |
| 14 | + redux.field_objects = redux.field_objects || {}; |
| 15 | + redux.field_objects.multi_media = redux.field_objects.multi_media || {}; |
17 | 16 |
|
18 | 17 | /*******************************************************************************
|
19 | 18 | * Function: init
|
|
83 | 82 | *
|
84 | 83 | * Module level init
|
85 | 84 | ******************************************************************************/
|
86 |
| - redux.field_objects.multi_media.modInit = function( el ) { |
| 85 | + redux.field_objects.multi_media.modInit = function() { |
87 | 86 |
|
88 | 87 | // Localization variable.
|
89 | 88 | l10n = redux_multi_media_l10;
|
90 |
| - |
91 |
| - // MainID into global variable. |
92 |
| - redux.field_objects.multi_media.mainID = el.attr( 'data-id' ); |
93 | 89 | };
|
94 | 90 |
|
95 | 91 | /*******************************************************************************
|
|
100 | 96 | ******************************************************************************/
|
101 | 97 |
|
102 | 98 | // Removes error message(s) when clicking the Upload button.
|
103 |
| - redux.field_objects.multi_media.removeErrMsgs = function() { |
| 99 | + redux.field_objects.multi_media.removeErrMsgs = function( mainID ) { |
104 | 100 |
|
105 | 101 | // Enumerate and remove existing 'file exists' messages.
|
106 |
| - $( '#' + redux.field_objects.multi_media.mainID + ' .attach_list li.redux-file-exists' ).each( |
| 102 | + $( '#' + mainID + ' .attach_list li.redux-file-exists' ).each( |
107 | 103 | function( idx, li ) {
|
108 | 104 | idx = null;
|
109 | 105 |
|
|
112 | 108 | );
|
113 | 109 |
|
114 | 110 | // Enumerate and remove existing 'max upload' messages.
|
115 |
| - $( '#' + redux.field_objects.multi_media.mainID + ' .attach_list li.redux-max-limit' ).each( |
| 111 | + $( '#' + mainID + ' .attach_list li.redux-max-limit' ).each( |
116 | 112 | function( idx, li ) {
|
117 | 113 | idx = null;
|
118 | 114 |
|
|
122 | 118 | };
|
123 | 119 |
|
124 | 120 | // Checks for duplicate after file selection.
|
125 |
| - redux.field_objects.multi_media.selExists = function( item ) { |
| 121 | + redux.field_objects.multi_media.selExists = function( mainID, item ) { |
126 | 122 | var len;
|
127 | 123 |
|
128 | 124 | var val = false;
|
129 | 125 |
|
130 | 126 | // Enumerate existing files.
|
131 |
| - $( '#' + redux.field_objects.multi_media.mainID + ' .attach_list li' ).each( |
| 127 | + $( '#' + mainID + ' .attach_list li' ).each( |
132 | 128 | function( idx, li ) {
|
133 | 129 | idx = null;
|
134 | 130 |
|
|
172 | 168 | // Get form name.
|
173 | 169 | var formName = $formfield.attr( 'name' );
|
174 | 170 |
|
| 171 | + var mainID = selector.attr( 'data-id' ); |
| 172 | + |
175 | 173 | // Prevent default action.
|
176 | 174 | event.preventDefault();
|
177 | 175 |
|
|
182 | 180 | }
|
183 | 181 |
|
184 | 182 | // Remove existing error messages.
|
185 |
| - redux.field_objects.multi_media.removeErrMsgs(); |
| 183 | + redux.field_objects.multi_media.removeErrMsgs( mainID ); |
186 | 184 |
|
187 | 185 | // Get library filter data.
|
188 | 186 | filter = $( selector ).find( '.library-filter' ).data( 'lib-filter' );
|
|
243 | 241 | var attachment = selection.toJSON();
|
244 | 242 |
|
245 | 243 | // Get existing file count.
|
246 |
| - var childCount = $( '#' + redux.field_objects.multi_media.mainID + ' .attach_list' ).children().length; |
| 244 | + var childCount = $( '#' + mainID + ' .attach_list' ).children().length; |
247 | 245 |
|
248 | 246 | $formfield.val( attachment.url );
|
249 | 247 | $( '#' + inputID + '_id' ).val( attachment.id );
|
|
258 | 256 | if ( maxFileUpload <= 0 || ( addCount + childCount ) < maxFileUpload ) {
|
259 | 257 |
|
260 | 258 | // Check for duplicates and format duplicate message.
|
261 |
| - if ( redux.field_objects.multi_media.selExists( this.id ) ) { |
| 259 | + if ( redux.field_objects.multi_media.selExists( mainID, this.id ) ) { |
262 | 260 | dupMsg = l10n.dup_warn;
|
263 | 261 | dupMsg = dupMsg.replace( '%s', '<strong>' + this.filename + '</strong>' );
|
264 | 262 | uploadStatus = '<li class="redux-file-exists">' + dupMsg + '</li>';
|
|
295 | 293 | }
|
296 | 294 |
|
297 | 295 | // Increment count of added files.
|
298 |
| - addCount += 1; |
| 296 | + addCount++; // += 1; |
299 | 297 |
|
300 | 298 | // If max file upload reached, generate error message.
|
301 | 299 | } else {
|
|
0 commit comments