1var OWFileAttachment = function(params) { 2 $.extend(this, params); 3 this.$context = $('#' + this.uid); 4 this.$previewCont = $('.ow_file_attachment_preview', this.$context); 5 this.inputCont = this.selector ? $(this.selector) : $('a.attach', this.$context); 6 7 var self = this; 8 var items = {}; 9 var itemId = 1; 10 11 var refreshClasses = function() { 12 var itemIndex = 1; 13 $.each(items, 14 function(index, data) { 15 data['html'].removeClass('ow_file_attachment_block1').removeClass('ow_file_attachment_block2').addClass('ow_file_attachment_block' + itemIndex); 16 itemIndex = itemIndex == 1 ? 2 : 1; 17 } 18 ); 19 }; 20 21 this.addItem = function(data, loader, customDeleteUrl, customConfirmation) { 22 data['html'] = $('<div><div class="ow_file_attachment_info">' + 23 '<div class="ow_file_attachment_name">' + data.name + ' <span class="ow_file_attachment_size" style="display: inline-block;">(' + data.size + 'KB)</span></div>' + 24 '<div class="ow_file_attachment_preload" style="display:' + (loader ? 'block' : 'none') + ';"></div>' + 25 '<a href="javascript://" class="ow_file_attachment_close"></a>' + 26 '</div></div>'); 27 28 if (typeof customDeleteUrl != "undefined") 29 { 30 data['customDeleteUrl'] = customDeleteUrl; 31 } 32 33 self.$previewCont.append(data['html']); 34 OW.trigger('base.attachment_rendered', {'data' : data}, this); 35 36 $('.ow_file_attachment_close', data['html']).bind('click', function() { 37 var confirmed = true; 38 39 if (typeof customConfirmation != "undefined") { 40 confirmed = confirm(customConfirmation); 41 } 42 43 if (confirmed) { 44 self.deleteItem(data['id'], customDeleteUrl); 45 } 46 }); 47 }; 48 49 /** 50 * Render uploaded items 51 * 52 * @param object uploadedItems 53 * @param string customDeleteUrl 54 * @param string customConfirmation 55 */ 56 this.renderUploaded = function(uploadedItems, customDeleteUrl, customConfirmation) { 57 $.each(uploadedItems, function(index, data) { 58 self.addItem(data, true, customDeleteUrl, customConfirmation); 59 itemId++; 60 }); 61 62 $.extend(items, uploadedItems); 63 refreshClasses(); 64 } 65 66 this.initInput = function() { 67 var $input = $('<input class="mlt_file_input" type="file"' + (this.multiple ? ' multiple=""' : '') + ' name="ow_file_attachment[]" />'); 68 this.inputCont.append($input); 69 70 $input.change( 71 function(e) { 72 var inItems = {}; 73 74 // check if files array is available 75 if (this.files != undefined) { 76 var elData; 77 for (var i = 0; i < this.files.length; i++) { 78 elData = this.files[i]; 79 inItems[itemId] = {id: itemId++, name: elData.name, size: (Math.round(elData.size / 1024))}; 80 } 81 } 82 else { 83 84 } 85 86 if (self.showPreview) { 87 $.each(inItems, 88 function(index, data) { 89 self.addItem(data, true); 90 } 91 ); 92 } 93 94 OW.trigger('base.add_attachment_to_queue', {'pluginKey': self.pluginKey, 'uid': self.uid, 'items': items}); 95 96 $.extend(items, inItems); 97 98 if (self.showPreview) { 99 refreshClasses(); 100 } 101 102 self.submitFiles(inItems); 103 } 104 ); 105 }; 106 107 this.submitFiles = function(data) { 108 var idList = [], idListIndex = 0; 109 $.each(data, function() { 110 idList[idListIndex++] = this.id; 111 } 112 ); 113 114 var index = idList.join('_'); 115 var nameObj = {}; 116 117 $.each(items, function(index, item) { 118 nameObj[item.name] = item.id; 119 }); 120 121 $form = $('<form method="post" action="' + self.submitUrl + '?flUid=' + self.uid + '" enctype="multipart/form-data" target="form_' + index + '"><input type="hidden" name="flData" value="' + 122 encodeURIComponent(JSON.stringify(nameObj)) + '" /><input type="hidden" name="flUid" value="' + self.uid + '"><input type="hidden" name="pluginKey" value="' + self.pluginKey + '">' + 123 '</form>') 124 .append($('input[type=file]', self.inputCont)); 125// $form.appendTo($('body')); 126 $('<div style="display:none" id="hd_' + index + '"><div>').appendTo($('body')) 127 .append($('<iframe name="form_' + index + '"></iframe>')) 128 .append($form); 129 $form.submit(); 130 131 self.initInput(); 132 }; 133 134 this.updateItems = function(data) { 135 136 if (!data.result && data.noData) { 137 OW.error(data.message); 138 return; 139 } 140 var indexList = []; 141 142 if (data.items) { 143 $.each(data.items, function(index, item) { 144 indexList.push(index); 145 146 if (item.result) { 147 items[index]['dbId'] = item['dbId']; 148 if( items[index]['cancelled'] ){ 149 self.deleteItem(index); 150 return; 151 } 152 if (self.showPreview) { 153 $('.ow_file_attachment_preload', items[index]['html']).hide(); 154 } 155 } else { 156 self.deleteItem(index); 157 if (self.showPreview) { 158 OW.error(item.message); 159 } 160 } 161 }); 162 163 OW.trigger('base.update_attachment', {'pluginKey': self.pluginKey, 'uid': self.uid, 'items': data.items}); 164 } 165 166 $('#hd_' + indexList.join('_')).remove(); 167 }; 168 169 this.deleteItem = function(id, customDeleteUrl) { 170 OW.trigger('base.attachment_deleted', {'id' : id}, this); 171 172 if (self.showPreview) { 173 items[id]['html'].remove(); 174 } 175 176 if( !items[id]['dbId'] ){
177 items[id]['cancelled'] = true; 178 return; 179 } 180 181 $.ajax({ 182 url: (typeof customDeleteUrl == "undefined" ? self.deleteUrl : customDeleteUrl), 183 data: {id: items[id]['dbId']}, 184 method: "POST" 185 }); 186 187 delete items[id]; 188 if (self.showPreview) { 189 refreshClasses(); 190 } 191 }; 192 193 this.reset = function(id, callback) { 194 self.uid = id; 195 196 if (typeof callback != "undefined") { 197 callback.call({}, items); 198 } 199 200 if (self.showPreview) { 201 $.each(items, 202 function(index, data) { 203 data['html'].remove(); 204 } 205 ); 206 207 refreshClasses(); 208 } 209 210 items = {}; 211 itemId = 1; 212 213 }; 214 215 $.each(self.lItems, function(index, lItem) { 216 items[itemId] = {id: itemId++, name: lItem.name, size: lItem.size, dbId: lItem.dbId}; 217 }); 218 219 if (self.showPreview) { 220 $.each(items, 221 function(index, data) { 222 self.addItem(data, false); 223 } 224 ); 225 226 refreshClasses(); 227 } 228 229 this.initInput(); 230}; 231 232OW.bind('base.file_attachment', function(data) { 233 if (owFileAttachments[data.uid]) { 234 owFileAttachments[data.newUid] = owFileAttachments[data.uid]; 235 delete owFileAttachments[data.uid]; 236 owFileAttachments[data.newUid].reset(data.newUid); 237 } 238}); 239 240window.owFileAttachments = {}; 241 242var OWPhotoAttachment = function(params) { 243 $.extend(this, params); 244 var self = this, $previewCont = $('#' + this.previewId), 245 $buttonCont = $('#' + this.buttonId), 246 $form, 247 $iframe = null, 248 $item = $('.ow_photo_attachment_pic', $previewCont), 249 canceled = false; 250 251 this.eventParams = {uid: self.uid, pluginKey: self.pluginKey}; 252 253 this.initInput = function() { 254 var $input = $('<input class="mlt_file_input" type="file" name="attachment" />'), self = this; 255 $buttonCont.empty().append($input).show(); 256 OW.trigger('base.attachment_show_button_cont', self.eventParam
256s); 257 $item.css({backgroundImage: ''}).unbind('click').addClass('loading'); 258 canceled = false; 259 $previewCont.hide(); 260 $('div', $item).unbind('click').click(function() { 261 canceled = true; 262 $previewCont.hide(); 263 self.initInput(); 264 OW.trigger('base.attachment_deleted', self.eventParams); 265 }); 266 267 if ($iframe != null) { 268 $iframe.remove(); 269 } 270 271 if ($form != null) { 272 $form.remove(); 273 } 274 275 $input.change( 276 function(e) { 277 $buttonCont.hide(); 278 OW.trigger('base.attachment_hide_button_cont', self.eventParams); 279 $previewCont.show(); 280 $form = $('<form method="post" action="' + self.addPhotoUrl + '?flUid=' + self.uid + '" enctype="multipart/form-data" target="form_' + self.uid + '">' + 281 '<input type="hidden" name="flUid" value="' + self.uid + '"><input type="hidden" name="pluginKey" value="' + self.pluginKey + '"></form>') 282 .append($('input[type=file]', $buttonCont)); 283 $iframe = $('<div style="display:none" id="hd_' + self.uid + '"><div>').appendTo($('body')) 284 .append($('<iframe name="form_' + self.uid + '"></iframe>')) 285 .append($form); 286 $form.submit(); 287 OW.trigger('base.add_photo_attachment_submit', self.eventParam
287s); 288 } 289 ); 290 }; 291 292 this.updateItem = function(data) { 293 if (canceled) { 294 canceled = false; 295 return; 296 } 297 298 var self = this, eventParams = {uid: self.uid, pluginKey: self.pluginKey, url: data.url}; 299 if (data.result) { 300 var previewImg = new Image(); 301 previewImg.onload = function() { 302 $item.removeClass('loading').css({backgroundImage: 'url(' + data.url + ')'}).click(function() { 303 OW.showImageInFloatBox(data.url) 304 }); 305 $('div', $item).unbind('click').click(function(e) { 306 e.stopPropagation(); 307 self.initInput(); 308 OW.trigger('base.attachment_deleted', eventParams); 309 }); 310 OW.trigger('base.attachment_added', eventParams); 311 }; 312 previewImg.src = data.url; 313 } 314 else { 315 if (data.message) { 316 OW.error(data.message); 317 } 318 319 self.initInput(); 320 } 321 }; 322 323 this.resetUid = function(data) { 324 this.uid = data; 325 this.eventParams.uid = this.uid; 326 self.initInput(); 327 }; 328 329 OW.bind('base.photo_attachment_reset', function(data) { 330 if (data.uid == self.uid && data.pluginKey == self.pluginKey) 331 self.initInput(); 332 }); 333 334 this.initInput(); 335}; 336 337window.owPhotoAttachment = {}; 338 339OW.bind('base.photo_attachment_uid_update', function(data) { 340 if (owPhotoAttachment[data.uid]) { 341 owPhotoAttachment[data.newUid] = owPhotoAttachment[data.uid]; 342 delete owPhotoAttachment[data.uid]; 343 owPhotoAttachment[data.newUid].resetUid(data.newUid); 344 } 345});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.