var resizeWidth = 1280; var resizeHeight = 1024; var resizeQuality = 90; var limitFilesQuantity = 0; jQuery(function($) { //var runtimes = $.browser.opera ? 'flash,gears,silverlight,browserplus,html4' : 'html5,flash,gears,silverlight,browserplus,html4'; var runtimes = 'html5,flash,silverlight,html4'; var uploader = $("#uploader").plupload({ // General settings runtimes : runtimes, url : $('#uploaderForm').attr('action'), multipart :true, multipart_params : { 'album_id' : 0 }, max_file_size : '40mb', chunk_size : '2mb', unique_names : false, // Sort files sortable: true, resize : {height : resizeHeight, quality : resizeQuality}, filters : [ {title : "Image files", extensions : "jpg,JPG,jpeg,gif,png"} ], // Views to activate views: { list: true, thumbs: true, // Show thumbs active: 'thumbs' }, // Flash settings flash_swf_url : '/skin/plupload/js/Moxie.swf', // Silverlight settings silverlight_xap_url : '/skin/plupload/js/Moxie.xap', init : { BeforeUpload: function(up) { up.settings.resize = {height : resizeHeight, quality : resizeQuality}; $('#uploader_start').hide(); }, QueueChanged: function() { if(limitFilesQuantity > 0 && this.files.length > limitFilesQuantity) { setTimeout(function(){ $('#uploader_start').button('disable'); }, 2); return true; } else { $('#uploader_start').button('enable'); } setTimeout(function(){ resetValue(); }, 2); if (this.state == 1) { $('#uploadCountdown').countdown('destroy').countdown({until: +30, format: 'S', layout: '{snn}', onExpiry: function(){ $('#uploader_start').click(); }}); $('#countdown').countdown('destroy'); $('#successLoad').hide(); } }, FilesAdded: function() { $('.plupload_droptext').hide(); if(limitFilesQuantity > 0 && this.files.length > limitFilesQuantity) { $('#imagesQuantity').text(this.files.length); $('#dialog-limit').dialog('open'); return true; } }, FileUploaded: function() { resetValue(); }, UploadComplete: function() { $('#uploader_stop').hide(); $('#uploader_start').show(); $('#successLoad').show(); $('window').resize(); $('#countdown').countdown({until: +30, format: 'S', layout: '{snn}', onExpiry: function(){ $('#successLoad').hide(); $('#dialog-upload').dialog('close'); }}); } }, viewchanged: function(event, args) { resetValue(); } }); $('#uploader_start').on('click', function(){ $('#uploader_stop').show();$(this).removeClass('ui-state-hover'); $('#uploadCountdown').countdown('destroy'); }); $('#uploader_stop').on('click', function(){$(this).hide(); $('#uploader_start').show();}); // Client side form validation $('#uploaderForm').submit(function(e) { var uploader = $('#uploader').plupload('getUploader'); // Files in queue upload them first if (uploader.files.length > 0) { // When all files are uploaded submit form uploader.bind('StateChanged', function() { if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) { $('#uploaderForm')[0].submit(); } }); uploader.start(); } else flushSpinnerMessage('You must at least upload one file.'); return false; }); $('#uploader_dropbox').append('
') var scrollbar = $('#uploader-scroll').slider({ orientation: "vertical", value: 100, slide: function( event, ui ) { reflowContent(ui.value); }, change: function( event, ui ) { reflowContent(ui.value); } }); $('#uploader_dropbox').mousewheel(function(e, delta){ delta *= 5; var obj = $( "#uploader-scroll" ); var newVal = obj.slider('option', 'value') + delta; newVal = Math.max(obj.slider('option', 'min'), Math.min(obj.slider('option', 'max'),newVal)); obj.slider('option', 'value', newVal); return false; }); //scrollpane parts var scrollPane = $( '#uploader_dropbox' ), scrollContent = $( "#uploader_filelist" ); //reset slider value based on scroll content position function resetValue() { var remainder = scrollPane.actual('height') - scrollContent.actual('height'); console.log(remainder); if(remainder < 0) { $('#uploader-scroll').show(); var percentage = 100 - Math.round( parseInt( scrollContent.position().top ) / remainder * 100 ); scrollbar.slider( "value", percentage ); } else { scrollContent.css( "marginTop", 0 ); $('#uploader-scroll').hide(); } } //if the slider is 100% and window gets larger, reveal content function reflowContent(amount) { if ( scrollContent.actual('height') > scrollPane.actual('height') ) { scrollContent.css( "marginTop", Math.round( (100 - amount) / 100 * ( scrollPane.actual('height') - scrollContent.actual('height') ) ) + "px" ); } else { scrollContent.css( "marginTop", 0 ); } } $('#uploader_container').removeAttr('title'); });