Current Path : /var/www/html/clients/nsmk.e-nk.ru/application/maxsite/plugins/file_manager/js/ |
Current File : /var/www/html/clients/nsmk.e-nk.ru/application/maxsite/plugins/file_manager/js/jquery.swfupload.js |
/* * SWFUpload jQuery Plugin v1.0.0 * * Copyright (c) 2009 Adam Royle * Licensed under the MIT license. * */ (function($){ var defaultHandlers = ['swfupload_loaded_handler','file_queued_handler','file_queue_error_handler','file_dialog_start_handler','file_dialog_complete_handler','upload_start_handler','upload_progress_handler','upload_error_handler','upload_success_handler','upload_complete_handler','queue_complete_handler']; var additionalHandlers = []; $.fn.swfupload = function(){ var args = $.makeArray(arguments); return this.each(function(){ var swfu; if (args.length == 1 && typeof(args[0]) == 'object') { swfu = $(this).data('__swfu'); if (!swfu) { var settings = args[0]; var $magicUploadControl = $(this); var handlers = []; $.merge(handlers, defaultHandlers); $.merge(handlers, additionalHandlers); $.each(handlers, function(i, v){ var eventName = v.replace(/_handler$/, '').replace(/_([a-z])/g, function(){ return arguments[1].toUpperCase(); }); settings[v] = function() { var event = $.Event(eventName); $magicUploadControl.trigger(event, $.makeArray(arguments)); return !event.isDefaultPrevented(); }; }); $(this).data('__swfu', new SWFUpload(settings)); } } else if (args.length > 0 && typeof(args[0]) == 'string') { var methodName = args.shift(); swfu = $(this).data('__swfu'); if (swfu && swfu[methodName]) { swfu[methodName].apply(swfu, args); } } }); }; $.swfupload = { additionalHandlers: function() { if (arguments.length === 0) { return additionalHandlers.slice(); } else { $(arguments).each(function(i, v){ $.merge(additionalHandlers, $.makeArray(v)); }); } }, defaultHandlers: function() { return defaultHandlers.slice(); }, getInstance: function(el) { return $(el).data('__swfu'); } }; })(jQuery); $(function() { $('#FM-swfupload').swfupload( { upload_url : FileManager.__upload //FileManager.fm+"php/upload.php" // ,post_params :{"PHPSESSID" : '<?php echo session_id(); ?>', "upload": FileManager.dir} // file_size_limit : "10240", // file_types : "*.*", // file_types_description : "All Files", // file_upload_limit : "0", ,flash_url : FileManager.fm+'swf/swfupload.swf' ,button_image_url : FileManager.fm+'css/images/null.jpeg' // !!! ИНАЧЕ БУДЕТ ЛИШНИЙ GET НА http://mso/admin ,button_placeholder_id : 'FM-swfupload-input' ,button_width :67 ,button_height :18 // SWFUpload.WINDOW_MODE.TRANSPARENT - not work in Safari & Chrome ,button_window_mode :($.browser.opera || $.browser.mozilla) ? SWFUpload.WINDOW_MODE.TRANSPARENT : SWFUpload.WINDOW_MODE.WINDOW ,button_cursor :SWFUpload.CURSOR.HAND ,button_text_top_padding: 0 ,button_text : '<span class="swfbutton"> UPLOAD </span>' ,button_text_style : '.swfbutton {color:#555555;z-index:1;font-family: verdana, helvetica, sans-serif; font-size:11px;}' ,debug : false ,prevent_swf_caching : false }) /* File Object The file object is passed to several event handlers. It contains information about the file. Some operating systems do not fill in all the values (this is especially true for the createdate and modificationdate values). { id : string, // SWFUpload file id, used for starting or cancelling and upload index : number, // The index of this file for use in getFile(i) name : string, // The file name. The path is not included. size : number, // The file size in bytes type : string, // The file type as reported by the client operating system creationdate : Date, // The date the file was created modificationdate : Date, // The date the file was last modified filestatus : number, // The file's current status. Use SWFUpload.FILE_STATUS to interpret the value. SWFUpload.FILE_STATUS = { QUEUED : -1, IN_PROGRESS : -2, ERROR : -3, COMPLETE : -4, CANCELLED : -5 }; function file status -1 Queued -2 Start -2 Progress -4 Success -4 Complete */ .bind('swfuploadLoaded', function(event) { log(' SWF loaded'); // var p = $("#FM-swfupload").offset(); // $("#SWFUpload_0").css({top:p.top+2, left:p.left+2}); //SWF.session = {}; }) .bind('fileDialogStart', function(event){log(' *** dialog start');}) .bind('fileQueued', function(event, file) { //log(' *** file queued - '+file.name); file.folder = FileManager.folder; SWF.session[file.index] = file; }) .bind('fileQueueError', function(event, file, errorCode, message) { //log(' *** file queue error - '+message); alert('ОШИБКА ('+file.name+')\n\n'+message); SWF.session[file.index] = file; SWF.session[file.index].errorCode = errorCode; SWF.session[file.index].message = message; }) .bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued) { //log(' *** file dialog complete'); try { if (numFilesQueued > 0) { // log(' *** upload to: '+FileManager.folder); $("#FM-upload-count").html(numFilesQueued); SWF.startUpload(); } else { } } catch (ex){SWF.debug(ex)} }) .bind('uploadStart', function(event, file) { //log(' *** upload start - '+file.name); var old = FileManager.dir[FileManager.folder][file.name]; if (old && (FileManager.settings.confirm_file_rewrite.state == true)) { if (confirm('Перезаписать файл:\n'+old.filename+' '+old.filesize+' байт от '+old.lastmodif+' на\n'+file.name+' '+file.size+' '+file.modificationdate+'?')) { } else { log(' *** cancel - '+file.index); SWF.cancelUpload(); return; } } $("#FM-upload-name").html(file.name); $("#FM-upload-state").html('upload'); try { SWF.session[file.index].filestatus = file.filestatus; SWF.setPostParams( { //PHPSESSID : '<?php echo session_id(); ?>' uploads_dir : FileManager.FCPATH ,folder : SWF.session[file.index].folder ,tasks : $.toJSON(FileManager.tasks) }); } catch(ex){SWF.debug(ex)} }) .bind('uploadProgress', function(event, file, bytesLoaded) { //log(' *** upload progress - '+bytesLoaded); try { SWF.session[file.index].filestatus = file.filestatus; SWF.session[file.index].bytesLoaded = bytesLoaded; SWF.session[file.index].percent = Math.ceil((bytesLoaded / file.size) * 100); $("#FM-upload-state").html(SWF.session[file.index].percent+'%'); } catch(ex){SWF.debug(ex)} }) .bind('uploadSuccess', function(event, file, serverData) { log(' *** upload success - '+file.name); $("#FM-upload-state").html('success'); try { SWF.session[file.index].filestatus = file.filestatus; try { var data = $.parseJSON(serverData); } catch(ex) { $("#FM-upload-state").html('error'); alert('Сервер вместо данных вернул сообщение: '+serverData); } if (data.error) { $("#FM-upload-state").html('error'); alert('ERROR: '+data.error) } else { FileManager.upLoadFile(data); } } catch(ex){SWF.debug(ex)} }) .bind('uploadComplete', function(event, file) { log(' *** upload complete - '+file.name); $("#FM-upload-count").html(SWF.getStats().files_queued); if (file.filestatus == -5) { $("#FM-upload").children().html(''); } else { $("#FM-upload-state").html('END'); } try { //SWF.session[file.index].filestatus = file.filestatus; delete SWF.session[file.index]; /* I want the next upload to continue automatically so I'll call startUpload here */ if (SWF.getStats().files_queued === 0) { window.setTimeout(function(){$("#FM-upload").children().html('')}, 300); } else { SWF.startUpload(); } } catch(ex){SWF.debug(ex)} }) .bind('uploadError', function(event, file, errorCode, message) { log(' *** upload error - '+message); if (errorCode == -280) // FILE_CANCELLED { } else { $("#FM-upload-state").html('error'); SWF.session[file.index].filestatus = file.filestatus; SWF.session[file.index].errorCode = errorCode; SWF.session[file.index].message = message; alert('Файл '+SWF.session[file.index].name+' размером '+SWF.session[file.index].size+' байт не может быть загружен в "'+SWF.session[file.index].folder+'", ошибка: '+message+', код: '+errorCode+', вероятная причина - размер файла.'); } }); SWF = $.swfupload.getInstance('#FM-swfupload'); SWF.session = {}; });