/// /** * 此文件的头部注释 */ /*global jquery: false */ (function ($) { 'use strict'; $(function () { var $inputs = $('input[type="text"]:enabled:visible'); //去除文本框的拼写检查 $('input[type="text"], textarea').attr('spellcheck', 'false'); //自动获取每个页面第一个输入文本框的焦点 if ($inputs.length > 0) { $inputs.first().focus(); } //设置是否允许用户激活输入中文,韩文,日文等的输入法(ime)状态 //ie、firefox浏览器支持该ime-mode属性,chrome、opera、safari浏览器不支持。 $('input[data-ui-ime="inactive"]').css('ime-mode', 'inactive'); $.scojs_tooltip("i[data-trigger=tooltip]", { position: "ne", delay: 0 }); var $body = $("body"); if (typeof (signalr) != "undefined") { var connection = new signalr.hubconnectionbuilder().withurl("/signalrmobileuploadhub").withautomaticreconnect().build(); connection.on("getmobileuploadurl", function (imageuploadtoken, mobileuploadresult) { $body.trigger('power.mobilefileuploaded', [imageuploadtoken, mobileuploadresult]); }); connection.start().catch(function (err) { return console.error(err.tostring()); }); } // 初始化控件 pe.ui.initcontrols(); }); pe.ui.initcontrols = function ($controls) { if (!$controls) { $controls = $('[data-ui-type]'); } function rendertree(selector, setting) { /// /// 渲染tree控件 /// /// tree参数 /// 选择tree控件的选择器 /// ztreeobj var url = '', $tree = $(selector); if ($tree.attr('data-tree-url')) { url = $tree.attr('data-tree-url'); } if (url !== '' || $tree.attr('data-tree-datasource') != '[]') { var tree = new pe.ui.tree($tree.attr('id'), { keyid: $tree.attr('data-tree-keyid'), url: url, async: { type: $tree.attr('data-tree-type') }, check: { enable: $tree.attr('data-tree-hascheckbox') == 'true' ? true : false }, data: { key: $.parsejson($tree.attr('data-tree-keyparams')) } }); $('form') .submit(function () { var treeselect = new pe.ui.treeselect(tree); if ($tree.attr('data-tree-hascheckbox') === 'true') { treeselect.bindcollection($tree, $tree.attr('data-tree-propertyname'), $tree.attr('data-tree-keyid')); } else { treeselect.bindproperty($tree, $tree.attr('data-tree-propertyname')); } }); } return $.fn.ztree.getztreeobj($tree.attr('id')); } /** * 过滤控件 * @param {string} type - 对应的控件类型 * @return {jquery} */ function filtercontrols(type) { return $controls.filter('[data-ui-type=' + type + ']'); } function numerictextbox(elem) { var that = elem, elemtemplate = '', $input = elem.find('input'), unit = $input.attr('data-ui-spinner-unit'), value = $input.val(), displayelement = $(elemtemplate.replace(/\{\$value\}/gi, value + ' ' + unit)) .attr('style', $input.attr('style')) .addclass('form-control ' + $input.attr('css')) .show(); $input.hide().before(displayelement); function setvalue() { if ($input.val()) { value = $input.val() + ' ' + unit; displayelement.val(value); //displayelement.show(); //$input.hide(); } } displayelement.focus(function (event) { displayelement.hide(); $input.show(); $input.focus(); if (/msie/.test(navigator.useragent.tolowercase())) { var r = $input[0].createtextrange(); r.collapse(false); r.select(); } else if (/firefox/.test(navigator.useragent.tolowercase())) { $input[0].setselectionrange($input.val().length, $input.val().length); } }); $input.on('blur change', function (event) { setvalue(); $input.hide(); displayelement.show(); }); elem.on('click', '.spinbox-down,.spinbox-up', function () { setvalue(); //$input.show(); //displayelement.hide(); }); // .on('mouseleave', '.spinbox-down,.spinbox-up', function () { // setvalue(); // $input.hide(); // displayelement.show(); //}); if ($input.closest('[data-ui-type]').attr('data-ui-type') === 'spinner') { // displayelement.addclass('ui-spinner-input'); elem.on('changed.fu.spinbox', function (event, ui) { setvalue(); $input.hide(); displayelement.show(); if ($['validator'] && $['validator']['methods']) { $input.valid(); } }); } } filtercontrols('datepicker') .each(function () { var $this = $(this), setting = $.extend({ language: 'zh-cn', autoclose: true, format: 'yyyy-mm-dd', minview: 2 }, $this.data()); if ($this.attr('disabled') !== 'disabled') { $this.datetimepicker(setting); } $this.on('disable.power', function () { $this.datetimepicker('remove'); }); $this.on('enable.power', function () { $this.datetimepicker(setting); }); }); filtercontrols('datetimepicker') .each(function () { var $this = $(this), setting = $.extend({ language: 'zh-cn', autoclose: true, format: 'yyyy-mm-dd hh:ii', minview: 0 }, $this.data()); if ($this.attr('disabled') !== 'disabled') { $this.datetimepicker(setting); } $this.on('disable.power', function () { $this.datetimepicker('remove'); }); $this.on('enable.power', function () { $this.datetimepicker(setting); }); }); filtercontrols('timepicker') .each(function () { var $this = $(this), setting = $.extend({ language: 'zh-cn', autoclose: true, format: 'hh:ii', minview: 0, startview: 0 }, $this.data()); if ($this.attr('disabled') !== 'disabled') { $this.datetimepicker(setting); } $this.on('disable.power', function () { $this.datetimepicker('remove'); }); $this.on('enable.power', function () { $this.datetimepicker(setting); }); }); filtercontrols('radiobuttonlist') .each(function () { var $this = $(this); var $input = $this.find('input[type="radio"]'); if ($this.attr('disabled') === 'disabled') { $input.attr('disabled', 'disabled'); } $this.on('disable.power', function () { $input.attr('disabled', 'disabled'); }); $this.on('enable.power', function () { $input.removeattr('disabled'); }); $this.data('original', $this.find(':radio:checked').val()); $this.parents('form') .on('reset', function (e) { var originalvalue = $this.data('original'); if (originalvalue) { $this.find(':radio[value=' + originalvalue + ']').icheck('check'); } else { $this.find(':radio:checked').icheck('uncheck'); } }); }); filtercontrols('checkboxlist') .each(function () { var $this = $(this); var $input = $this.find('input[type="checkbox"]'); if ($this.attr('disabled') === 'disabled') { $input.attr('disabled', 'disabled'); } }); filtercontrols('spinner') .each(function () { var $this = $(this), $input = $this.find('input'); $this.off('fu.data-api'); if ($input.attr('data-ui-spinner-unit')) { numerictextbox($this); } // $this.spinner(); if ($this.attr('disabled') === 'disabled') { $this.spinbox('disable'); } $this.on('enable.power', function () { $this.spinbox('enable'); }); $this.on('disable.power', function () { $this.spinbox('disable'); }); }); // viewpath 用的是ztree插件,可选择百度其api // ----------------------------- var viewchosenpickertemplate = ''; var viewchosen = function (element) { var $this = $(element), vc = this, pickerid = '', option = $this.data(); this.urlpath = option.urlpath; this.inputter = $this.find('input'); this.dirtyvalue = ''; pickerid = this.pickerid = this.inputter.prop('id') + '-picker'; this.chosen = $this.find('.viewchosen-chosen').attr('data-target', '#' + pickerid); this.editor = $this.find('.viewchosen-editor'); this.picker = $(viewchosenpickertemplate).prop('id', pickerid).appendto('body'); this.viewpath = this.inputter.val(); this.edtiorpath = this.editor.prop('href'); this.seteditorpath(); this.pathtree = null; this.initpicker(); this.search(); this.searchoff(); this.inputlisten(); this.refreshclick(this); //this.chosen.on('click',$.proxy(this,showpicker)); this.picker.on('click', '.viewchosen-ok', $.proxy(this, 'setpath')); this.picker.on('show.bs.modal', $.proxy(this, 'selectnode')); }; viewchosen.prototype = { setpath: function () { if (this.dirtyvalue) { this.viewpath = this.dirtyvalue; this.dirtyvalue = ''; this.inputter.val(this.viewpath); this.inputter.trigger('change'); this.editor.prop('href', pe.tools.connecturl(this.edtiorpath, { 'filepath': this.viewpath })); } }, seteditorpath: function () { this.editor.prop('href', pe.tools.connecturl(this.edtiorpath, { 'filepath': this.viewpath })); }, initpicker: function () { var self = this, inputterval = this.inputter.val(), treesetting = { view: { selectedmulti: false, nameishtml: true }, data: { key: { name: 'viewpathname', title: '', url: 'url', children: 'folderviewmodels', checked: 'checked' }, simpledata: { enable: true } }, callback: { onclick: $.proxy(self, 'nodeselect') } }; $.ajax({ url: this.urlpath, data: { 'viewpathdir': self.inputter.val() }, type: "post", datatype: 'json', async: false, success: function (serverdata) { self.pathtree = $.fn.ztree.init(self.picker.find(".viewpathtreenode") .attr('id', self.pickerid + '-' + 'tree'), treesetting, serverdata); self.selectnode(); } }); }, refreshclick: function (self) { $(self.picker.find('.refreshclick')) .on('click', function () { self.initpicker(); }); }, search: function () { $('.searchoff').hide(); var self = this; // 搜索。 $('.search') .on('click', function () { var treeid = self.pickerid + '-' + 'tree'; var $tree = $.fn.ztree.getztreeobj(treeid); // 获取当前搜索文本框的值。 var searchkeyvalue = this.parentelement.childnodes[1]; searchkeyvalue = searchkeyvalue.value; var nodes = $tree.transformtoarray($tree.getnodes()); // 去除关键词样式,避免样式重叠。 $.each(nodes, function (k, v) { v.viewpathname = v.viewpathname.replace('', ''); v.viewpathname = v.viewpathname.replace('', ''); $tree.updatenode(v); }); // 对ztree的模糊查找。 var nodelist = $tree.getnodesbyparamfuzzy("viewpathname", searchkeyvalue); // 判断搜索关键词是否为空。 if (searchkeyvalue.trim() === "") { $('.search').show(); $('.searchoff').hide(); // 显示所有节点。 $tree.shownodes(nodes); return; } $('.search').hide(); $('.searchoff').show(); $tree.hidenodes(nodes); var filternodes = []; for (var i = 0; i < nodelist.length; i++) { filternodes.push(nodelist[i]); } //寻找当前节点的父节点方法。 function findparent(ztree, node) { ztree.expandnode(node, true, false, false); var pnode = node.getparentnode(); ztree.shownode(pnode); if (pnode != null) { filternodes.push(pnode); findparent(ztree, pnode); } } for (var i = 0; i < filternodes.length; i++) { findparent($tree, filternodes[i]); } $tree.shownodes(filternodes); // 为搜索关键词添加样式。 if (searchkeyvalue) { $.each(nodes, function (k, v) { var start = v.viewpathname.tolowercase().indexof(searchkeyvalue.tolowercase()); var end = start + searchkeyvalue.length; var keyvalue = v.viewpathname.substring(start, end); if (start > -1) { v.viewpathname = v.viewpathname .replace(keyvalue, '' + keyvalue + ''); $tree.updatenode(v); } }); } }); }, searchoff: function () { // 取消搜索按钮。 $('.searchoff') .on('click', function () { $('.input-search').val(''); $('.input-search').focus(); $('.search').click(); }); }, inputlisten: function () { var time; // 搜索框keyup。 $('.input-search') .bind('input propertychange keyup', function (event) { cleartimeout(time); if (event.keycode == 13) { // 获取当前搜索按钮。 var searchbutton = this.parentelement.childnodes[3]; searchbutton.click(); return; } time = settimeout(function () { $('.search').click(); }, 1100); }); }, selectnode: function () { var inputterval = this.inputter.val(); var node = this.pathtree.getnodebyparam("viewpathdir", inputterval); if (node) { this.pathtree.setting.view.expandspeed = ""; this.pathtree.expandall(false); this.pathtree.setting.view.expandspeed = "fast"; this.pathtree.selectnode(node); } else { this.pathtree.cancelselectednode(); this.pathtree.expandall(false); var nodes = this.pathtree.getnodes(); this.pathtree.expandnode(nodes[0], true, true, true); } }, nodeselect: function (event, treeid, treenode) { if (treenode.viewpathdirtype == "0") { this.dirtyvalue = treenode.viewpathdir; } } }; var viewpathchecker = function (url, inputter) { this.url = url; this.feedback = inputter.next('.form-control-feedback'); this.inputter = inputter; inputter.on('change', $.proxy(this, 'check')); this.check(); }; viewpathchecker.prototype = { check: function () { var value = this.inputter.val().trim(); this.feedback.prop('title', ''); if (!value) { this.feedback.removeclass('glyphicon-warning-sign glyphicon-time'); return; }; this.feedback.removeclass('glyphicon-warning-sign'); this.feedback.addclass('glyphicon-time'); $.get(this.url, { path: value }, $.proxy(this, 'showresult'), 'json'); }, showresult: function (data) { if (data.result) { this.showsuccess(); } else { this.showerror(data); } }, showsuccess: function () { this.feedback.removeclass('glyphicon-time'); // this.feedback.addclass('glyphicon-ok'); }, showerror: function (data) { this.feedback.removeclass('glyphicon-time'); this.feedback.prop('title', data.message); this.feedback.addclass('glyphicon-warning-sign'); } }; filtercontrols("viewpath") .each(function () { var $this = $(this), $inputter = $this.find('input'), checker = new viewpathchecker($this.data().checkpath, $inputter), $chose = $this.find('button.viewchosen-chosen'), $editor = $this.find('a'); $editor.popover({ placement: 'top', trigger: 'focus', content: '请先选择模板!' }); $editor.on('show.bs.popover', function () { if ($inputter.val()) { return false; } }); $editor.on('click', function () { if (!$inputter.val()) { return false; } }); new viewchosen(this); $this.data('viewpathchecker', checker); $this.parents('.form-group').addclass('has-feedback control-viewpath'); $this.on("disable.power", function () { $inputter.attr("disabled", "disabled"); $chose.attr("disabled", "disabled"); $editor.attr("disabled", "disabled"); }); $this.on("enable.power", function () { $inputter.removeattr("disabled"); $chose.removeattr("disabled"); $editor.removeattr("disabled"); }); }); filtercontrols("textbox") .each(function () { var $this = $(this); $this.on("disable.power", function () { $this.attr("disabled", "disabled"); }); $this.on("enable.power", function () { $this.removeattr("disabled"); }); }); filtercontrols("theme") .each(function () { var $theme = $(this); $(this) .on('click', '.color-theme', function () { if ($(this).hasclass('selected')) { $(this).find('input[type="radio"]').prop('checked', false); $(this).removeclass('selected'); } else { $theme.find('.color-theme').removeclass('selected'); $theme.find('input[type="radio"]').prop('checked', false); $(this).addclass('selected'); $(this).find('input[type="radio"]').prop('checked', true); } }); }); filtercontrols('combobox') .each(function () { var $this = $(this), setting = $.extend({ inputname: $this.attr('data-name') }, $this.data()); if ($this.attr('disabled') != 'disabled') { $this.find('select').combobox(setting); } else { $this.find('select').remove(); } $(this) .on("disable.power", function () { $this.find('input').attr("disabled", "disabled"); $this.find('button').attr("disabled", "disabled"); }); $(this) .on("enable.power", function () { $this.find('input').removeattr("disabled"); $this.find('button').removeattr("disabled"); }); }); // bytesbox // ----------------------------- (function () { var symbols = ['b', 'k', 'm', 'g', 't', 'p', 'e', 'z', 'y', 'd', 'n']; function getlog(value) { return math.floor(math.log(value) / math.log(1024)); } function convertor(value, symbol, target) { var log = 0, isinteger = /^[1-9]+[0-9]*]*$/, result = value, targetindex = -1, index = -1; if (!symbol) { symbol = 'b'; } if (value <= 0) { return { value: value, symbol: target || symbol }; } if (target) { for (var i = 0; i < symbols.length; i++) { if (symbols[i] === symbol) { index = i; } if (symbols[i] === target) { targetindex = i; } } log = targetindex - index; } else { log = getlog(value); } if (result >= 1024 || result < 1 || target) { result = result * math.pow(1024, log * -1); } if (index < 0) { for (var i = 0; i < symbols.length; i++) { if (symbol === symbols[i]) { index = i; break; } } }; if (!isinteger.test(result)) { result = number(result.tofixed(2)); } return { value: result, symbol: symbols[index + log] }; } var bytesbox = function (element, options) { var $element = $(element), self = this, $input = this.$input = $element.find('input[type="text"]'), $symbole = this.$symbole = $element.find('.bytesbox-symbole'), settings = this.settings = $element.data(); this.symbol = 'b'; this.value = $input.val(); this.displayvalue = this.value; $input.on('change', $.proxy(self.smartconvert, self)); $element.on('click', '[data-symbol]', $.proxy(this.setsymbol, this)); if (this.value) { this.convertvalue((this.settings.unit)[0].tolowercase()); } $element.closest('form') .on('submit', function () { $input.val(self.value); $symbole.html('b '); settimeout(function () { self.convertvalue(self.symbol); }, 300); }) .on('reset', function () { $symbole.html('b '); settimeout(function () { self.value = $input.val(); self.convertvalue(self.symbol); }, 200); }); $element.on("disable.power", function () { $input.prop("disabled", true); $symbole.prop("disabled", true); }); $element.on("enable.power", function () { $input.prop("disabled", false); $symbole.prop("disabled", false); }); }; bytesbox.prototype = { smartconvert: function (argument) { var value = this.$input.val(), char = '', matchregex = /[b,k,m,g,t]/i; if (!$.isnumeric(value)) { char = value.replace(/\d+/, ''); if (char && char.length == 1 && matchregex.test(char)) { value = /\d+/.exec(value); this.symbol = char; } else { this.$input.val(0); return; } } if (value) { if (this.symbol !== 'b') { this.value = convertor(value, this.symbol, 'b').value; } else { this.value = value; } } //this.convertvalue(); }, convertvalue: function (symbole) { var data = convertor(this.value, 'b', symbole); this.$input.val(data.value); this.$symbole.html(data.symbol.touppercase() + (data.symbol === 'b' ? '' : 'b') + ' '); this.symbol = data.symbol; }, setsymbol: function (e) { var $this = $(e.target), targetsymbol = $this.data().symbol; this.convertvalue(targetsymbol); } }; filtercontrols('bytesbox') .each(function (i, n) { $(n).data('bytesbox', new bytesbox(n)); }); })(); filtercontrols('treemutlipleselect') .each(function () { var $this = $(this), $tree = $this.find('.ztree'), tree = rendertree($tree), selectednodes = [], label = $this.find('.dropdown-label'), values = [], title = []; if ($this.attr('disabled') === 'disabled') { $this.on('shown.bs.dropdown', function (e) { $this.removeclass('open'); }); } $this.on('enable.power', function () { $this.removeattr('disabled'); $this.unbind('shown.bs.dropdown'); }); $this.on('disable.power', function () { $this.attr('disabled', 'disabled'); $this.on('shown.bs.dropdown', function (e) { $this.removeclass('open'); }); }); function expandnode(node) { var parentnode = node.getparentnode(); if (parentnode) { tree.expandnode(parentnode, true, false); expandnode(node.getparentnode()); } } function setlabel() { if (tree) { selectednodes = tree.getcheckednodes(true); } title.length = 0; values.length = 0; if (selectednodes.length < 1) { title.push('请选择'); } $.each(selectednodes, function (i, n) { title.push(n['name']); values.push(n['treeparentnodeid']); expandnode(n); }); if (title.length > 0) { label.text(title.join(',')); $tree.data('values', values); } }; setlabel(); $this.data('original', selectednodes); $this.parents('form') .on('reset', function (e) { var nodes = $this.data('original'); $.each(tree.getcheckednodes(true), function (k, v) { tree.checknode(v, false, false); }); if (nodes.length < 1) { tree.expandall(false); } else { tree.setting.view.expandspeed = ""; tree.expandall(false); tree.setting.view.expandspeed = "fast"; var keyid = nodes[0]['treeparentnodeid'] ? 'treeparentnodeid' : 'treesetnodeid'; $.each(nodes, function (k, v) { var node = tree.getnodebyparam(keyid, v[keyid]); tree.checknode(node, true, false); }); } setlabel(); }); $tree.on('click', function (e) { return false; }); $tree.on('treeselect', function (e, treeid, treenode) { setlabel(); }); }); filtercontrols('treeselect') .each(function () { var $this = $(this), $tree = $this.find('.ztree'), tree = rendertree($tree); if ($this.attr('disabled') === 'disabled') { $this.on('shown.bs.dropdown', function (e) { $this.removeclass('open'); }); } $this.on('enable.power', function () { $this.removeattr('disabled'); $this.unbind('shown.bs.dropdown'); }); $this.on('disable.power', function () { $this.attr('disabled', 'disabled'); $this.on('shown.bs.dropdown', function (e) { $this.removeclass('open'); }); }); function expandnode(node) { if (node.getparentnode() != null) { tree.expandnode(node.getparentnode(), true, false); expandnode(node.getparentnode()); } } var selectednodes = []; if (tree) { selectednodes = tree.getselectednodes(); } var label = $this.find('.dropdown-label'); var deselect = $this.find('.deselect'); if (selectednodes[0]) { var parentnode = selectednodes[0].getparentnode(); var stringpath = selectednodes[0]['name']; var ismultiple = $('.selectednodename').data('type'); if (ismultiple === "multiple") { label.text("更换"); while (parentnode != null) { stringpath = parentnode['name'] + ' >> ' + stringpath; parentnode = parentnode.getparentnode(); } } else { label.text(selectednodes[0]['name']); } $('.selectednodename').val(stringpath); var nodeid = selectednodes[0].treeparentnodeid; $('.selectednodename').data('val', nodeid); expandnode(selectednodes[0]); $this.data('original', selectednodes[0]); } deselect.on('click', resetfun); function resetfun() { var node = $this.data('original'); if (node) { tree.setting.view.expandspeed = ""; tree.expandall(false); tree.setting.view.expandspeed = "fast"; var keyid = node['treeparentnodeid'] ? 'treeparentnodeid' : 'treesetnodeid'; var originalnode = tree.getnodebyparam(keyid, node[keyid]); tree.selectnode(originalnode); expandnode(originalnode); label.text(originalnode['name']); } else { label.text('请选择'); if (tree) { tree.cancelselectednode(); tree.expandall(false); } } deselect.hide(); } $this.parents('form').on('reset', resetfun); var $setnodesshow = $("#setnodesshow"); function setnodes(v, nodename) { if (nodename) { nodename = nodename + " >> " + v.name; } else { nodename = v.name; } if (v.checked) { $setnodesshow .append("
  • " + "
    " + "
    " + "" + "
    " + "  " + "
  • "); // 禁用另一棵树节点。 var nodetree = $.fn.ztree.getztreeobj("nodeid"); var node = nodetree.getnodebyparam("treeparentnodeid", v.treeparentnodeid, null); node.enable = false; } if (v.children) { $.each(v.children, function (i, sv) { setnodes(sv, nodename); }); } } function setcheck(v, ids, moldname, p) { if (!v.checked && label.text() != v.name) { v.chkdisabled = false; } if (v.disabledclick || v.checked || (moldname && v.moldname != moldname)) { v.checked = false; v.enable = false; v.chkdisabled = true; } if (ids) { $.each(ids, function (id_i, id_v) { if (id_v && v.treeparentnodeid == id_v && !v.disabledclick) { v.checked = true; v.enable = true; v.disabledclick = false; v.chkdisabled = false; if (p) { p.open = true; } } }); } if (v.children) { v.open = false; $.each(v.children, function (i, sv) { setcheck(sv, ids, moldname, v); }); } } function removenodetagevt() { removenodetag($(this).parent().parent()[0]); } function removenodetag(li) { if (li) { var id = $(li).find("input:eq(1)").val(); var tid = li.id.replace("li", ""); $.get($("#checkdeleteurl").val(), { nodeid: id, contentid: $("#contentid").val() }, function (result) { if (result == "true") { li.remove(); var sendtree = $.fn.ztree.getztreeobj("sendnodetree"); var node = sendtree.getnodebytid(tid); if (node != null) { node.checked = false; sendtree.updatenode(node, true); } // 启用另一棵树节点。 var nodetree = $.fn.ztree.getztreeobj("nodeid"); var nodeobj = nodetree.getnodebyparam("treeparentnodeid", id, null); nodeobj.enable = true; } else { new window.top.pe.ui.message('删除失败,您不具备该节点的删除权限。', 'error'); } }); } } function removenodetags() { var lis = $setnodesshow.find("li"); $.each(lis, function (i, v) { removenodetag(v); }); } function init(moldname) { if ($("#sendnode").length > 0) { var nodetree = $.fn.ztree.getztreeobj("nodeid"), datasource = nodetree.getnodes(), getnodeids = $("#getnodeids").val(), ids; if (getnodeids) { ids = getnodeids.split(","); } if (!moldname) { var curid = "nodeid_" + $("#nodeid .curselectednode").attr("id").split("_")[1]; var curnode = nodetree.getnodebytid(curid); if (curnode) { moldname = curnode.moldname; } } $.each(datasource, function (i, v) { setcheck(v, ids, moldname); }); $setnodesshow.css("padding", "0"); $.each(datasource, function (i, v) { setnodes(v); }); if ($setnodesshow.find("li").length === 0) { $setnodesshow.css("padding", "0"); } var sendnodesetting = { async: { enable: true, autoparam: ["treeparentnodeid=nodeid"], type: "post" }, check: { enable: true, chkboxtype: { "y": "", "n": "" } }, view: { nameishtml: true }, data: { keep: { parent: true }, key: { name: 'name', title: '', children: 'children', checked: 'checked' }, simpledata: { enable: true, idkey: 'treeparentnodeid', pidkey: 'parentid' } }, callback: { beforecheck: function (treeid, treenode) { if (treenode.checked) { var ajax = $.ajax({ url: $("#checkdeleteurl").val(), data: { nodeid: treenode.treeparentnodeid, contentid: $("#contentid").val() }, async: false }); if ("false" == ajax.responsetext) { new window.top.pe.ui.message('删除失败,您不具备该节点的删除权限。', 'error'); return false; } } else { var edit = $.ajax({ url: $("#checkediturl").val(), data: { nodeid: treenode.treeparentnodeid }, async: false }); if ("false" == edit.responsetext) { new window.top.pe.ui.message('操作失败,您不具备目标节点的编辑权限。', 'error'); return false; } } }, oncheck: function (e, treeid, treenode) { $setnodesshow.css("padding", "0"); $setnodesshow.find("li").remove(); var datasource = $.fn.ztree.getztreeobj("sendnodetree").getnodes(); $.each(datasource, function (i, v) { setnodes(v); }); $setnodesshow.find(".removenode").on("click", removenodetagevt); if ($setnodesshow.find("li").length == 0) { $setnodesshow.css("padding", "0"); } } } }; $.fn.ztree.init($("#sendnodetree"), sendnodesetting, datasource); if (ids) { $setnodesshow.find(".removenode").on("click", removenodetagevt); } if (!moldname) { removenodetags(); } } }; init(); $tree.on('treeselect', function (e, treeid, treenode) { if (typeof (treenode.enable) != "undefined" && !treenode.enable) { return false; } $tree.data('nodename', label.text()); //修改页 // 另一棵树取消之前的选中。 var nodetree = $.fn.ztree.getztreeobj("sendnodetree"); if (nodetree != null) { var preselectnode = $('.selectednodename').data('val'); var prenode = nodetree.getnodebyparam("treeparentnodeid", preselectnode, null); nodetree.setchkdisabled(prenode, false); } // var parentnode = treenode.getparentnode(); var stringpath = treenode['name']; var ismultiple = $('.selectednodename').data('type'); if (ismultiple === "multiple") { label.text("更换"); while (parentnode != null) { stringpath = parentnode['name'] + ' >> ' + stringpath; parentnode = parentnode.getparentnode(); } } else { label.text(treenode['name']); deselect.show(); } $('.selectednodename').val(stringpath); $('.selectednodename').data('val', treenode['treeparentnodeid']); // 另一棵树对应节点设置选中。 if (nodetree != null) { var node = nodetree.getnodebyparam("treeparentnodeid", treenode['treeparentnodeid'], null); nodetree.setchkdisabled(node, true); } $this.removeclass('open'); if ($("#sendnode").length > 0) { //init(treenode.moldname); } } ); $tree.on('click', function (e) { return false; }); }); filtercontrols('checkboxlist') .each(function () { var $this = $(this), $checkboxs = $this.find('input:checkbox'), propertyname = $checkboxs.first().attr('name'), fieldname = $this.data().field, $hiddens = $('
    ').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); } }; });