').addclass('hiddens').appendto($this),
isextendfield;
if (propertyname) {
isextendfield = propertyname.indexof("extendcontentobject") > -1;
}
if ($this.hasclass('disabled')) {
$this.find('.checkbox').icheck('disable');
}
$this.on('disable.power',
function () {
$(this).find('input:checkbox').attr('disabled', 'disabled');
});
$this.on('enable.power',
function () {
$(this).find('input:checkbox').removeattr('disabled');
});
var checkeditems = [];
$.each($this.find(':checkbox:checked'),
function () {
checkeditems.push($(this).val());
});
$this.data('original', checkeditems);
$this.parents('form')
.on('reset',
function (e) {
$this.find(':checkbox:checked').icheck('uncheck');
var items = $this.data('original');
if (items.length > 0) {
$.each(items,
function (k, v) {
$this.find(':checkbox[value=' + v + ']').icheck('check');
});
}
});
$checkboxs.each(function (i, n) {
$(this).attr('name', '');
});
$checkboxs.on('ifchanged',
function () {
$hiddens.html('');
settimeout(createhiddens, 200);
});
function createhiddens() {
if (isextendfield) {
var $hidden = $('
').attr('type', 'hidden').attr('name', propertyname);
$this.find('.checked input:checkbox')
.each(function (i, n) {
if ($hidden.val() == '') {
$hidden.val($(this).val());
} else {
$hidden.val($hidden.val() + ',' + $(this).val());
}
});
$hiddens.append($hidden);
} else {
$this.find('.checked input:checkbox')
.each(function (i, n) {
var $hidden;
if (fieldname) {
$hidden = $('
')
.attr('type', 'hidden')
.attr('name', propertyname + '[' + i + '].' + fieldname);
} else {
$hidden =
$('
').attr('type', 'hidden').attr('name', propertyname + '[' + i + ']');
}
$hidden.val($(this).val());
$hiddens.append($hidden);
});
}
}
settimeout(createhiddens, 200);
});
filtercontrols('flagscheckboxlist')
.each(function () {
var $this = $(this),
$checkboxs = $this.find('input:checkbox'),
propertyname = $checkboxs.first().attr('name'),
$hidden = $('
').attr('type', 'hidden').attr('name', propertyname).appendto($this);;
if ($this.hasclass('disabled')) {
$this.find('.checkbox').icheck('disable');
}
$checkboxs.each(function (i, n) {
$(this).attr('name', '');
});
$checkboxs.on('ifchanged',
function () {
settimeout(createhidden, 200);
});
$this.on("disable.power",
function () {
$checkboxs.attr("disabled", "disabled");
});
$this.on("enable.power",
function () {
$checkboxs.removeattr("disabled");
});
function createhidden() {
var val = 0;
$this.find('.checked input:checkbox')
.each(function (i, n) {
val += number($(n).val());
});
$hidden.val(val);
}
settimeout(createhidden, 200);
});
filtercontrols('select')
.each(function () {
var $this = $(this),
setting = $.extend({
width: $this.data('width'),
},
$this.data());
$this.data('original', $this.val());
$(this).selectpicker(setting);
$this.parents('form')
.on('reset',
function (e) {
$this.selectpicker('val', $this.data('original'));
$this.selectpicker('refresh');
});
$this.on('disable.power',
function () {
$(this).attr('disabled', true);
$this.selectpicker('refresh');
});
$this.on('enable.power',
function () {
$(this).removeattr('disabled', false);
$this.selectpicker('refresh');
});
$this.prop('disabled', false);
});
filtercontrols('switch')
.each(function () {
var $this = $(this),
data = $this.data(),
name = $this.attr("name"),
$hiddenhandel = $("#hidden_" + name),
setting = { color: '#088bcf' };
var switchery = new switchery(this, $.extend({}, setting, data));
$this.change(function () {
$(this).attr('value', this.checked);
if (this.checked) {
$hiddenhandel.attr("disabled", "disabled");
} else {
$hiddenhandel.removeattr("disabled");
}
});
$this.on('disable.power',
function () {
$hiddenhandel.attr("disabled", "disabled");
$(this).next().remove();
switchery.options.disabled = true;
switchery.init();
});
$this.on('enable.power',
function () {
$hiddenhandel.removeattr("disabled");
$(this).next().remove();
$(this).removeattr('disabled');
switchery.options.disabled = false;
switchery.init();
});
});
filtercontrols('uploader')
.each(function () {
var $this = $(this),
uploadpathreplacesymbol = $this.data('uploadpathreplacesymbol'),
uploadpath = $this.data('uploadpath');
$this.on('disable.power',
function () {
$("#upload_overlay").css("display", "block");
$this.find("input[type=hidden]").attr("disabled", "disabled");
});
$this.on('enable.power',
function () {
$("#upload_overlay").css("display", "none");
$this.find("input[type=hidden]").removeattr("disabled");
});
var qrcodebutton = $this.find(".qrcode-button");
var token;
if (!qrcodebutton) {
return;
}
var $qrcodecontainerdata = $this.find("#qrcode-container").data();
function getkeyvalue(url, name) {
var parastring = url.substring(url.indexof("?") + 1, url.length).split("&");
var data = new dictionary();
for (var i = 0; i < parastring.length; i++) {
data.put(parastring[i].split("=")[0], parastring[i].split("=")[1]);
}
return data.get(name);
}
function dictionary() {
this.data = new array();
this.put = function (key, value) {
this.data[key] = value;
};
this.get = function (key) {
return this.data[key];
};
this.remove = function (key) {
this.data[key] = null;
};
this.isempty = function () {
return this.data.length == 0;
};
this.size = function () {
return this.data.length;
};
}
function mobileuploadsuccessresult(mobileuploadresult) {
var relativepath = mobileuploadresult.relativepath.replacepathsymbolforshow(uploadpathreplacesymbol, uploadpath);
new pe.ui.message('上传成功!', 'success');
$this.find(".photolist").removeclass("hidden");
$this.find(".upload-placeholder").css("position", "absolute");
$this.find(".upload-placeholder").css("top", "-15000px");
$($this.find(".photolist li img")[0]).attr("src", relativepath);
$($this.find(".photolist input")[0]).val(mobileuploadresult.relativepath);
$this.find("#qrcode-area-img").modal('hide');
}
$this.find('#btnqrcode')
.on('click',
function () {
qrcodebutton.click();
});
$("body").on('power.mobilefileuploaded',
function (event, imageuploadtoken, mobileuploadresult) {
if (token === imageuploadtoken && !mobileuploadresult.iserror) {
mobileuploadsuccessresult(mobileuploadresult);
}
});
qrcodebutton.on('click',
function () {
var qrcodecontent = $qrcodecontainerdata.getqrcodecontent;
if (qrcodecontent) {
//生成contenturl。
$.ajax({
url: qrcodecontent,
type: "get",
data: {
'uploadproviderkey': $qrcodecontainerdata.uploadproviderkey,
'isextendfield': $qrcodecontainerdata.isextendfield,
'extendfieldid': $qrcodecontainerdata.extendfieldid
},
success: function (contenturl) {
if (contenturl) {
$qrcodecontainerdata.qrcodecontent = contenturl;
$this.find(".qrcode-link").attr('href', contenturl);
var qrcodeimg = $this.find(".qrcode-img");
$this.find("#qrcode-area-img").modal('show');
qrcodeimg.attr("src",
'/qrcode/qrcode?content=' +
contenturl +
'&size=200');
token = getkeyvalue($qrcodecontainerdata.qrcodecontent, "token");
} else {
new pe.ui.message('扫码上传路径生成失败!', 'error');
}
}
});
}
});
});
filtercontrols('multilinetext')
.each(function () {
var $this = $(this);
if ($this.attr("autosize")) {
$this.autosize();
}
if ($this.attr("isfullscreen")) {
$this.fseditor();
}
$this.on('propertychange',
function () {
var maxlength = $this.attr('maxlength');
if (maxlength > 0) {
if ($this.val().length > maxlength) {
$this.val($this.val().substr(0, maxlength));
}
}
});
$this.on("disable.power",
function () {
$this.attr("disabled", "disabled");
});
$this.on("enable.power",
function () {
$this.removeattr("disabled");
});
});
filtercontrols('colorpicker')
.each(function () {
var $this = $(this),
setting = $.extend({
format: 'hex'
});
if ($this.attr('disabled') !== 'disabled') {
$this.colorpicker(setting);
} else {
$this.find('i').attr('style', 'background-color:' + $this.find('input').val());
}
$this.on('disable.power',
function () {
$this.colorpicker('disable');
});
$this.on('enable.power',
function () {
$this.colorpicker('enable');
});
});
filtercontrols('buttonset')
.each(function () {
var $this = $(this);
if ($this.find('input[type="radio"]:checked').length) {
$this.find('input[type="radio"]:first').prop('checked', true);
$this.find('label:first').addclass('active');
}
$this.on('disable.power',
function () {
$this.find('input[type="radio"]').attr("disabled", "true");
});
$this.on('enable.power',
function () {
$this.find('input[type="radio"]').removeattr("disabled");
});
});
filtercontrols('emailbox')
.each(function () {
var $emailboxinput = new pe.ui.emailbox(this);
$(this)
.on('disable.power',
function () {
$emailboxinput.disable();
}),
$(this)
.on('enable.power',
function () {
$emailboxinput.enable();
}); //用于测试disabled和enable方法
//$(this).trigger('disable.power');
//$(this).trigger('enable.power');
});
filtercontrols('listbox')
.each(function () {
var $listbox = new pe.ui.listbox(this);
$(this)
.on('disable.power',
function () {
$listbox.disable();
}),
$(this)
.on('enable.power',
function () {
$listbox.enable();
});
});
var legends = filtercontrols('legend');
if (legends.length > 0) {
$('form')
.submit(function () {
openlenged();
});
legends.each(function () {
var $this = $(this);
$this.on('click',
'.form-legend',
function () {
if ($this.hasclass('open')) {
$this.removeclass('open');
//$this.switchclass('open', '');
} else {
$this.switchclass('', 'open');
}
$('body').animate({ scrolltop: $this.offset().top });
// 特殊处理,当legend展开时,刷新上传控件上传按钮位置。
settimeout(function () {
$('.upload-file-single')
.each(function () {
$(this).data('curuploadobject').refresh();
});
$('.upload-photo-single')
.each(function () {
$(this).data('curuploadobject').refresh();
});
$('.upload-file-multi')
.each(function () {
$(this).data('curuploadobject').refresh();
});
$('.upload-photo-multi')
.each(function () {
$(this).data('curuploadobject').refresh();
});
var minheight = $(window).height() * 0.9,
containerheight = $('#all-page-container').height();
if (containerheight < minheight) {
$('.widget-box').removeclass('widget-bottom-fixed');
} else {
$('.widget-box').addclass('widget-bottom-fixed');
}
},
500);
});
});
}
function openlenged() {
var errors = $(".field-validation-error");
if (errors.length > 0) {
errors.each(function () {
var legend = $(this).parents('[data-ui-type="legend"]');
if (legend && !legend.hasclass('open')) {
legend.switchclass('', 'open');
}
});
}
}
filtercontrols('identifier')
.each(function () {
var $this = $(this);
$('#' + $this.data().identifiersource)
.on('change',
function () {
var check = /^(?!(.|\n)*<[a-z!\/?])(?!(.|\n)*)(.|\n)*$/i;
if (check.test($(this).val())) {
var $input = $(this),
identifierurl = $this.data().identifierurl;
$.ajax({
url: identifierurl,
type: "post",
data: { 'name': $input.val() },
success: function (data) {
$this.val(data);
}
});
}
});
});
filtercontrols('tags')
.each(function () {
var setting = {},
$tags = $(this),
source = $tags.attr("data-source").split(",");
if (source) {
setting.typeahead = {
source: source
};
}
$tags.tagsinput(setting);
$tags.on("disable.power",
function () {
$tags.next().find("input").attr("disabled", "disabled");
});
$tags.on("enable.power",
function () {
$tags.next().find("input").removeattr("disabled");
});
});
filtercontrols('cron')
.each(function () {
var $cron = $(this),
$partitionnumber = $cron.find('#partitionnumber'),
$partitiontimeunit = $cron.find('#partitiontimeunit'),
$fixedtimeweek = $cron.find('#fixed-time-week'),
$fixedtimetime = $cron.find('#fixed-time-time'),
$detaileddefinitioncron = $cron.find("#detailed-definition-cron"),
$cronexpressions = $cron.find("#cronexpression").find('input'), // 解决单页面存在多表达式控件问题
$form = $cron.parents('form');
initcroncontrol();
function initcroncontrol() {
if ($cronexpressions.val().trim() === '') {
$cronexpressions.val('0 3 * * *');
}
var cronexpressionsval = $cronexpressions.val();
$cronexpressions.css("display", 'none');
if (checkpartitiontcontrol(cronexpressionsval)) {
initpartitiontcontrol(cronexpressionsval);
} else if (checkfixedtimecontrol(cronexpressionsval)) {
initfixedtimecontrol(cronexpressionsval);
} else {
initdetaileddefinitioncontrol(cronexpressionsval);
}
}
function checkpartitiontcontrol(cronexpressionsval) {
var cronparams = cronexpressionsval.split(" ");
if (!checkminutefield(cronparams[0])) {
return false;
}
if (!checkhourfield(cronparams[1])) {
return false;
}
if (!checkstar(cronparams[2]) || !checkstar(cronparams[3])) {
return false;
}
if (!checkstar(cronparams[4]) && !checkweekfield(cronparams[4])) {
return false;
}
return true;
}
function checkweekfield(field) {
var reg = /^(0|([1-9]\d?)|(1[01]\d)|(6))(\.\d*)?$/;
if (!reg.test(field)) {
return false;
}
return true;
}
function checkminutefield(field) {
var reg = /^(|[1-5])[0-9]$/;
if (!reg.test(field)) {
return false;
}
return true;
}
function checkstar(field) {
if (field !== "*") {
return false;
}
return true;
}
function checkhourfield(field) {
var reg = /^(0|([1-9]\d?)|(1[01]\d)|(23))(\.\d*)?$/;
if (!reg.test(field)) {
return false;
}
return true;
}
function checkfixedtimecontrol(cronexpressionsval) {
var cronparams = cronexpressionsval.split(" ");
if (!checkslash(cronparams[0]) && !checkslash(cronparams[1])) {
return false;
} else if (checkslash(cronparams[0]) && checkslash(cronparams[1])) {
return false;
} else if (checkslash(cronparams[0]) && !checkstar(cronparams[1])) {
return false;
} else if (checkslash(cronparams[1]) && !checkstar(cronparams[0])) {
// 每x小时 0 */x * * * 执行。
if (cronexpressionsval.indexof("0 */") === 0 &&
cronexpressionsval.lastindexof("* * * *") === -1 &&
cronexpressionsval.lastindexof(" * * *") > 0) {
return true;
}
return false;
}
if (!checkstar(cronparams[2]) || !checkstar(cronparams[3]) || !checkstar(cronparams[4])) {
return false;
}
return true;
}
function checkslash(field) {
if (field && field.indexof("/") > -1) {
return true;
}
return false;
}
function initpartitiontcontrol(cronexpressionsval) {
var cronparams = cronexpressionsval.split(" ");
var week;
var min = addzero(cronparams[0]);
var hour = addzero(cronparams[1]);
if (cronparams[4] === "*") {
week = "8";
} else {
week = cronparams[4];
}
$fixedtimetime.val(hour + ':' + min);
var selectedradio = $fixedtimeweek.find("option[value='" + week + "']");
selectedradio.attr("selected", true);
setbootstrapselecttext('[data-id="fixed-time-week"] .pull-left', selectedradio.text());
checkradiotimeroption(0);
}
function addzero(number) {
if (parseint(number) < 10) {
return '0' + number;
}
return number;
}
function initfixedtimecontrol(cronexpressionsval) {
var cronparams = cronexpressionsval.split(" ");
for (var i = 0; i < cronparams.length - 1; i++) {
if (cronparams[i].indexof('*/') > -1) {
var partitionnumber = cronparams[i].replace('*/', '');
$partitionnumber.val(partitionnumber);
var selectedradio = $partitiontimeunit.find("option[value='" + (i + 1) + "']");
selectedradio.attr("selected", true);
setbootstrapselecttext('[data-id="partitiontimeunit"] .pull-left', selectedradio.text());
checkradiotimeroption(1);
}
}
}
function setbootstrapselecttext(spanelementtarget, textval) {
var fixedtimeweekspan = $(spanelementtarget);
fixedtimeweekspan.text(textval);
}
function initdetaileddefinitioncontrol() {
checkradiotimeroption(2);
$cronexpressions.css("display", 'block');
}
function checkradiotimeroption(index) {
$cron.find('.iradio_minimal-blue').removeclass("checked");
$($cron.find('[name="timer-option"]')[index]).parent().addclass("checked");
$($cron.find('[name="timer-option"]')[index]).attr('checked', 'true');
}
$form.on('submit',
function () {
if ($cronexpressions.val().trim() === '') {
new pe.ui.message('请设置定时更新!', 'warning');
return false;
}
});
$fixedtimetime.datetimepicker({
language: 'zh-cn',
autoclose: true,
format: 'hh:ii',
minview: 0,
startview: 0,
pickerposition: 'top-right'
})
.on('show',
function () {
$('.table-condensed .switch').css('visibility', 'hidden');
$('.datetimepicker-dropdown-top-right').css('overflow-y', 'hidden');
});
$cron.find('[name="timer-option"]')
.on('click',
function () {
$cron.find('.iradio_minimal-blue').removeclass("checked");
$(this).parent().addclass("checked");
$cronexpressions.css("display", 'none');
setpartitiontcronstring();
setfixedtimecronstring();
setdetaileddefinitioncronstring();
});
$partitiontimeunit.on('change',
function () {
setpartitiontcronstring();
});
$partitionnumber.keyup(function () {
setpartitiontcronstring();
});
$partitionnumber.keypress(function () {
keypress();
});
$detaileddefinitioncron.keyup(function () {
setdetaileddefinitioncronstring();
});
$fixedtimeweek.on('change',
function () {
setfixedtimecronstring();
});
$fixedtimetime.on('change',
function () {
setfixedtimecronstring();
});
function keypress() {
var keycode = event.keycode;
if ((keycode >= 48 && keycode <= 57)) {
event.returnvalue = true;
} else {
event.returnvalue = false;
}
}
function setpartitiontcronstring() {
var timeroptionval = gettimeroptionval();
if (timeroptionval === '1') {
var partitionnumber = $partitionnumber.val();
var partitiontimeunit = $partitiontimeunit.val();
var partitiontcronstring =
getpartitiontcronstring(partitionnumber, parseint(partitiontimeunit));
$cronexpressions.val(partitiontcronstring);
}
}
function setdetaileddefinitioncronstring() {
var timeroptionval = gettimeroptionval();
if (timeroptionval === '3') {
$cronexpressions.css("display", 'block');
} else {
$cronexpressions.css("display", 'none');
}
}
function setfixedtimecronstring() {
var timeroptionval = gettimeroptionval();
if (timeroptionval === '2') {
var fixedtimetime = $fixedtimetime.val();
var fixedtimeweek = $fixedtimeweek.val();
var partitiontcronstring = getfixedtimecronstring(fixedtimeweek, fixedtimetime);
$cronexpressions.val(partitiontcronstring);
}
}
function gettimeroptionval() {
return $cron.find("input[name='timer-option']:checked").val() || $cron.find("input[name='timer-option']").filter("[checked='checked']").val();
}
function getpartitiontcronstring(partitionnumber, partitiontimeunit) {
var cronstring = "";
for (var i = 1; i < 6; i++) {
if (partitiontimeunit === i) {
cronstring = cronstring + "*/" + partitionnumber + " ";
} else {
if (partitiontimeunit >= 3 && i === 2) {
cronstring = cronstring + "3 ";
} else {
if (cronstring === "") {
// 修复cron每小时执行一次。
cronstring = "0 ";
} else {
cronstring = cronstring + "* ";
}
}
}
}
return cronstring;
}
function getfixedtimecronstring(fixedtimeweek, fixedtimetime) {
var cronstring = '';
var times = fixedtimetime.split(":");
var hour = parseint(times[0]);
var minute = parseint(times[1]);
if (fixedtimeweek === "8") {
cronstring = minute + " " + hour + " * * *";
} else {
cronstring = minute + " " + hour + " * * " + fixedtimeweek;
}
return cronstring;
}
});
filtercontrols('keywords')
.each(function () {
var $this = $(this);
var feedback = $this.find('.form-control-feedback');
var $tags = $this.find('.form-control');
var action = $this.attr("data-action");
var fromfieldname = $this.attr("data-fromfieldname");
var count = $this.attr("data-count");
if ($('[name=' + fromfieldname + ']').length === 0) {
$this.find('.pickup-keyword').prop("hidden", true);
}
$this.find('.pickup-keyword')
.on('click',
function () {
var content = $('[name=' + fromfieldname + ']').val();
if (!content) {
new pe.ui.message('请输入内容后再提取关键词!', 'warning');
return false;
}
$.ajax({
url: action,
data: {
'content': content,
'count': count
},
type: "get",
datatype: 'json',
beforesend: function () {
feedback.addclass('glyphicon-time');
},
complete: function () {
feedback.removeclass('glyphicon-time');
},
success: function (keywords) {
if (keywords.length > 0) {
$tags.tagsinput('removeall');
$.each(keywords,
function (index, keyword) {
$tags.tagsinput('add', keyword);
});
} else {
new pe.ui.message('未能提取到关键词,请检查输入内容后再提取关键词!', 'warning');
}
}
});
});
});
filtercontrols('mutiplelistbox')
.each(function (k, v) {
var propertyname = $(this).attr('data-mutiplelistbox-propertyname');
var bindpropertyname = $(this).attr('data-mutiplelistbox-datavaluefieldname');
$(v).after('
');
$("form")
.submit(function () {
var index = -1;
var options = $(v).find('option:selected');
$.each(options,
function (kk, vv) {
index++;
var hidden = '
';
var chkbox = '
';
$(v).next('div').append(hidden).append(chkbox);
});
});
});
filtercontrols('icon')
.each(function (k, v) {
var $this = $(this),
datasource = ['fa fa-folder-o'];
//修改时候的情况
if ($this.val() !== "") {
datasource = $this.val();
}
var iconpicker = $this.fonticonpicker({
allcategorytext: '所有',
iconsperpage: 20,
hassearch: true,
emptyicon: false
});
iconpicker.seticons([datasource]);
//为下拉框绑定事件。
$('.selector-button')
.on('click',
function () {
$.ajax({
url: '/admin/content/base/js/power.fonticonpicker.js',
success: function () {
iconpicker.seticons(fa);
}
});
});
});
filtercontrols("multiselect")
.each(function (k, v) {
var setting = {},
$select = $(this),
data = $select.data();
$select.multiselect($.extend({}, setting, data));
var propertyname = $(this).attr('data-name');
var bindpropertyname = $(this).attr('data-field');
$(v).after('
');
if (!$(this).attr('data-propertys')) {
$("form")
.submit(function () {
$(v).next('div').html('');
var index = -1;
var options = $(v).find('option:selected');
$.each(options,
function (kk, vv) {
index++;
var hidden = '
';
var chkbox = '
';
$(v).next('div').append(hidden).append(chkbox);
});
});
}
});
filtercontrols('autocomplete')
.each(function (k, v) {
var config = getautocompleteconfig(this);
$(this)
.typeahead({
source: function (query, process) {
$.ajax({
url: config.url,
datatype: 'json',
type: 'get',
data: { term: query, count: config.itemcount },
success: function (result) {
var i,
items;
if (typeof result === 'string') {
result = $.parsejson(result);
}
items = $.map(result,
function (data) {
if (typeof data === 'string') {
return data;
} else {
for (i in data) {
if (data.hasownproperty(i)) {
return data[i];
}
}
}
});
return process(items);
}
});
},
matcher: function (item) {
return true;
},
minlength: 0
});
});
function getautocompleteconfig(obj) {
var o = $(obj);
return {
url: o.attr('data-autocomplete-url'),
itemcount: o.attr('data-autocomplete-itemcount')
};
}
//filtercontrols('tree').each(function (k, v) {
//});
////var checksettings = {
//// checkboxclass: 'icheckbox_minimal-blue',
//// radioclass: 'iradio_minimal-blue'
////};
////filtercontrols('radio').icheck(checksettings);
////filtercontrols('checkbox')
//// .icheck(checksettings)
//// .on('ifchanged',
//// function (event) {
//// var $self = $(this);
//// settimeout(function () {
//// $self.attr('checked', $self.parent().is('.checked'));
//// },
//// 200);
//// }
//// );
var editors = filtercontrols('ueditor');
if (editors.length > 0) {
editors.each(function (i, n) {
if ($(n).attr('disabled') === 'disabled') {
return;
}
var $this = $(n),
pattern = $this.data('ueditor-pattern'),
simplebuttons = [
'collapse', 'rarefont', 'source', '|', 'undo', 'redo', '|',
'fontfamily', 'fontsize', 'bold', 'italic', 'underline', 'strikethrough', '|',
'forecolor', 'backcolor', 'removeformat', '|',
'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|',
'indent', 'insertorderedlist', 'insertunorderedlist', 'inserttable', 'lineheight', 'link'
],
normalbuttons = simplebuttons.concat([
'|', 'insertimage', 'qrcodeupload', 'wordconvert', 'attachment',
'insertaudio', 'insertvideo'
]),
fullbuttons = [
'fullscreen', 'collapse', 'rarefont', 'source', '|',
'fontfamily', 'fontsize', 'bold', 'italic', 'underline', '|',
'forecolor', 'backcolor', 'removeformat', 'autoformat', 'typoscheck', '|',
'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|',
'indent', 'insertorderedlist', 'insertunorderedlist', 'inserttable', 'lineheight', '|',
'wordconvert', 'pdfconvert', 'insertimage', 'qrcodeupload', 'link',
'attachment', 'map',
'insertaudio', 'insertvideo', 'autotypeset', 'fontborder',
'superscript', 'subscript', 'formatmatch', 'blockquote', 'pasteplain', '|',
'selectall', 'cleardoc', '|',
'rowspacingtop', 'rowspacingbottom', '|', 'customstyle', 'paragraph', '|',
'directionalityltr',
'directionalityrtl', '|',
'strikethrough', '|', 'unlink', 'anchor', '|', 'imagenone',
'imageleft',
'imageright', 'imagecenter', '|',
'pagebreak', 'template', 'background', '|', 'horizontal', 'date', 'time',
'spechars', 'kityformula', 'wordimage', '|',
'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow',
'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells',
'splittorows', 'splittocols', 'charts', '|', 'undo', 'redo', '|',
'searchreplace', 'drafts', 'autosave', 'message'
],
extremesimplebuttons = [
'rarefont', 'undo', 'redo', '|',
'fontfamily', 'fontsize', 'bold', '|',
'forecolor', '|',
'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'insertorderedlist',
'insertunorderedlist'
],
weixinbuttons = [
'rarefont', 'source', 'undo', 'redo', '|', 'fontfamily', 'fontsize', 'bold', '|', 'forecolor', '|',
'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'insertimage', 'qrcodeupload', 'wordconvert', 'insertvideo'
],
microbuttons = [
'rarefont', 'bold', '|',
'forecolor', '|',
'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'insertorderedlist',
'insertunorderedlist'
],
typobuttons = [
'rarefont', 'undo', 'redo', '|',
'fontfamily', 'fontsize', 'bold', '|',
'forecolor', '|',
'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'insertorderedlist',
'insertunorderedlist', 'typoscheck'
],
config = {
//这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
toolbars: [],
initialcontent: '',
readonly: $this.attr('readonly') === 'readonly' ? true : false,
autoheightenabled: false,
initialframewidth: '100%',
autofloatenabled: false,
serverurl: $this.data('fileupload'),
mergeurl: $this.data('mergeurl'),
elementpathenabled: false,
initialframeheight: $this.data("height"),
wordcount: false
},
uploadpath = $this.data('uploadpath'),
symbol = $this.data('uploadpathreplacesymbol');
switch (pattern.tolowercase()) {
case 'simple':
config.toolbars = [simplebuttons];
break;
case 'full':
config.toolbars = [fullbuttons];
config.wordcount = true;
break;
case 'extremesimple':
config.toolbars = [extremesimplebuttons];
config.wordcount = true;
break;
case 'weixin':
config.toolbars = [weixinbuttons];
break;
case 'micro':
config.toolbars = [microbuttons];
break;
case 'typo':
config.toolbars = [typobuttons];
break;
default:
config.toolbars = [normalbuttons];
break;
}
var editorsetting = $.extend({}, config, $this.data()),
editor = new ue.geteditor($this.attr('id'), editorsetting);
editor.addlistener("beforepaste",
function (type, html) {
var $html = $("
" + html.html + "
");
if ($html.length < 1) {
return;
}
var hyperlink = $html.find('a');
if (hyperlink.length > 0) {
if (confirm("内容含有超链接,是否去掉超链接?")) {
hyperlink.each(function () {
$(this).removeattr("href");
$(this).removeattr("_href");
});
}
}
$html.find('voice').replacewith(function () {
var $element = $(this);
return $element.text();
});
html.html = $html.html();
//html.html = $('
').append($html).html(); 外部嵌套一层div,在粘贴的时候会报错。
//html.html = html.html.replace(/
]*)>([^<>]*)<\/voice>/gi, "$2");
});
editor.options["uploadproviderkey"] = $(this).attr("data-uploadproviderkey");
editor.options["extendfieldid"] = $(this).attr("data-extendfieldid");
editor.options["isextendfield"] = $(this).attr("data-isextendfield");
editor.options["managepath"] = $(this).attr("data-managepath");
editor.options["uploadpath"] = uploadpath;
editor.options["uploadpathreplacesymbol"] = symbol;
editor.options["pdfconverturl"] = $(this).attr("data-pdfconverturl");
editor.options["insertaudiourl"] = $(this).attr("data-insertaudiourl");
editor.options["wordconverturl"] = $(this).attr("data-wordconverturl");
editor.options["qrcodeuploadurl"] = $(this).attr("data-qrcodeuploadurl");
editor.options["qrcodedialogurl"] = $(this).attr("data-qrcodedialogurl");
editor.options["absolutefrontsiteurl"] = $(this).attr("data-absolutefrontsiteurl");
editor.ready(function () {
var $form = $this.parents('form'),
pathregex = new regexp('((src|href)\\s*=\\s*(\"|\'))' + uploadpath, 'gi');
$this.data('original', editor.getcontent());
$form.on('reset',
function (e) {
if (this !== e.target) {
return;
}
editor.setcontent($this.data('original'));
});
$form.on('submit',
function () {
if (editor.querycommandstate('source') === 1) {
editor.execcommand('source');
}
//var value = $this.val(); 在火狐下获取不到正确值。
var value = editor.getcontent();
$this.val(value.replace(pathregex, "$1" + symbol));
});
});
$this.data('editor', editor);
});
};
}
})(jquery);
//使用angular的控件,控制器。
$(function () {
$('label.control-label')
.each(function () {
var title = $(this).attr('title');
if (title != '' && title != undefined) {
var $i = $('');
$i.attr('data-content', $(this).attr('title'))
.attr('data-trigger', 'tooltip')
.attr('data-position', 'ne');
$(this).prepend($i);
}
});
if ($('i[data-trigger=tooltip]').length > 0) {
$('i[data-trigger=tooltip]').scojs_tooltip({ position: 'ne', delay: 0 });
}
pe.ui.ueditor = {
filtertypotag: function () {
var contenteditorname = $("[data-ui-type='ueditor']").attr("name");
function filtertypostag(content) {
var $content = $($.parsehtml(content));
$content.find('span[data-typos-type]').replacewith(function () { return $(this).text(); });
var $body = $("");
$content.each(function () {
$body.append($(this));
});
return $body.html();
}
function addlistenercontentchange() {
if (contenteditorname === "content") {
var contenteditor = ue.geteditor('content');
contenteditor.addlistener('contentchange',
function () {
window.pe.typo.typoconfig.contentchanges = true;
});
}
}
addlistenercontentchange();
$('form')
.submit(function () {
if (contenteditorname === "content") {
var contenteditor = ue.geteditor('content');
var filtertypostaghtml = filtertypostag(contenteditor.getcontent());
if (filtertypostaghtml) {
contenteditor.setcontent(filtertypostaghtml);
}
}
});
}
};
pe.ui.ajaxform = {
preventrepeter: function () {
$("button[data-loading-text]").button('loading');
},
onerror: function (xhr, statuscode, errordown) {
$('button[data-loading-text]').button('reset');
try {
eval(xhr.responsetext);
} catch (e) {
new pe.ui.message('服务器端出现异常', 'error');
}
},
onsuccess: function (data, e) {
settimeout(function () {
$('button[data-loading-text]').button('reset');
},
1000);
}
};
});