// JavaScript Document dialog
/**
*(**************************** 素材管理弹框 *************************
*/
(function(){
var elemBase,elemBody,elemLocal,elemWeb, elemOnline, elemIcon, elemLogo,options;
var selectPicData = [];
function initBase(){
elemBase = $('
');
$('.upload_web',elemBase).click(function(){
$(this).addClass('cur').siblings().removeClass('cur');
initWeb();
});
$('.upload_local',elemBase).click(function(){
$(this).addClass('cur').siblings().removeClass('cur');
initLocal();
});
$('.online',elemBase).click(function(){
$(this).addClass('cur').siblings().removeClass('cur');
initOnline();
});
$('.icon',elemBase).click(function(){
$(this).addClass('cur').siblings().removeClass('cur');
initOnline();
});
$('.background',elemBase).click(function(){
$(this).addClass('cur').siblings().removeClass('cur');
initOnline();
});
$('.logo',elemBase).click(function(){
$(this).addClass('cur').siblings().removeClass('cur');
initOnline();
});
$('.confirm',elemBase).click(function(){
if(options.type==0 && options.muti==false && selectPicData.length>0){
$("#"+options.picId).val(selectPicData[0].id);
$("#"+options.previewId).html('').show();
}
$.Dialog.close();
});
}
function initLocal(){
if(!elemLocal)elemLocal = $('');
elemBody.html(elemLocal);
$('.upload_wrap .web',elemLocal).click(function(){
$('.upload_wrap .local',elemLocal).hide();
});
$("#upload_picture_file",elemLocal).uploadify({
"height" : 40,
"swf" : STATIC+"/uploadify/uploadify.swf",
"fileObjName" : "download",
"buttonText" : "上传图片",
"uploader" : options.uploadUrl,
"width" : 120,
'removeTimeout' : 1,
'fileTypeExts' : '*.jpg; *.png; *.gif;',
"onUploadSuccess" : function(file, data){
var data = $.parseJSON(data);
var src = '';
if(data.status){
src = data.url || ROOT + data.path;
$(".preview",elemLocal).html('
');
var json = new Object();
json.src = src;
json.id = data.id;
selectPicData.push(json);
} else {
updateAlert(data.info);
setTimeout(function(){
$('#top-alert').find('button').click();
$(that).removeClass('disabled').prop('disabled',false);
},1500);
}
}
});
}
function initWeb(){
if(!elemWeb)elemWeb = $('');
$('.upload_wrap .web',elemWeb).click(function(){
$('.upload_wrap .local',elemWeb).hide();
});
elemBody.html(elemWeb);
}
function initOnline(){
if(!elemOnline)elemOnline = $('');
var elemCate = $('');
var elemList = $('.pic_list',elemOnline);
var elemPage = $('.image_page',elemOnline);
var elemCateSwitch = $('.cate_switch',elemCate);
var elemCateList = $('.cate_list',elemCate);
elemCateSwitch.click(function(){
if(!elemCateSwitch.hasClass('open')){
elemCateList.show();
elemCateSwitch.text("关闭分类").hide().show();
elemCateSwitch.addClass("open");
}else{
elemCateList.hide();
elemCateSwitch.text("选择分类");
elemCateSwitch.removeClass("open");
}
});
//类别加载
elemCateList.html("");
for(var i=0;i<21;i++){
var $cate = $('小图标');
elemCateList.append($cate);
$cate.click(function(){
alert("选择了分类 "+$(this).text());
elemCateList.hide();
elemCateSwitch.removeClass("open").text("选择图标");
});
}
//图片加载
var imageCount = 100;
var pages = Math.ceil(imageCount/21);
elemList.html("");
for(var i=0;i<20;i++){
var $img = $('
');
elemList.append($img);
$img.click(function(){
$(this).addClass('select').siblings().removeClass('select');
});
}
//页码
elemPage.html("");
for(var i=0;i'+parseInt(i+1)+'');
if(i==0){
$a.addClass('cur');
}
elemPage.append($a);
$a.click(function(){
loadImage(1);
});
}
elemBody.html(elemOnline);
elemBody.append(elemCate);
}
function init(data){
options = data;
initBase();
$.Dialog.open("素材管理",{"width":800,"height":520},elemBase);
elemBody = $('.image_body',elemBase);
initLocal();
}
var ImageManager = {
init:init,
close: $.Dialog.close
};
$.extend({ImageManager: ImageManager});
})();