地质所 沉降监测网建设项目
chenhuan
2024-05-16 0fdd42e318f51f9e3c6581473416af1cca69877f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*!
 * HTML entities dialog plugin for Editor.md
 *
 * @file        html-entities-dialog.js
 * @author      pandao
 * @version     1.2.0
 * @updateTime  2015-03-08
 * {@link       https://github.com/pandao/editor.md}
 * @license     MIT
 */
 
(function() {
 
    var factory = function (exports) {
 
        var $            = jQuery;
        var pluginName   = "html-entities-dialog";
        var selecteds    = [];
        var entitiesData = [];
 
        exports.fn.htmlEntitiesDialog = function() {
            var _this       = this;
            var cm          = this.cm;
            var lang        = _this.lang;
            var settings    = _this.settings;
            var path        = settings.pluginPath + pluginName + "/";
            var editor      = this.editor;
            var cursor      = cm.getCursor();
            var selection   = cm.getSelection();
            var classPrefix = _this.classPrefix;
 
            var dialogName  = classPrefix + "dialog-" + pluginName, dialog;
            var dialogLang  = lang.dialog.htmlEntities;
 
            var dialogContent = [
                '<div class="' + classPrefix + 'html-entities-box" style=\"width: 760px;height: 334px;margin-bottom: 8px;overflow: hidden;overflow-y: auto;\">',
                '<div class="' + classPrefix + 'grid-table">',
                '</div>',
                '</div>',
            ].join("\r\n");
 
            cm.focus();
 
            if (editor.find("." + dialogName).length > 0) 
            {
                dialog = editor.find("." + dialogName);
 
                selecteds = [];
                dialog.find("a").removeClass("selected");
 
                this.dialogShowMask(dialog);
                this.dialogLockScreen();
                dialog.show();
            } 
            else
            {
                dialog = this.createDialog({
                    name       : dialogName,
                    title      : dialogLang.title,
                    width      : 800,
                    height     : 475,
                    mask       : settings.dialogShowMask,
                    drag       : settings.dialogDraggable,
                    content    : dialogContent,
                    lockScreen : settings.dialogLockScreen,
                    maskStyle  : {
                        opacity         : settings.dialogMaskOpacity,
                        backgroundColor : settings.dialogMaskBgColor
                    },
                    buttons    : {
                        enter  : [lang.buttons.enter, function() {                            
                            cm.replaceSelection(selecteds.join(" "));
                            this.hide().lockScreen(false).hideMask();
                            
                            return false;
                        }],
                        cancel : [lang.buttons.cancel, function() {                           
                            this.hide().lockScreen(false).hideMask();
                            
                            return false;
                        }]
                    }
                });
            }
                
            var table = dialog.find("." + classPrefix + "grid-table");
 
            var drawTable = function() {
 
                if (entitiesData.length < 1) return ;
 
                var rowNumber = 20;
                var pageTotal = Math.ceil(entitiesData.length / rowNumber);
 
                table.html("");
                
                for (var i = 0; i < pageTotal; i++)
                {
                    var row = "<div class=\"" + classPrefix + "grid-table-row\">";
                    
                    for (var x = 0; x < rowNumber; x++)
                    {
                        var entity = entitiesData[(i * rowNumber) + x];
                        
                        if (typeof entity !== "undefined")
                        {
                            var name = entity.name.replace("&amp;", "&");
 
                            row += "<a href=\"javascript:;\" value=\"" + entity.name + "\" title=\"" + name + "\" class=\"" + classPrefix + "html-entity-btn\">" + name + "</a>";
                        }
                    }
                    
                    row += "</div>";
                    
                    table.append(row);
                }
 
                dialog.find("." + classPrefix + "html-entity-btn").bind(exports.mouseOrTouch("click", "touchend"), function() {
                    $(this).toggleClass("selected");
 
                    if ($(this).hasClass("selected")) 
                    {
                        selecteds.push($(this).attr("value"));
                    }
                });
            };
            
            if (entitiesData.length < 1) 
            {            
                if (typeof (dialog.loading) == "function") dialog.loading(true);
 
                $.getJSON(path + pluginName.replace("-dialog", "") + ".json", function(json) {
 
                    if (typeof (dialog.loading) == "function") dialog.loading(false);
 
                    entitiesData = json;
                    drawTable();
                });
            }
            else
            {        
                drawTable();
            }
        };
 
    };
    
    // CommonJS/Node.js
    if (typeof require === "function" && typeof exports === "object" && typeof module === "object")
    { 
        module.exports = factory;
    }
    else if (typeof define === "function")  // AMD/CMD/Sea.js
    {
        if (define.amd) { // for Require.js
 
            define(["editormd"], function(editormd) {
                factory(editormd);
            });
 
        } else { // for Sea.js
            define(function(require) {
                var editormd = require("./../../editormd");
                factory(editormd);
            });
        }
    } 
    else
    {
        factory(window.editormd);
    }
 
})();