Вход Регистрация
Файл: templates/default/js/images-upload.js
Строк: 95
<?php
var icms icms || {};

icms.images = (function ($) {

    
this.uploadCallback null;
    
this.removeCallback null;

    
//====================================================================//

    
this.upload = function(field_nameupload_url){

        var 
uploader = new qq.FileUploader({
            
elementdocument.getElementById('file-uploader-'+field_name),
            
actionupload_url,
            
multiplefalse,
            
debugfalse,

            
onSubmit: function(idfileName){
                var 
widget = $('#widget_image_'+field_name);
                $(
'.upload'widget).hide();
                $(
'.loading'widget).show();
            },

            
onComplete: function(idfile_nameresult){

                var 
widget = $('#widget_image_'+field_name);

                if(!
result.success) {
                    
alert(result.error);
                    $(
'.upload'widget).show();
                    $(
'.loading'widget).hide();
                    return;
                }

                $(
'.preview img'widget).attr('src'result.paths.small.url);
                $(
'.preview'widget).show();
                $(
'.loading'widget).hide();

                $(
'.data'widget).html('');

                for(var 
path in result.paths){
                    $(
'.data'widget).append('<input type="hidden" name="'+field_name+'['+path+']" value="'+result.paths[path].path+'" />');
                }

                if (
typeof(icms.images.uploadCallback) == 'function'){
                    
icms.images.uploadCallback(field_nameresult);
                }

            }

        });

    }

    
//====================================================================//

    
this.createUploader = function(field_nameupload_url){

        var 
uploader = new qq.FileUploader({
            
elementdocument.getElementById('file-uploader-'+field_name),
            
actionupload_url,
            
debugfalse,

            
onComplete: function(idfile_nameresult){

                if(!
result.success) {
                    return;
                }

                var 
idx = $('.data input:last'widget).attr('rel');
                if (
typeof(idx) == 'undefined') { idx 0; } else { idx++; }

                var 
widget = $('#widget_image_'+field_name);
                var 
preview_block = $('.preview_template'widget).clone().removeClass('preview_template').addClass('preview').attr('rel'idx).show();

                $(
'img'preview_block).attr('src'result.paths.small.url);
                $(
'a'preview_block).click(function() { icms.images.removeOne(field_nameidx); });

                $(
'.previews_list'widget).append(preview_block);

                for(var 
path in result.paths){
                    $(
'.data'widget).append('<input type="hidden" name="'+field_name+'['+idx+']['+path+']" value="'+result.paths[path].path+'" rel="'+idx+'" />');
                }

            }

        });

    }

    
//====================================================================//

    
this.remove = function(field_name){

        var 
widget = $('#widget_image_'+field_name);
        $(
'.preview'widget).hide();
        $(
'.preview img'widget).attr('src''');
        $(
'.upload'widget).show();
        $(
'.loading'widget).hide();
        $(
'.data'widget).html('');

        if (
typeof(icms.images.removeCallback) == 'function'){
            
icms.images.removeCallback(field_nameresult);
        }

    }

    
//====================================================================//

    
this.removeOne = function(field_nameidx){

        var 
widget = $('#widget_image_'+field_name);

        $(
'.data input[rel='+idx+']'widget).remove();
        $(
'.preview[rel='+idx+']'widget).remove();

        var 
count 0;
        var 
current false;

        $(
'.data input').each(function(){

            if (
current === false){
                
current = $(this).attr('rel');
            } else {
                if ($(
this).attr('rel') != current) {
                    
count++;
                    
current = $(this).attr('rel');
                }
            }

            $(
this).attr('rel'count);

        });

        if (
typeof(icms.images.removeCallback) == 'function'){
            
icms.images.removeCallback(field_nameidx);
        }

    }

    
//====================================================================//

    
return this;

}).
call(icms.images || {},jQuery);
?>
Онлайн: 0
Реклама