1jQuery(document).ready(function() { 2 // javascript validation 3 $('.feManagerValidation').femanagerValidation(); 4 5 // ajax uploader 6 var images = createUploader(); 7 // Store initially present filenames from hidden #image input in data structure 8 if ($('#femanager_field_image').length > 0) { 9 $.each($('#femanager_field_image').val().split(','), function(index, filename) { 10 if(filename.trim().length > 0) { 11 images.addImageName(filename, filename) 12 } 13 }); 14 } 15 16 // delete image 17 $('#femanager_field_preview-image').find('.qq-upload-delete').click(function(e) { 18 e.preventDefault(); 19 20 var item = $(e.target).parent(); 21 // Remove filename from hidden #image input 22 images.deleteImageName(item.find('.qq-upload-file').text()); 23 24 item.fadeOut('', function() { 25 $(this).remove(); 26 }); 27 }); 28 29 // confirmation 30 $('*[data-confirm]').click(function(e) { 31 var message = $(this).data('confirm'); 32 if (!confirm(message)) { 33 e.preventDefault(); 34 } 35 }); 36}); 37 38/** 39 * Create Fileuploader 40 * 41 * @return object 42 */ 43function createUploader() { 44 if ($('#femanager_field_fine-uploader').length == 0) { 45 return; 46 } 47 48 var imageNameHandler = { 49 // Data structure to store image names for Femanager 50 imageNames: {}, 51 // Join image names in data structure to be stored in hidden #image input 52 getImageNames: function () { 53 return $.map(this.imageNames, function(item) { return item; } ).join(','); 54 }, 55 // Add filename to data structure and hidden #image input 56 addImageName: function(id, filename) { 57 this.imageNames[id] = filename; 58 $('#femanager_field_image').val(this.getImageNames()); 59 }, 60 // Remove filename from data structure and hidden #image input 61 deleteImageName: function (idToDelete) { 62 delete this.imageNames[idToDelete]; 63 $('#femanager_field_image').val(this.getImageNames()); 64 } 65 }; 66 var uploader = new qq.FineUploader({ 67 68 element: document.getElementById('femanager_field_fine-uploader'), 69 request: { 70 endpoint: Femanager.getBaseUrl() + 'index.php?eID=femanagerFileUpload&id=' + $('#femanagerPid').val(), 71 customHeaders: { 72 Accept: 'application/json' 73 } 74 }, 75 multiple: true, 76 template: $('.image_container_template:first').html(), 77 fileTemplate: '<li>' + 78 '<div class="qq-progress-bar"></div>' + 79 '<span class="qq-upload-spinner"></span>' + 80 '<span class="qq-upload-finished"></span>' + 81 '<span class="qq-upload-file"></span>' + 82 '<span class="qq-upload-size"></span>' + 83 '<a class="qq-upload-cancel" href="#">{cancelButtonText}</a>' + 84 '<a class="qq-upload-retry" href="#">{retryButtonText}</a>' + 85 '<a class="qq-upload-delete icon-trash" href="#">{deleteButtonText}</a>' + 86 '<span class="qq-upload-status-text">{statusText}</span>' + 87 '</li>', 88 deleteFile: { 89 enabled: true, 90 forceConfirm: true, 91 endpoint: Femanager.getBaseUrl() + 'index.php?eID=femanagerFileDelete&id=' + $('#femanagerPid').val() // TODO delete file on server 92 }, 93 classes: { 94 success: 'alert alert-success', 95 fail: 'alert alert-error' 96 }, 97 validation: { 98 allowedExtensions: getValueFromField('#uploadFileExtension', 'jpeg, jpg, gif, png, bmp', 'array'), // allowed file extensions 99 sizeLimit: getValueFromField('#uploadSize', 25000000, 'int'), // in bytes 100 itemLimit: getValueFromField('#uploadAmount', 1, 'int') // limit number of uploads 101 }, 102 callbacks: { 103 onComplete: function(id, fileName, responseJSON) { 104 if (responseJSON.success) { 105 // show preview image 106 var image = $('<img />') 107 .addClass('fileupload_image') 108 .prop('src', $('#uploadFolder').val() + '/' + responseJSON.uploadName) 109 .prop('alt', responseJSON.uploadName) 110 111 image.appendTo(this.getItemByFileId(id)); 112 113 // add filename to Femanager data structure 114 imageNameHandler.addImageName(id, responseJSON.uploadName); 115 } 116 }, 117 onDeleteComplete: function(id, xhr, isError) { 118 // Remove filename from Femanager data structure 119 imageNameHandler.deleteImageName(id); 120 } 121 } 122 }); 123 return imageNameHandler; 124} 125 126window.Femanager = {}; 127 128/** 129 * Get value from a hidden field 130 * 131 * @param selector string 132 * @param fallback mixed 133 * @param mode string ("int", "array") 134 * @returns {*} 135 */ 136function getValueFromField(selector, fallback, mode) { 137 var value = fallback; 138 if ($(selector).length) { 139 value = $(selector).val(); 140 } 141 if (mode != undefined) { 142 if (mode === 'int') { 143 value = parseInt(value); 144 } else if (mode === 'array') { 145 value = value.toString(); 146 value = value.replace(/[\s,]+/g, ','); // replace " , " to "," 147 value = value.split(','); 148 } 149 } 150 return value; 151} 152 153/** 154 * Return BaseUrl as prefix 155 * 156 * @return string Base Url 157 */ 158window.Femanager.getBaseUrl = function() { 159 var baseurl; 160 if (jQuery('base').length > 0) { 161 baseurl = jQuery('base').prop('href'); 162 } else if (window.location.hostname.indexOf('localhost') !== -1) { 163 baseurl = ''; 164 } else { 165 var port = ''; 166 if (window.location.port.length > 0) { 167 port = ':' + window.location.port; 168 } 169 if (window.location.protocol != "https:") { 170 baseurl = 'http://' + window.location.hostname + port + '/'; 171 } else { 172 baseurl = 'https://' + window.location.hostname + port + '/'; 173 } 174 } 175 return baseurl; 176};
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.