(function() {
var utils = UM.utils,
browser = UM.browser,
Base = {
checkURL: function(url) {
if (!url) return false;
url = utils.trim(url);
if (url.length <= 0) {
return false;
}
if (url.search(/http:\/\/|https:\/\//) !== 0) {
url += 'http://';
}
url = url.replace(/\?[\s\S]*$/, "");
if (!/(.gif|.jpg|.jpeg|.png)$/i.test(url)) {
return false;
}
return url;
},
getAllPic: function(sel, $w, editor) {
var me = this,
arr = [],
$imgs = $(sel, $w);
$.each($imgs, function(index, node) {
$(node).removeAttr("width").removeAttr("height");
// if (node.width > editor.options.initialFrameWidth) {
// me.scale(node, editor.options.initialFrameWidth -
// parseInt($(editor.body).css("padding-left")) -
// parseInt($(editor.body).css("padding-right")));
// }
return arr.push({
_src: node.src,
src: node.src
});
});
return arr;
},
scale: function(img, max, oWidth, oHeight) {
var width = 0,
height = 0,
percent, ow = img.width || oWidth,
oh = img.height || oHeight;
if (ow > max || oh > max) {
if (ow >= oh) {
if (width = ow - max) {
percent = (width / ow).toFixed(2);
img.height = oh - oh * percent;
img.width = max;
}
} else {
if (height = oh - max) {
percent = (height / oh).toFixed(2);
img.width = ow - ow * percent;
img.height = max;
}
}
}
return this;
},
close: function($img) {
$img.css({
top: ($img.parent().height() - $img.height()) / 2,
left: ($img.parent().width() - $img.width()) / 2
}).prev().on("click", function() {
if ($(this).parent().remove().hasClass("edui-image-upload-item")) {
//显示图片计数-1
Upload.showCount--;
Upload.updateView();
}
});
return this;
},
createImgBase64: function(img, file, $w) {
if (browser.webkit) {
//Chrome8+
img.src = window.webkitURL.createObjectURL(file);
} else if (browser.gecko) {
//FF4+
img.src = window.URL.createObjectURL(file);
} else {
//实例化file reader对象
var reader = new FileReader();
reader.onload = function(e) {
img.src = this.result;
$w.append(img);
};
reader.readAsDataURL(file);
}
},
callback: function(editor, $w, url, state) {
if (state == "SUCCESS") {
//显示图片计数+1
Upload.showCount++;
var $img = $(""),
$item = $("
| " + " | <%=lang_btn_add%> |