| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- $(document).ready(function() {
-
- space.ueditor.toolbar.init.myFace();// 初始化,自定义百度编辑器的《表情》工具按钮
- space.ueditor.toolbar.init.commonLanguage();// 初始化,自定义百度编辑器的《常用语》工具按钮
- space.ueditor.toolbar.init.cmsFileSystem();// 初始化,自定义百度编辑器的《附件》工具按钮
-
- });
- space.ueditor = {
- toolbar: {}
- }
- space.ueditor.toolbar = {
- /**
- * 模板
- */
- template: {
- // 气泡模板
- airbubbles: '<div id="{airbubbles}" class="bubble-layer" style="left: 300px; top: 100px;"><div class="bubble-layer-content"></div><div class="bubble-layer-arrows"></div></div>',
- // 微标
- badge: '<span id="{badge}" class="fileDot"></span>',
- },
- /**
- * 关闭所有弹层
- */
- closeAllBubbleLayer: function() {
- $(".bubble-layer").fadeOut(100);
- },
- /**
- * 注册按钮事件
- * @param {Object} btnId
- * @param {Object} callback
- */
- regClickDocument: function(btnId, callback) {
- // 全局注册点击事件
- document.onclick = function(e) {
- var len = $(e.target).parents("div[id='" + btnId + "']").length;
- if(e.target.id != btnId && len == 0) {
- space.ueditor.toolbar.closeAllBubbleLayer();
- }
- if(callback) {
- callback(e)
- }
- }
- },
- /**
- * 追加内容
- * @param {Object} elId 元素 id
- * @param {Object} html 内容
- */
- appendHtml: function(elId, html) {
- $("#" + elId).find('.bubble-layer-content').append(html);
- },
- editorAppendHtml: function(editor, html) {
- editor.execCommand('inserthtml', html);
- },
- /**
- * 重置气泡大小
- */
- resetAirbubblesSize: function(editor, btn, id) {
-
- // 编辑器的坐标
- var ediOffSet = $(editor.iframe).parent().offset();
- // 初始化坐标
- var btnOffSet = $(btn.target).offset();
- var airbubblesLeft = 0;// 气泡窗口,左边距离
- var arrowsLeft = 30;// 三角箭头
- var btnLeft = (btnOffSet.left - 26);
- // 计算左边的距离
- if (ediOffSet.left <= 0 && btnLeft < ediOffSet.left) {
- airbubblesLeft = btnOffSet.left;
- arrowsLeft = btnOffSet.left - 4;
- }
- else {
- airbubblesLeft = btnLeft;
- }
-
- var airbubblesTop = (btnOffSet.top - $(id).height() - 16);
- var airbubblesHeight = 112;
- // 计算高度
- if (airbubblesHeight > airbubblesTop) {
- airbubblesHeight = airbubblesHeight - (airbubblesHeight - btnOffSet.top + 16)
- }
-
- if (airbubblesTop < 0) {
- airbubblesTop = 0;
- }
-
- // 气泡窗口
- $(id).css({
- "top": airbubblesTop + "px",
- "left": airbubblesLeft + "px",
- "height": airbubblesHeight + "px",
- });
-
- // 三角箭头
- $(id).find('.bubble-layer-arrows').css({
- "left": arrowsLeft + "px"
- })
-
- },
- init: {
- /**
- * 表情
- */
- myFace: function() {
- var id = space.utils.randomString(8);
- $('body').append(space.ueditor.toolbar.template.airbubbles.replace("{airbubbles}", id));
- $("#" + id).css({
- 'width': '300px',
- 'height': '112px'
- });
- for(var i = 1; i <= 32; i++) {
- var html = '<img class="face-img" src="/apps/space/images/ueditor/faces/FACE_' + i + '.png">';
- space.ueditor.toolbar.appendHtml(id, html);
- }
- space.plugins.ueditor.registerUeditorToolBar.button({
- title: '表情',
- uiName: 'myFace',
- icon: '/apps/space/images/ueditor/MyFace.png',
- click: function(editor, btn, param) {
- space.ueditor.toolbar.closeAllBubbleLayer();
- var id = "#" + param.id;
- // 如果已经显示了,再次点击就隐藏掉
- if(!$(id).is(':hidden')) {
- return;
- }
-
- space.ueditor.toolbar.resetAirbubblesSize(editor, btn, id);
-
- $(id).fadeIn(200);
- space.ueditor.toolbar.regClickDocument(btn.id, function(e) {
- if(e.target.nodeName == "IMG" && $(e.target).parents("div[id='" + param.id + "']").length == 1) {
- space.ueditor.toolbar.editorAppendHtml(editor, "<img width='26px' src='" + $(e.target).attr("src") + "' />");
- }
- });
- },
- param: {
- id: id
- }
- })
- },
- /**
- * 常用语
- */
- commonLanguage: function() {
-
- var id = space.utils.randomString(8);
- $('body').append(space.ueditor.toolbar.template.airbubbles.replace("{airbubbles}", id));
- $("#" + id).css({
- 'width': '300px',
- 'height': '112px'
- });
-
- $.ajax({
- type: "get",
- url: "/apps?ark=personCustomPhrase_list&app=personnel",
- async: false,
- dataType: 'json',
- success: function(data) {
-
- if(data.code == 'success') {
-
- var list = data.personCustomPhraseList;
- if(!list || list.length == 0) {
- var noDataHtml = '<div style="width:100%;height:100%;color:#999;text-align:center;line-height:110px;cursor: default;"><i class="el-icon-warning-outline"></i> 未设置常用语</div>';
- space.ueditor.toolbar.appendHtml(id, noDataHtml);
- return;
- }
- var html = '<ul class="ul-list">';
- for (var i = 0;i < list.length;i++) {
- html += '<li>' + list[i].content + '</li>';
- }
- html += '</ul>';
- space.ueditor.toolbar.appendHtml(id, html);
- }
-
- }
- });
-
- space.plugins.ueditor.registerUeditorToolBar.button({
- title: '常用语',
- uiName: 'commonLanguage',
- icon: '/apps/space/images/ueditor/CommonLanuage.png',
- click: function(editor, btn, param) {
- space.ueditor.toolbar.closeAllBubbleLayer();
- var id = "#" + param.id;
- // 如果已经显示了,再次点击就隐藏掉
- if(!$("#" + param.id).is(':hidden')) {
- return;
- }
-
- space.ueditor.toolbar.resetAirbubblesSize(editor, btn, id);
-
- $(id).fadeIn(200);
- space.ueditor.toolbar.regClickDocument(btn.id, function(e) {
- if(e.target.nodeName == "LI" && $(e.target).parents("div[id='" + param.id + "']").length == 1 &&
- $(e.target).parent("ul.ul-list").length == 1) {
- // 插入内容
- space.ueditor.toolbar.editorAppendHtml(editor, e.target.innerText);
- }
- });
- },
- param: {
- id: id
- }
-
- });
- },
- /**
- * 附件
- */
- cmsFileSystem: function() {
-
- var id = space.utils.randomString(8);
- $('body').append(space.ueditor.toolbar.template.badge.replace("{badge}", id));
-
- space.plugins.ueditor.registerUeditorToolBar.button({
- title: '附件',
- uiName: 'cmsFileSystem',
- icon: '/apps/space/images/ueditor/CmsFileSystem.png',
- ready: function(editor, btn) {
- $("#" + id).on('click', function() {
- $(btn).click();
- });
- },
- click: function(editor, btn, param) {
-
- // 初始化《附件》的 CMS 参数
- editor.CMS.CMS_badge = param.id;
-
- var winSetting = {"title": "附件", "width": "90%", "height": "90%", "url": "/apps?app=sys&destination=sys.cms.uploading"};
- // 打开 CMS 上传文件的窗口
- space.plugins.layer.openPredefinePage(winSetting, {
- success: function(win) {
- win.CMS = {
- id: editor.CMS.childID
- }
- },
- end: function() {
- if (!window.CMS) {
- return
- }
-
- var badgeId = "#" + editor.CMS.CMS_badge;// 当前插件在工具类的 id
- var fileCount = window.CMS.fileCount;// 已上传的附件数量
- editor.CMS.childID = window.CMS.id;
-
- var btnOffSet = $(btn.target).offset();
- $(badgeId).css({
- "top": (btnOffSet.top - $(badgeId).height() + 12) + "px",
- "left": (btnOffSet.left + 16) + "px",
- });
-
- $(badgeId).text(fileCount);
- $(badgeId).show();
-
- }
- });
-
- },
- param: {
- id: id,
- }
- });
-
- }
- }
- }
|