| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 | 
							- (function () {
 
-     var onlineImage,
 
-         backupStyle = editor.queryCommandValue('background');
 
-     window.onload = function () {
 
-         initTabs();
 
-         initColorSelector();
 
-     };
 
-     /* 初始化tab标签 */
 
-     function initTabs(){
 
-         var tabs = $G('tabHeads').children;
 
-         for (var i = 0; i < tabs.length; i++) {
 
-             domUtils.on(tabs[i], "click", function (e) {
 
-                 var target = e.target || e.srcElement;
 
-                 for (var j = 0; j < tabs.length; j++) {
 
-                     if(tabs[j] == target){
 
-                         tabs[j].className = "focus";
 
-                         var contentId = tabs[j].getAttribute('data-content-id');
 
-                         $G(contentId).style.display = "block";
 
-                         if(contentId == 'imgManager') {
 
-                             initImagePanel();
 
-                         }
 
-                     }else {
 
-                         tabs[j].className = "";
 
-                         $G(tabs[j].getAttribute('data-content-id')).style.display = "none";
 
-                     }
 
-                 }
 
-             });
 
-         }
 
-     }
 
-     /* 初始化颜色设置 */
 
-     function initColorSelector () {
 
-         var obj = editor.queryCommandValue('background');
 
-         if (obj) {
 
-             var color = obj['background-color'],
 
-                 repeat = obj['background-repeat'] || 'repeat',
 
-                 image = obj['background-image'] || '',
 
-                 position = obj['background-position'] || 'center center',
 
-                 pos = position.split(' '),
 
-                 x = parseInt(pos[0]) || 0,
 
-                 y = parseInt(pos[1]) || 0;
 
-             if(repeat == 'no-repeat' && (x || y)) repeat = 'self';
 
-             image = image.match(/url[\s]*\(([^\)]*)\)/);
 
-             image = image ? image[1]:'';
 
-             updateFormState('colored', color, image, repeat, x, y);
 
-         } else {
 
-             updateFormState();
 
-         }
 
-         var updateHandler = function () {
 
-             updateFormState();
 
-             updateBackground();
 
-         }
 
-         domUtils.on($G('nocolorRadio'), 'click', updateBackground);
 
-         domUtils.on($G('coloredRadio'), 'click', updateHandler);
 
-         domUtils.on($G('url'), 'keyup', function(){
 
-             if($G('url').value && $G('alignment').style.display == "none") {
 
-                 utils.each($G('repeatType').children, function(item){
 
-                     item.selected = ('repeat' == item.getAttribute('value') ? 'selected':false);
 
-                 });
 
-             }
 
-             updateHandler();
 
-         });
 
-         domUtils.on($G('repeatType'), 'change', updateHandler);
 
-         domUtils.on($G('x'), 'keyup', updateBackground);
 
-         domUtils.on($G('y'), 'keyup', updateBackground);
 
-         initColorPicker();
 
-     }
 
-     /* 初始化颜色选择器 */
 
-     function initColorPicker() {
 
-         var me = editor,
 
-             cp = $G("colorPicker");
 
-         /* 生成颜色选择器ui对象 */
 
-         var popup = new UE.ui.Popup({
 
-             content: new UE.ui.ColorPicker({
 
-                 noColorText: me.getLang("clearColor"),
 
-                 editor: me,
 
-                 onpickcolor: function (t, color) {
 
-                     updateFormState('colored', color);
 
-                     updateBackground();
 
-                     UE.ui.Popup.postHide();
 
-                 },
 
-                 onpicknocolor: function (t, color) {
 
-                     updateFormState('colored', 'transparent');
 
-                     updateBackground();
 
-                     UE.ui.Popup.postHide();
 
-                 }
 
-             }),
 
-             editor: me,
 
-             onhide: function () {
 
-             }
 
-         });
 
-         /* 设置颜色选择器 */
 
-         domUtils.on(cp, "click", function () {
 
-             popup.showAnchor(this);
 
-         });
 
-         domUtils.on(document, 'mousedown', function (evt) {
 
-             var el = evt.target || evt.srcElement;
 
-             UE.ui.Popup.postHide(el);
 
-         });
 
-         domUtils.on(window, 'scroll', function () {
 
-             UE.ui.Popup.postHide();
 
-         });
 
-     }
 
-     /* 初始化在线图片列表 */
 
-     function initImagePanel() {
 
-         onlineImage = onlineImage || new OnlineImage('imageList');
 
-     }
 
-     /* 更新背景色设置面板 */
 
-     function updateFormState (radio, color, url, align, x, y) {
 
-         var nocolorRadio = $G('nocolorRadio'),
 
-             coloredRadio = $G('coloredRadio');
 
-         if(radio) {
 
-             nocolorRadio.checked = (radio == 'colored' ? false:'checked');
 
-             coloredRadio.checked = (radio == 'colored' ? 'checked':false);
 
-         }
 
-         if(color) {
 
-             domUtils.setStyle($G("colorPicker"), "background-color", color);
 
-         }
 
-         if(url && /^\//.test(url)) {
 
-             var a = document.createElement('a');
 
-             a.href = url;
 
-             browser.ie && (a.href = a.href);
 
-             url = browser.ie ? a.href:(a.protocol + '//' + a.host + a.pathname + a.search + a.hash);
 
-         }
 
-         if(url || url === '') {
 
-             $G('url').value = url;
 
-         }
 
-         if(align) {
 
-             utils.each($G('repeatType').children, function(item){
 
-                 item.selected = (align == item.getAttribute('value') ? 'selected':false);
 
-             });
 
-         }
 
-         if(x || y) {
 
-             $G('x').value = parseInt(x) || 0;
 
-             $G('y').value = parseInt(y) || 0;
 
-         }
 
-         $G('alignment').style.display = coloredRadio.checked && $G('url').value ? '':'none';
 
-         $G('custom').style.display = coloredRadio.checked && $G('url').value && $G('repeatType').value == 'self' ? '':'none';
 
-     }
 
-     /* 更新背景颜色 */
 
-     function updateBackground () {
 
-         if ($G('coloredRadio').checked) {
 
-             var color = domUtils.getStyle($G("colorPicker"), "background-color"),
 
-                 bgimg = $G("url").value,
 
-                 align = $G("repeatType").value,
 
-                 backgroundObj = {
 
-                     "background-repeat": "no-repeat",
 
-                     "background-position": "center center"
 
-                 };
 
-             if (color) backgroundObj["background-color"] = color;
 
-             if (bgimg) backgroundObj["background-image"] = 'url(' + bgimg + ')';
 
-             if (align == 'self') {
 
-                 backgroundObj["background-position"] = $G("x").value + "px " + $G("y").value + "px";
 
-             } else if (align == 'repeat-x' || align == 'repeat-y' || align == 'repeat') {
 
-                 backgroundObj["background-repeat"] = align;
 
-             }
 
-             editor.execCommand('background', backgroundObj);
 
-         } else {
 
-             editor.execCommand('background', null);
 
-         }
 
-     }
 
-     /* 在线图片 */
 
-     function OnlineImage(target) {
 
-         this.container = utils.isString(target) ? document.getElementById(target) : target;
 
-         this.init();
 
-     }
 
-     OnlineImage.prototype = {
 
-         init: function () {
 
-             this.reset();
 
-             this.initEvents();
 
-         },
 
-         /* 初始化容器 */
 
-         initContainer: function () {
 
-             this.container.innerHTML = '';
 
-             this.list = document.createElement('ul');
 
-             this.clearFloat = document.createElement('li');
 
-             domUtils.addClass(this.list, 'list');
 
-             domUtils.addClass(this.clearFloat, 'clearFloat');
 
-             this.list.id = 'imageListUl';
 
-             this.list.appendChild(this.clearFloat);
 
-             this.container.appendChild(this.list);
 
-         },
 
-         /* 初始化滚动事件,滚动到地步自动拉取数据 */
 
-         initEvents: function () {
 
-             var _this = this;
 
-             /* 滚动拉取图片 */
 
-             domUtils.on($G('imageList'), 'scroll', function(e){
 
-                 var panel = this;
 
-                 if (panel.scrollHeight - (panel.offsetHeight + panel.scrollTop) < 10) {
 
-                     _this.getImageData();
 
-                 }
 
-             });
 
-             /* 选中图片 */
 
-             domUtils.on(this.container, 'click', function (e) {
 
-                 var target = e.target || e.srcElement,
 
-                     li = target.parentNode,
 
-                     nodes = $G('imageListUl').childNodes;
 
-                 if (li.tagName.toLowerCase() == 'li') {
 
-                     updateFormState('nocolor', null, '');
 
-                     for (var i = 0, node; node = nodes[i++];) {
 
-                         if (node == li && !domUtils.hasClass(node, 'selected')) {
 
-                             domUtils.addClass(node, 'selected');
 
-                             updateFormState('colored', null, li.firstChild.getAttribute("_src"), 'repeat');
 
-                         } else {
 
-                             domUtils.removeClasses(node, 'selected');
 
-                         }
 
-                     }
 
-                     updateBackground();
 
-                 }
 
-             });
 
-         },
 
-         /* 初始化第一次的数据 */
 
-         initData: function () {
 
-             /* 拉取数据需要使用的值 */
 
-             this.state = 0;
 
-             this.listSize = editor.getOpt('imageManagerListSize');
 
-             this.listIndex = 0;
 
-             this.listEnd = false;
 
-             /* 第一次拉取数据 */
 
-             this.getImageData();
 
-         },
 
-         /* 重置界面 */
 
-         reset: function() {
 
-             this.initContainer();
 
-             this.initData();
 
-         },
 
-         /* 向后台拉取图片列表数据 */
 
-         getImageData: function () {
 
-             var _this = this;
 
-             if(!_this.listEnd && !this.isLoadingData) {
 
-                 this.isLoadingData = true;
 
-                 var url = editor.getActionUrl(editor.getOpt('imageManagerActionName')),
 
-                     isJsonp = utils.isCrossDomainUrl(url);
 
-                 ajax.request(url, {
 
-                     'timeout': 100000,
 
-                     'dataType': isJsonp ? 'jsonp':'',
 
-                     'data': utils.extend({
 
-                             start: this.listIndex,
 
-                             size: this.listSize
 
-                         }, editor.queryCommandValue('serverparam')),
 
-                     'method': 'get',
 
-                     'onsuccess': function (r) {
 
-                         try {
 
-                             var json = isJsonp ? r:eval('(' + r.responseText + ')');
 
-                             if (json.state == 'SUCCESS') {
 
-                                 _this.pushData(json.list);
 
-                                 _this.listIndex = parseInt(json.start) + parseInt(json.list.length);
 
-                                 if(_this.listIndex >= json.total) {
 
-                                     _this.listEnd = true;
 
-                                 }
 
-                                 _this.isLoadingData = false;
 
-                             }
 
-                         } catch (e) {
 
-                             if(r.responseText.indexOf('ue_separate_ue') != -1) {
 
-                                 var list = r.responseText.split(r.responseText);
 
-                                 _this.pushData(list);
 
-                                 _this.listIndex = parseInt(list.length);
 
-                                 _this.listEnd = true;
 
-                                 _this.isLoadingData = false;
 
-                             }
 
-                         }
 
-                     },
 
-                     'onerror': function () {
 
-                         _this.isLoadingData = false;
 
-                     }
 
-                 });
 
-             }
 
-         },
 
-         /* 添加图片到列表界面上 */
 
-         pushData: function (list) {
 
-             var i, item, img, icon, _this = this,
 
-                 urlPrefix = editor.getOpt('imageManagerUrlPrefix');
 
-             for (i = 0; i < list.length; i++) {
 
-                 if(list[i] && list[i].url) {
 
-                     item = document.createElement('li');
 
-                     img = document.createElement('img');
 
-                     icon = document.createElement('span');
 
-                     domUtils.on(img, 'load', (function(image){
 
-                         return function(){
 
-                             _this.scale(image, image.parentNode.offsetWidth, image.parentNode.offsetHeight);
 
-                         }
 
-                     })(img));
 
-                     img.width = 113;
 
-                     img.setAttribute('src', urlPrefix + list[i].url + (list[i].url.indexOf('?') == -1 ? '?noCache=':'&noCache=') + (+new Date()).toString(36) );
 
-                     img.setAttribute('_src', urlPrefix + list[i].url);
 
-                     domUtils.addClass(icon, 'icon');
 
-                     item.appendChild(img);
 
-                     item.appendChild(icon);
 
-                     this.list.insertBefore(item, this.clearFloat);
 
-                 }
 
-             }
 
-         },
 
-         /* 改变图片大小 */
 
-         scale: function (img, w, h, type) {
 
-             var ow = img.width,
 
-                 oh = img.height;
 
-             if (type == 'justify') {
 
-                 if (ow >= oh) {
 
-                     img.width = w;
 
-                     img.height = h * oh / ow;
 
-                     img.style.marginLeft = '-' + parseInt((img.width - w) / 2) + 'px';
 
-                 } else {
 
-                     img.width = w * ow / oh;
 
-                     img.height = h;
 
-                     img.style.marginTop = '-' + parseInt((img.height - h) / 2) + 'px';
 
-                 }
 
-             } else {
 
-                 if (ow >= oh) {
 
-                     img.width = w * ow / oh;
 
-                     img.height = h;
 
-                     img.style.marginLeft = '-' + parseInt((img.width - w) / 2) + 'px';
 
-                 } else {
 
-                     img.width = w;
 
-                     img.height = h * oh / ow;
 
-                     img.style.marginTop = '-' + parseInt((img.height - h) / 2) + 'px';
 
-                 }
 
-             }
 
-         },
 
-         getInsertList: function () {
 
-             var i, lis = this.list.children, list = [], align = getAlign();
 
-             for (i = 0; i < lis.length; i++) {
 
-                 if (domUtils.hasClass(lis[i], 'selected')) {
 
-                     var img = lis[i].firstChild,
 
-                         src = img.getAttribute('_src');
 
-                     list.push({
 
-                         src: src,
 
-                         _src: src,
 
-                         floatStyle: align
 
-                     });
 
-                 }
 
-             }
 
-             return list;
 
-         }
 
-     };
 
-     dialog.onok = function () {
 
-         updateBackground();
 
-         editor.fireEvent('saveScene');
 
-     };
 
-     dialog.oncancel = function () {
 
-         editor.execCommand('background', backupStyle);
 
-     };
 
- })();
 
 
  |