├── angular-editor ├── fonts │ └── fontawesome-webfont.woff ├── javascripts │ ├── application.js │ ├── directives │ │ └── doc_directive.js │ └── simditor │ │ ├── module.js │ │ ├── uploader.js │ │ └── simditor.js ├── index.html └── stylesheets │ ├── simditor.css │ └── font-awesome.css └── index.html /angular-editor/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanming/wanming.github.io/master/angular-editor/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /angular-editor/javascripts/application.js: -------------------------------------------------------------------------------- 1 | /*global window,angular*/ 2 | (function (window) { 3 | 'use strict'; 4 | var angular = window.angular, appName = 'app'; 5 | 6 | angular 7 | .module(appName, [ 8 | 'simditor' 9 | ]) 10 | .controller('mainController', function ($scope) { 11 | $scope.editor = 'tom'; 12 | }); 13 | 14 | }(window)); -------------------------------------------------------------------------------- /angular-editor/javascripts/directives/doc_directive.js: -------------------------------------------------------------------------------- 1 | /*global window,location*/ 2 | (function (window) { 3 | 'use strict'; 4 | 5 | var Simditor = window.Simditor; 6 | var directives = angular.module('simditor',[]); 7 | 8 | directives.directive('simditor', function () { 9 | return { 10 | require: "?^ngModel", 11 | link: function (scope, element, attrs, ngModel) { 12 | element.append("
"); 13 | 14 | scope.simditor = new Simditor({ 15 | textarea: element.children()[0], 16 | pasteImage: true, 17 | toolbar: ['title', 'bold', 'italic', 'underline', 'strikethrough', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent'], 18 | defaultImage: 'assets/images/image.png', 19 | upload: location.search === '?upload' ? { 20 | url: '/upload' 21 | } : false 22 | }); 23 | 24 | function readViewText() { 25 | var html = element.find('.simditor-body').html(); 26 | // When we clear the content editable the browser leaves a
behind 27 | // If strip-br attribute is provided then we strip this out 28 | if (attrs.stripBr && html === '
') { 29 | html = ''; 30 | } 31 | 32 | ngModel.$setViewValue(html); 33 | } 34 | 35 | var $target = element.find('.simditor-body'); 36 | 37 | ngModel.$render = function () { 38 | scope.simditor.focus(); 39 | $target.prepend(ngModel.$viewValue); 40 | }; 41 | 42 | element.on('blur keyup change', function () { 43 | scope.$apply(readViewText); 44 | }); 45 | } 46 | }; 47 | }); 48 | }(window)); -------------------------------------------------------------------------------- /angular-editor/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | angular-editor 5 | 6 | 7 | 8 | 9 | 10 | 14 | 15 | 16 |
17 |

angular-editor

18 |

angular rich text editor with simditor(by tower.im)

19 |

20 | just one line to write:

<div simditor ng-model="xxx"></div>
21 |

22 |
23 |
24 |
{{editor}}
25 |
26 |
27 |
Happy wife,happy life.
28 | 29 | 30 | 31 | 32 | 33 | Fork me on GitHub 34 | 35 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Github home page of wanming 5 | 6 | 7 | 8 | 52 | 53 | 54 |

Github home page of wanming

55 |

I'm working on these stuffs:

56 |
    57 |
  1. angular-editor, angular rich text editor inpired by tower's simditor
  2. 58 |
59 |
60 |

contact me with :

61 |

email:wanmingtom@gmail.com

62 |

github:http://github.com/wanming

63 | 64 | 65 | 66 | 67 |
68 | Fork me on GitHub 69 | 70 | -------------------------------------------------------------------------------- /angular-editor/javascripts/simditor/module.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Module, Plugin, Widget, 3 | __slice = [].slice, 4 | __hasProp = {}.hasOwnProperty, 5 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; 6 | 7 | Module = (function() { 8 | function Module() {} 9 | 10 | Module.extend = function(obj) { 11 | var key, val, _ref; 12 | if (!((obj != null) && typeof obj === 'object')) { 13 | return; 14 | } 15 | for (key in obj) { 16 | val = obj[key]; 17 | if (key !== 'included' && key !== 'extended') { 18 | this[key] = val; 19 | } 20 | } 21 | return (_ref = obj.extended) != null ? _ref.call(this) : void 0; 22 | }; 23 | 24 | Module.include = function(obj) { 25 | var key, val, _ref; 26 | if (!((obj != null) && typeof obj === 'object')) { 27 | return; 28 | } 29 | for (key in obj) { 30 | val = obj[key]; 31 | if (key !== 'included' && key !== 'extended') { 32 | this.prototype[key] = val; 33 | } 34 | } 35 | return (_ref = obj.included) != null ? _ref.call(this) : void 0; 36 | }; 37 | 38 | Module.prototype.on = function() { 39 | var args, _ref; 40 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 41 | return (_ref = $(this)).on.apply(_ref, args); 42 | }; 43 | 44 | Module.prototype.one = function() { 45 | var args, _ref; 46 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 47 | return (_ref = $(this)).one.apply(_ref, args); 48 | }; 49 | 50 | Module.prototype.off = function() { 51 | var args, _ref; 52 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 53 | return (_ref = $(this)).off.apply(_ref, args); 54 | }; 55 | 56 | Module.prototype.trigger = function() { 57 | var args, _ref; 58 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 59 | return (_ref = $(this)).trigger.apply(_ref, args); 60 | }; 61 | 62 | Module.prototype.triggerHandler = function() { 63 | var args, _ref; 64 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 65 | return (_ref = $(this)).triggerHandler.apply(_ref, args); 66 | }; 67 | 68 | return Module; 69 | 70 | })(); 71 | 72 | Widget = (function(_super) { 73 | __extends(Widget, _super); 74 | 75 | Widget.connect = function(cls) { 76 | if (typeof cls !== 'function') { 77 | return; 78 | } 79 | if (!cls.className) { 80 | throw new Error('Widget.connect: lack of class property "className"'); 81 | return; 82 | } 83 | if (!this._connectedClasses) { 84 | this._connectedClasses = []; 85 | } 86 | this._connectedClasses.push(cls); 87 | if (cls.className) { 88 | return this[cls.className] = cls; 89 | } 90 | }; 91 | 92 | Widget.prototype._init = function() {}; 93 | 94 | Widget.prototype.opts = {}; 95 | 96 | function Widget(opts) { 97 | var cls, instance, instances, name, _base, _i, _len; 98 | this.opts = $.extend({}, this.opts, opts); 99 | (_base = this.constructor)._connectedClasses || (_base._connectedClasses = []); 100 | instances = (function() { 101 | var _i, _len, _ref, _results; 102 | _ref = this.constructor._connectedClasses; 103 | _results = []; 104 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 105 | cls = _ref[_i]; 106 | name = cls.className.charAt(0).toLowerCase() + cls.className.slice(1); 107 | _results.push(this[name] = new cls(this)); 108 | } 109 | return _results; 110 | }).call(this); 111 | this._init(); 112 | for (_i = 0, _len = instances.length; _i < _len; _i++) { 113 | instance = instances[_i]; 114 | if (typeof instance._init === "function") { 115 | instance._init(); 116 | } 117 | } 118 | this.trigger('pluginconnected'); 119 | } 120 | 121 | Widget.prototype.destroy = function() {}; 122 | 123 | return Widget; 124 | 125 | })(Module); 126 | 127 | Plugin = (function(_super) { 128 | __extends(Plugin, _super); 129 | 130 | Plugin.className = 'Plugin'; 131 | 132 | Plugin.prototype.opts = {}; 133 | 134 | function Plugin(widget) { 135 | this.widget = widget; 136 | this.opts = $.extend({}, this.opts, this.widget.opts); 137 | } 138 | 139 | Plugin.prototype._init = function() {}; 140 | 141 | return Plugin; 142 | 143 | })(Module); 144 | 145 | window.Module = Module; 146 | 147 | window.Widget = Widget; 148 | 149 | window.Plugin = Plugin; 150 | 151 | }).call(this); 152 | -------------------------------------------------------------------------------- /angular-editor/javascripts/simditor/uploader.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Uploader, 3 | __hasProp = {}.hasOwnProperty, 4 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; 5 | 6 | Uploader = (function(_super) { 7 | __extends(Uploader, _super); 8 | 9 | Uploader.count = 0; 10 | 11 | Uploader.prototype.opts = { 12 | url: '', 13 | params: null, 14 | connectionCount: 3, 15 | leaveConfirm: '正在上传文件,如果离开上传会自动取消' 16 | }; 17 | 18 | Uploader.prototype.files = []; 19 | 20 | Uploader.prototype.queue = []; 21 | 22 | Uploader.prototype.html5 = !!(window.File && window.FileList); 23 | 24 | function Uploader(opts) { 25 | var _this = this; 26 | if (opts == null) { 27 | opts = {}; 28 | } 29 | $.extend(this.opts, opts); 30 | this.id = ++Uploader.count; 31 | this.on('uploadcomplete', function(e, file) { 32 | _this.files.splice($.inArray(file, _this.files), 1); 33 | if (_this.queue.length > 0 && _this.files.length < _this.opts.connectionCount) { 34 | return _this.upload(_this.queue.shift()); 35 | } else { 36 | return _this.uploading = false; 37 | } 38 | }); 39 | $(window).on('beforeunload.uploader-' + this.id, function(e) { 40 | if (!_this.uploading) { 41 | return; 42 | } 43 | e.originalEvent.returnValue = _this.opts.leaveConfirm; 44 | return _this.opts.leaveConfirm; 45 | }); 46 | } 47 | 48 | Uploader.prototype.generateId = (function() { 49 | var id; 50 | id = 0; 51 | return function() { 52 | return id += 1; 53 | }; 54 | })(); 55 | 56 | Uploader.prototype.upload = function(file, opts) { 57 | var f, _i, _len; 58 | if (opts == null) { 59 | opts = {}; 60 | } 61 | if (file == null) { 62 | return; 63 | } 64 | if ($.isArray(file)) { 65 | for (_i = 0, _len = file.length; _i < _len; _i++) { 66 | f = file[_i]; 67 | this.upload(f, opts); 68 | } 69 | } else if ($(file).is('input:file') && this.html5) { 70 | this.upload($.makeArray($(file)[0].files), opts); 71 | } else if (!file.id || !file.obj) { 72 | file = this.getFile(file); 73 | } 74 | if (!(file && file.obj)) { 75 | return; 76 | } 77 | $.extend(file, opts); 78 | if (this.files.length >= this.opts.connectionCount) { 79 | this.queue.push(file); 80 | return; 81 | } 82 | if (this.triggerHandler('beforeupload', [file]) === false) { 83 | return; 84 | } 85 | this.files.push(file); 86 | if (this.html5) { 87 | this.xhrUpload(file); 88 | } else { 89 | this.iframeUpload(file); 90 | } 91 | return this.uploading = true; 92 | }; 93 | 94 | Uploader.prototype.getFile = function(fileObj) { 95 | var name, _ref, _ref1; 96 | if (fileObj instanceof window.File || fileObj instanceof window.Blob) { 97 | name = (_ref = fileObj.fileName) != null ? _ref : fileObj.name; 98 | } else if ($(fileObj).is('input:file')) { 99 | name = $input.val().replace(/.*(\/|\\)/, ""); 100 | fileObj = $(fileObj).clone(); 101 | } else { 102 | return null; 103 | } 104 | return { 105 | id: this.generateId(), 106 | url: this.opts.url, 107 | params: this.opts.params, 108 | name: name, 109 | size: (_ref1 = fileObj.fileSize) != null ? _ref1 : fileObj.size, 110 | ext: name ? name.split('.').pop().toLowerCase() : '', 111 | obj: fileObj 112 | }; 113 | }; 114 | 115 | Uploader.prototype.xhrUpload = function(file) { 116 | var formData, k, v, _ref, 117 | _this = this; 118 | formData = new FormData(); 119 | formData.append("upload_file", file.obj); 120 | formData.append("original_filename", file.name); 121 | if (file.params) { 122 | _ref = file.params; 123 | for (k in _ref) { 124 | v = _ref[k]; 125 | formData.append(k, v); 126 | } 127 | } 128 | return file.xhr = $.ajax({ 129 | url: file.url, 130 | data: formData, 131 | processData: false, 132 | contentType: false, 133 | type: 'POST', 134 | headers: { 135 | 'X-File-Name': encodeURIComponent(file.name) 136 | }, 137 | xhr: function() { 138 | var req, 139 | _this = this; 140 | req = $.ajaxSettings.xhr(); 141 | if (req) { 142 | req.upload.onprogress = function(e) { 143 | return _this.progress(e); 144 | }; 145 | } 146 | return req; 147 | }, 148 | progress: function(e) { 149 | if (!e.lengthComputable) { 150 | return; 151 | } 152 | return _this.trigger('uploadprogress', [file, e.loaded, e.total]); 153 | }, 154 | error: function(xhr, status, err) { 155 | return _this.trigger('uploaderror', [file, xhr, status]); 156 | }, 157 | success: function(result) { 158 | _this.trigger('uploadprogress', [file, file.size, file.size]); 159 | return _this.trigger('uploadsuccess', [file, result]); 160 | }, 161 | complete: function(xhr, status) { 162 | return _this.trigger('uploadcomplete', [file, xhr.responseText]); 163 | } 164 | }); 165 | }; 166 | 167 | Uploader.prototype.iframeUpload = function(file) { 168 | var k, v, _ref, 169 | _this = this; 170 | file.iframe = $('iframe', { 171 | src: 'javascript:false;', 172 | name: 'uploader-' + file.id 173 | }).hide().appendTo(document.body); 174 | file.form = $('
', { 175 | method: 'post', 176 | enctype: 'multipart/form-data', 177 | action: file.url, 178 | target: file.iframe[0].name 179 | }).hide().append(file.obj).appendTo(document.body); 180 | if (file.params) { 181 | _ref = file.params; 182 | for (k in _ref) { 183 | v = _ref[k]; 184 | $('', { 185 | type: 'hidden', 186 | name: k, 187 | value: v 188 | }).appendTo(form); 189 | } 190 | } 191 | file.iframe.on('load', function() { 192 | var error, iframeDoc, json, responseEl, result; 193 | if (!(iframe.parent().length > 0)) { 194 | return; 195 | } 196 | iframeDoc = iframe[0].contentDocument; 197 | if (iframeDoc && iframeDoc.body && iframeDoc.body.innerHTML === "false") { 198 | return; 199 | } 200 | responseEl = iframeDoc.getElementById('json-response'); 201 | json = responseEl ? responseEl.innerHTML : iframeDoc.body.innerHTML; 202 | try { 203 | result = $.parseJSON(json); 204 | } catch (_error) { 205 | error = _error; 206 | _this.trigger('uploaderror', [file, null, 'parsererror']); 207 | result = {}; 208 | } 209 | if (result.success) { 210 | _this.trigger('uploadsuccess', [file, result]); 211 | } 212 | _this.trigger('uploadcomplete', [file, result]); 213 | return file.iframe.remove(); 214 | }); 215 | return file.form.submit().remove(); 216 | }; 217 | 218 | Uploader.prototype.cancel = function(file) { 219 | var f, _i, _len, _ref; 220 | if (!file.id) { 221 | _ref = this.files; 222 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 223 | f = _ref[_i]; 224 | if (f.id === file) { 225 | file = f; 226 | break; 227 | } 228 | } 229 | } 230 | this.trigger('uploadcancel', [file]); 231 | if (this.html5) { 232 | if (file.xhr) { 233 | file.xhr.abort(); 234 | } 235 | return file.xhr = null; 236 | } else { 237 | file.iframe.attr('src', 'javascript:false;').remove(); 238 | return this.trigger('uploadcomplete', [file]); 239 | } 240 | }; 241 | 242 | Uploader.prototype.readImageFile = function(fileObj, callback) { 243 | var fileReader, img; 244 | if (!$.isFunction(callback)) { 245 | return; 246 | } 247 | img = new Image(); 248 | img.onload = function() { 249 | return callback(img); 250 | }; 251 | img.onerror = function() { 252 | return callback(); 253 | }; 254 | if (window.FileReader && FileReader.prototype.readAsDataURL && /^image/.test(fileObj.type)) { 255 | fileReader = new FileReader(); 256 | fileReader.onload = function(e) { 257 | return img.src = e.target.result; 258 | }; 259 | return fileReader.readAsDataURL(fileObj); 260 | } else { 261 | return callback(); 262 | } 263 | }; 264 | 265 | Uploader.prototype.destroy = function() { 266 | var file, _i, _len, _ref; 267 | this.queue.length = 0; 268 | _ref = this.files; 269 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 270 | file = _ref[_i]; 271 | this.cancel(file); 272 | } 273 | $(window).off('.uploader-' + this.id); 274 | return $(document).off('.uploader-' + this.id); 275 | }; 276 | 277 | return Uploader; 278 | 279 | })(Module); 280 | 281 | this.simple || (this.simple = {}); 282 | 283 | this.simple.uploader = function(opts) { 284 | return new Uploader(opts); 285 | }; 286 | 287 | }).call(this); 288 | -------------------------------------------------------------------------------- /angular-editor/stylesheets/simditor.css: -------------------------------------------------------------------------------- 1 | .simditor { 2 | position: relative; 3 | border: 1px solid #cccccc; 4 | } 5 | .simditor .simditor-wrapper { 6 | position: relative; 7 | background: #ffffff; 8 | overflow: hidden; 9 | } 10 | .simditor .simditor-wrapper .simditor-placeholder { 11 | display: none; 12 | position: absolute; 13 | top: 40px; 14 | left: 0; 15 | z-index: 0; 16 | padding: 22px 15px; 17 | font-size: 16px; 18 | font-family: helvetica,Arial; 19 | line-height: 1.5; 20 | color: #999999; 21 | background: transparent; 22 | } 23 | .simditor .simditor-wrapper.toolbar-floating { 24 | padding-top: 40px; 25 | } 26 | .simditor .simditor-wrapper.toolbar-floating .simditor-toolbar { 27 | position: fixed; 28 | top: 0; 29 | z-index: 10; 30 | box-shadow: 0 0 6px rgba(0, 0, 0, 0.1); 31 | } 32 | .simditor .simditor-body { 33 | padding: 22px 15px 40px; 34 | min-height: 300px; 35 | outline: none; 36 | cursor: text; 37 | position: relative; 38 | z-index: 1; 39 | background: transparent; 40 | } 41 | .simditor .simditor-body > :first-child { 42 | margin-top: 0 !important; 43 | } 44 | .simditor .simditor-body a.selected { 45 | background: #b3d4fd; 46 | } 47 | .simditor .simditor-body a.simditor-mention { 48 | cursor: pointer; 49 | } 50 | .simditor .simditor-body .simditor-image { 51 | margin: 15px 0; 52 | cursor: pointer; 53 | outline: none; 54 | position: relative; 55 | } 56 | .simditor .simditor-body .simditor-image.selected { 57 | background: none; 58 | box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.2); 59 | } 60 | .simditor .simditor-body .simditor-image img { 61 | margin: 0; 62 | } 63 | .simditor .simditor-body .simditor-image .mask { 64 | position: absolute; 65 | background: rgba(0, 0, 0, 0.4); 66 | width: 100%; 67 | height: 100%; 68 | top: 0; 69 | } 70 | .simditor .simditor-body .simditor-image .simditor-image-progress { 71 | width: 30px; 72 | height: 30px; 73 | background: #ffffff; 74 | border-radius: 30px; 75 | position: absolute; 76 | top: 50%; 77 | left: 50%; 78 | margin: -15px 0 0 -15px; 79 | color: #333333; 80 | font-size: 14px; 81 | line-height: 30px; 82 | text-align: center; 83 | box-shadow: 0 0 8px rgba(0, 0, 0, 0.4); 84 | } 85 | .simditor .simditor-body .simditor-image .simditor-image-progress.loading { 86 | background: white url(../images/loading-upload.gif) no-repeat center center; 87 | } 88 | .simditor .simditor-body .simditor-image .simditor-image-progress.loading span { 89 | display: none; 90 | } 91 | .simditor .simditor-body .simditor-image .simditor-image-resize-handle { 92 | display: none; 93 | } 94 | .simditor .simditor-body .simditor-table { 95 | position: relative; 96 | } 97 | .simditor .simditor-body .simditor-table.resizing { 98 | cursor: col-resize; 99 | } 100 | .simditor .simditor-body .simditor-table .simditor-resize-handle { 101 | position: absolute; 102 | left: 0; 103 | top: 0; 104 | width: 10px; 105 | height: 100%; 106 | cursor: col-resize; 107 | } 108 | .simditor .simditor-body pre { 109 | min-height: 28px; 110 | box-sizing: border-box; 111 | -moz-box-sizing: border-box; 112 | } 113 | .simditor .simditor-paste-area { 114 | background: transparent; 115 | border: none; 116 | outline: none; 117 | } 118 | .simditor .simditor-toolbar { 119 | border-bottom: 1px solid #eeeeee; 120 | background: #ffffff; 121 | width: 100%; 122 | } 123 | .simditor .simditor-toolbar > ul { 124 | height: 40px; 125 | margin: 0; 126 | padding: 0 0 0 6px; 127 | list-style: none; 128 | } 129 | .simditor .simditor-toolbar > ul > li { 130 | position: relative; 131 | float: left; 132 | } 133 | .simditor .simditor-toolbar > ul > li > span.separator { 134 | display: block; 135 | float: left; 136 | background: #cfcfcf; 137 | width: 1px; 138 | height: 18px; 139 | margin: 11px 15px; 140 | } 141 | .simditor .simditor-toolbar > ul > li > .toolbar-item { 142 | display: block; 143 | float: left; 144 | width: 50px; 145 | height: 40px; 146 | outline: none; 147 | overflow: hidden; 148 | color: #333333; 149 | font-size: 15px; 150 | line-height: 40px; 151 | text-align: center; 152 | text-decoration: none; 153 | margin: 0 1px; 154 | } 155 | .simditor .simditor-toolbar > ul > li > .toolbar-item span { 156 | opacity: 0.6; 157 | } 158 | .simditor .simditor-toolbar > ul > li > .toolbar-item:hover span { 159 | opacity: 1; 160 | } 161 | .simditor .simditor-toolbar > ul > li > .toolbar-item.active { 162 | background: #eeeeee; 163 | } 164 | .simditor .simditor-toolbar > ul > li > .toolbar-item.active span { 165 | opacity: 1; 166 | } 167 | .simditor .simditor-toolbar > ul > li > .toolbar-item.disabled { 168 | cursor: default; 169 | } 170 | .simditor .simditor-toolbar > ul > li > .toolbar-item.disabled span { 171 | opacity: 0.3; 172 | } 173 | .simditor .simditor-toolbar > ul > li > .toolbar-item.toolbar-item-title span:before { 174 | content: "T"; 175 | font-size: 19px; 176 | font-weight: bold; 177 | font-family: 'Times New Roman'; 178 | } 179 | .simditor .simditor-toolbar > ul > li > .toolbar-item.toolbar-item-title.active-h1 span:before { 180 | content: 'H1'; 181 | font-size: 18px; 182 | } 183 | .simditor .simditor-toolbar > ul > li > .toolbar-item.toolbar-item-title.active-h2 span:before { 184 | content: 'H2'; 185 | font-size: 18px; 186 | } 187 | .simditor .simditor-toolbar > ul > li > .toolbar-item.toolbar-item-title.active-h3 span:before { 188 | content: 'H3'; 189 | font-size: 18px; 190 | } 191 | .simditor .simditor-toolbar > ul > li.menu-on .toolbar-item { 192 | position: relative; 193 | z-index: 21; 194 | background: #ffffff; 195 | box-shadow: 0 -3px 3px rgba(0, 0, 0, 0.2); 196 | } 197 | .simditor .simditor-toolbar > ul > li.menu-on .toolbar-menu { 198 | display: block; 199 | } 200 | .simditor .simditor-toolbar .toolbar-menu { 201 | display: none; 202 | position: absolute; 203 | top: 39px; 204 | left: 1px; 205 | z-index: 20; 206 | background: #ffffff; 207 | text-align: left; 208 | box-shadow: 0 0 3px rgba(0, 0, 0, 0.2); 209 | } 210 | .simditor .simditor-toolbar .toolbar-menu ul { 211 | min-width: 160px; 212 | list-style: none; 213 | margin: 0; 214 | padding: 10px 1px; 215 | } 216 | .simditor .simditor-toolbar .toolbar-menu ul > li .menu-item { 217 | display: block; 218 | font-size: 16px; 219 | line-height: 2em; 220 | padding: 0 10px; 221 | text-decoration: none; 222 | color: #666666; 223 | } 224 | .simditor .simditor-toolbar .toolbar-menu ul > li .menu-item:hover { 225 | background: #f6f6f6; 226 | } 227 | .simditor .simditor-toolbar .toolbar-menu ul > li .menu-item.menu-item-h1 { 228 | font-size: 24px; 229 | color: #333333; 230 | } 231 | .simditor .simditor-toolbar .toolbar-menu ul > li .menu-item.menu-item-h2 { 232 | font-size: 22px; 233 | color: #333333; 234 | } 235 | .simditor .simditor-toolbar .toolbar-menu ul > li .menu-item.menu-item-h3 { 236 | font-size: 20px; 237 | color: #333333; 238 | } 239 | .simditor .simditor-toolbar .toolbar-menu ul > li .separator { 240 | display: block; 241 | border-top: 1px solid #cccccc; 242 | height: 0; 243 | line-height: 0; 244 | font-size: 0; 245 | margin: 6px 0; 246 | } 247 | .simditor .simditor-toolbar .toolbar-menu.toolbar-menu-table .menu-create-table { 248 | background: #ffffff; 249 | } 250 | .simditor .simditor-toolbar .toolbar-menu.toolbar-menu-table .menu-create-table table { 251 | border: none; 252 | border-collapse: collapse; 253 | border-spacing: 0; 254 | table-layout: fixed; 255 | } 256 | .simditor .simditor-toolbar .toolbar-menu.toolbar-menu-table .menu-create-table table td { 257 | height: 16px; 258 | padding: 0; 259 | border: 2px solid #ffffff; 260 | background: #f3f3f3; 261 | cursor: pointer; 262 | } 263 | .simditor .simditor-toolbar .toolbar-menu.toolbar-menu-table .menu-create-table table td:before { 264 | width: 16px; 265 | display: block; 266 | content: ""; 267 | } 268 | .simditor .simditor-toolbar .toolbar-menu.toolbar-menu-table .menu-create-table table td.selected { 269 | background: #cfcfcf; 270 | } 271 | .simditor .simditor-toolbar .toolbar-menu.toolbar-menu-table .menu-edit-table { 272 | display: none; 273 | } 274 | .simditor .simditor-toolbar .toolbar-menu.toolbar-menu-image .menu-item-upload-image { 275 | position: relative; 276 | overflow: hidden; 277 | } 278 | .simditor .simditor-toolbar .toolbar-menu.toolbar-menu-image .menu-item-upload-image input[type=file] { 279 | position: absolute; 280 | right: 0px; 281 | top: 0px; 282 | opacity: 0; 283 | font-size: 100px; 284 | cursor: pointer; 285 | } 286 | .simditor .simditor-popover { 287 | display: none; 288 | padding: 5px 8px 0; 289 | background: #ffffff; 290 | box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); 291 | border-radius: 2px; 292 | position: absolute; 293 | z-index: 2; 294 | } 295 | .simditor .simditor-popover .settings-field { 296 | margin: 0 0 5px 0; 297 | font-size: 12px; 298 | } 299 | .simditor .simditor-popover .settings-field label { 300 | margin: 0 2px 0 0; 301 | } 302 | .simditor .simditor-popover .settings-field input[type=text] { 303 | width: 200px; 304 | box-sizing: border-box; 305 | font-size: 12px; 306 | } 307 | .simditor .simditor-popover.link-popover .btn-unlink, .simditor .simditor-popover.image-popover .btn-upload { 308 | margin: 0 0 0 5px; 309 | color: #333333; 310 | font-size: 14px; 311 | } 312 | .simditor .simditor-popover.link-popover .btn-unlink span, .simditor .simditor-popover.image-popover .btn-upload span { 313 | opacity: 0.6; 314 | } 315 | .simditor .simditor-popover.link-popover .btn-unlink:hover span, .simditor .simditor-popover.image-popover .btn-upload:hover span { 316 | opacity: 1; 317 | } 318 | .simditor .simditor-popover.image-popover .btn-upload { 319 | position: relative; 320 | display: inline-block; 321 | overflow: hidden; 322 | } 323 | .simditor .simditor-popover.image-popover .btn-upload input[type=file] { 324 | position: absolute; 325 | right: 0px; 326 | top: 0px; 327 | opacity: 0; 328 | height: 100%; 329 | width: 28px; 330 | } 331 | 332 | .simditor .simditor-body, .editor-style { 333 | font-size: 16px; 334 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 335 | line-height: 1.6; 336 | color: #333; 337 | outline: none; 338 | word-wrap: break-word; 339 | } 340 | .simditor .simditor-body a, .editor-style a { 341 | color: #4298BA; 342 | text-decoration: none; 343 | word-break: break-all; 344 | } 345 | .simditor .simditor-body a:visited, .editor-style a:visited { 346 | color: #4298BA; 347 | } 348 | .simditor .simditor-body a:hover, .editor-style a:hover { 349 | color: #0F769F; 350 | } 351 | .simditor .simditor-body a:active, .editor-style a:active { 352 | color: #9E792E; 353 | } 354 | .simditor .simditor-body a:hover, .simditor .simditor-body a:active, .editor-style a:hover, .editor-style a:active { 355 | outline: 0; 356 | } 357 | .simditor .simditor-body h1, .simditor .simditor-body h2, .simditor .simditor-body h3, .simditor .simditor-body h4, .simditor .simditor-body h5, .simditor .simditor-body h6, .editor-style h1, .editor-style h2, .editor-style h3, .editor-style h4, .editor-style h5, .editor-style h6 { 358 | font-weight: bold; 359 | margin: 40px 0 20px; 360 | color: #000000; 361 | } 362 | .simditor .simditor-body h1, .editor-style h1 { 363 | font-size: 24px; 364 | } 365 | .simditor .simditor-body h2, .editor-style h2 { 366 | font-size: 22px; 367 | } 368 | .simditor .simditor-body h3, .editor-style h3 { 369 | font-size: 20px; 370 | } 371 | .simditor .simditor-body h4, .editor-style h4 { 372 | font-size: 18px; 373 | } 374 | .simditor .simditor-body h5, .editor-style h5 { 375 | font-size: 16px; 376 | } 377 | .simditor .simditor-body h6, .editor-style h6 { 378 | font-size: 16px; 379 | } 380 | .simditor .simditor-body p, .simditor .simditor-body div, .editor-style p, .editor-style div { 381 | word-wrap: break-word; 382 | margin: 0 0 15px 0; 383 | color: #333; 384 | word-wrap: break-word; 385 | } 386 | .simditor .simditor-body b, .simditor .simditor-body strong, .editor-style b, .editor-style strong { 387 | font-weight: bold; 388 | } 389 | .simditor .simditor-body i, .simditor .simditor-body em, .editor-style i, .editor-style em { 390 | font-style: italic; 391 | } 392 | .simditor .simditor-body u, .editor-style u { 393 | text-decoration: underline; 394 | } 395 | .simditor .simditor-body strike, .simditor .simditor-body del, .editor-style strike, .editor-style del { 396 | text-decoration: line-through; 397 | } 398 | .simditor .simditor-body ul, .simditor .simditor-body ol, .editor-style ul, .editor-style ol { 399 | list-style: disc outside none; 400 | margin: 15px 0; 401 | padding: 0 0 0 40px; 402 | line-height: 1.6; 403 | } 404 | .simditor .simditor-body ul ul, .simditor .simditor-body ul ol, .simditor .simditor-body ol ul, .simditor .simditor-body ol ol, .editor-style ul ul, .editor-style ul ol, .editor-style ol ul, .editor-style ol ol { 405 | padding-left: 30px; 406 | } 407 | .simditor .simditor-body ul ul, .simditor .simditor-body ol ul, .editor-style ul ul, .editor-style ol ul { 408 | list-style: circle outside none; 409 | } 410 | .simditor .simditor-body ul ul ul, .simditor .simditor-body ol ul ul, .editor-style ul ul ul, .editor-style ol ul ul { 411 | list-style: square outside none; 412 | } 413 | .simditor .simditor-body ol, .editor-style ol { 414 | list-style: decimal; 415 | } 416 | .simditor .simditor-body blockquote, .editor-style blockquote { 417 | border-left: 6px solid #ddd; 418 | padding: 5px 0 5px 10px; 419 | margin: 15px 0 15px 15px; 420 | } 421 | .simditor .simditor-body blockquote > :first-child, .editor-style blockquote > :first-child { 422 | margin-top: 0; 423 | } 424 | .simditor .simditor-body pre, .editor-style pre { 425 | padding: 10px 5px 10px 10px; 426 | margin: 15px 0; 427 | display: block; 428 | line-height: 18px; 429 | background: #F0F0F0; 430 | border-radius: 3px; 431 | font-size: 13px; 432 | font-family: 'monaco', 'Consolas', "Liberation Mono", Courier, monospace; 433 | overflow-x: auto; 434 | white-space: pre; 435 | word-wrap: normal; 436 | } 437 | .simditor .simditor-body code, .editor-style code { 438 | display: inline-block; 439 | padding: 0 4px; 440 | margin: 0 5px; 441 | background: #eeeeee; 442 | border-radius: 3px; 443 | font-size: 13px; 444 | font-family: 'monaco', 'Consolas', "Liberation Mono", Courier, monospace; 445 | } 446 | .simditor .simditor-body hr, .editor-style hr { 447 | display: block; 448 | height: 0px; 449 | border: 0; 450 | border-top: 1px solid #ccc; 451 | margin: 15px 0; 452 | padding: 0; 453 | } 454 | .simditor .simditor-body table, .editor-style table { 455 | width: 100%; 456 | table-layout: fixed; 457 | border-collapse: collapse; 458 | border-spacing: 0; 459 | margin: 15px 0; 460 | } 461 | .simditor .simditor-body table thead, .editor-style table thead { 462 | background-color: #f9f9f9; 463 | } 464 | .simditor .simditor-body table td, .editor-style table td { 465 | min-width: 40px; 466 | height: 30px; 467 | border: 1px solid #ccc; 468 | vertical-align: top; 469 | padding: 2px 4px; 470 | box-sizing: border-box; 471 | } 472 | .simditor .simditor-body table td.active, .editor-style table td.active { 473 | background-color: #ffffee; 474 | } 475 | .simditor .simditor-body img, .editor-style img { 476 | max-width: 800px; 477 | margin: 20px 0; 478 | display: block; 479 | -ms-interpolation-mode: bicubic; 480 | vertical-align: bottom; 481 | box-shadow: 0 1px 6px rgba(0, 0, 0, 0.3); 482 | } 483 | .simditor .simditor-body *[data-indent="0"], .editor-style *[data-indent="0"] { 484 | margin-left: 0px; 485 | } 486 | .simditor .simditor-body *[data-indent="1"], .editor-style *[data-indent="1"] { 487 | margin-left: 40px; 488 | } 489 | .simditor .simditor-body *[data-indent="2"], .editor-style *[data-indent="2"] { 490 | margin-left: 80px; 491 | } 492 | .simditor .simditor-body *[data-indent="3"], .editor-style *[data-indent="3"] { 493 | margin-left: 120px; 494 | } 495 | .simditor .simditor-body *[data-indent="4"], .editor-style *[data-indent="4"] { 496 | margin-left: 160px; 497 | } 498 | .simditor .simditor-body *[data-indent="5"], .editor-style *[data-indent="5"] { 499 | margin-left: 200px; 500 | } 501 | .simditor .simditor-body *[data-indent="6"], .editor-style *[data-indent="6"] { 502 | margin-left: 240px; 503 | } 504 | .simditor .simditor-body *[data-indent="7"], .editor-style *[data-indent="7"] { 505 | margin-left: 280px; 506 | } 507 | .simditor .simditor-body *[data-indent="8"], .editor-style *[data-indent="8"] { 508 | margin-left: 320px; 509 | } 510 | .simditor .simditor-body *[data-indent="9"], .editor-style *[data-indent="9"] { 511 | margin-left: 360px; 512 | } 513 | .simditor .simditor-body *[data-indent="10"], .editor-style *[data-indent="10"] { 514 | margin-left: 400px; 515 | } 516 | -------------------------------------------------------------------------------- /angular-editor/stylesheets/font-awesome.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Font Awesome 4.0.3 by @davegandy - http://fontawesome.io - @fontawesome 3 | * License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License) 4 | */ 5 | /* FONT PATH 6 | * -------------------------- */ 7 | @font-face { 8 | font-family: 'FontAwesome'; 9 | src: url('../fonts/fontawesome-webfont.eot?v=4.0.3'); 10 | src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.0.3') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff?v=4.0.3') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.0.3') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.0.3#fontawesomeregular') format('svg'); 11 | font-weight: normal; 12 | font-style: normal; 13 | } 14 | .fa { 15 | display: inline-block; 16 | font-family: FontAwesome; 17 | font-style: normal; 18 | font-weight: normal; 19 | line-height: 1; 20 | -webkit-font-smoothing: antialiased; 21 | -moz-osx-font-smoothing: grayscale; 22 | } 23 | /* makes the font 33% larger relative to the icon container */ 24 | .fa-lg { 25 | font-size: 1.3333333333333333em; 26 | line-height: 0.75em; 27 | vertical-align: -15%; 28 | } 29 | .fa-2x { 30 | font-size: 2em; 31 | } 32 | .fa-3x { 33 | font-size: 3em; 34 | } 35 | .fa-4x { 36 | font-size: 4em; 37 | } 38 | .fa-5x { 39 | font-size: 5em; 40 | } 41 | .fa-fw { 42 | width: 1.2857142857142858em; 43 | text-align: center; 44 | } 45 | .fa-ul { 46 | padding-left: 0; 47 | margin-left: 2.142857142857143em; 48 | list-style-type: none; 49 | } 50 | .fa-ul > li { 51 | position: relative; 52 | } 53 | .fa-li { 54 | position: absolute; 55 | left: -2.142857142857143em; 56 | width: 2.142857142857143em; 57 | top: 0.14285714285714285em; 58 | text-align: center; 59 | } 60 | .fa-li.fa-lg { 61 | left: -1.8571428571428572em; 62 | } 63 | .fa-border { 64 | padding: .2em .25em .15em; 65 | border: solid 0.08em #eeeeee; 66 | border-radius: .1em; 67 | } 68 | .pull-right { 69 | float: right; 70 | } 71 | .pull-left { 72 | float: left; 73 | } 74 | .fa.pull-left { 75 | margin-right: .3em; 76 | } 77 | .fa.pull-right { 78 | margin-left: .3em; 79 | } 80 | .fa-spin { 81 | -webkit-animation: spin 2s infinite linear; 82 | -moz-animation: spin 2s infinite linear; 83 | -o-animation: spin 2s infinite linear; 84 | animation: spin 2s infinite linear; 85 | } 86 | @-moz-keyframes spin { 87 | 0% { 88 | -moz-transform: rotate(0deg); 89 | } 90 | 100% { 91 | -moz-transform: rotate(359deg); 92 | } 93 | } 94 | @-webkit-keyframes spin { 95 | 0% { 96 | -webkit-transform: rotate(0deg); 97 | } 98 | 100% { 99 | -webkit-transform: rotate(359deg); 100 | } 101 | } 102 | @-o-keyframes spin { 103 | 0% { 104 | -o-transform: rotate(0deg); 105 | } 106 | 100% { 107 | -o-transform: rotate(359deg); 108 | } 109 | } 110 | @-ms-keyframes spin { 111 | 0% { 112 | -ms-transform: rotate(0deg); 113 | } 114 | 100% { 115 | -ms-transform: rotate(359deg); 116 | } 117 | } 118 | @keyframes spin { 119 | 0% { 120 | transform: rotate(0deg); 121 | } 122 | 100% { 123 | transform: rotate(359deg); 124 | } 125 | } 126 | .fa-rotate-90 { 127 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1); 128 | -webkit-transform: rotate(90deg); 129 | -moz-transform: rotate(90deg); 130 | -ms-transform: rotate(90deg); 131 | -o-transform: rotate(90deg); 132 | transform: rotate(90deg); 133 | } 134 | .fa-rotate-180 { 135 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2); 136 | -webkit-transform: rotate(180deg); 137 | -moz-transform: rotate(180deg); 138 | -ms-transform: rotate(180deg); 139 | -o-transform: rotate(180deg); 140 | transform: rotate(180deg); 141 | } 142 | .fa-rotate-270 { 143 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); 144 | -webkit-transform: rotate(270deg); 145 | -moz-transform: rotate(270deg); 146 | -ms-transform: rotate(270deg); 147 | -o-transform: rotate(270deg); 148 | transform: rotate(270deg); 149 | } 150 | .fa-flip-horizontal { 151 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1); 152 | -webkit-transform: scale(-1, 1); 153 | -moz-transform: scale(-1, 1); 154 | -ms-transform: scale(-1, 1); 155 | -o-transform: scale(-1, 1); 156 | transform: scale(-1, 1); 157 | } 158 | .fa-flip-vertical { 159 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1); 160 | -webkit-transform: scale(1, -1); 161 | -moz-transform: scale(1, -1); 162 | -ms-transform: scale(1, -1); 163 | -o-transform: scale(1, -1); 164 | transform: scale(1, -1); 165 | } 166 | .fa-stack { 167 | position: relative; 168 | display: inline-block; 169 | width: 2em; 170 | height: 2em; 171 | line-height: 2em; 172 | vertical-align: middle; 173 | } 174 | .fa-stack-1x, 175 | .fa-stack-2x { 176 | position: absolute; 177 | left: 0; 178 | width: 100%; 179 | text-align: center; 180 | } 181 | .fa-stack-1x { 182 | line-height: inherit; 183 | } 184 | .fa-stack-2x { 185 | font-size: 2em; 186 | } 187 | .fa-inverse { 188 | color: #ffffff; 189 | } 190 | /* Font Awesome uses the Unicode Private Use Area (PUA) to ensure screen 191 | readers do not read off random characters that represent icons */ 192 | .fa-glass:before { 193 | content: "\f000"; 194 | } 195 | .fa-music:before { 196 | content: "\f001"; 197 | } 198 | .fa-search:before { 199 | content: "\f002"; 200 | } 201 | .fa-envelope-o:before { 202 | content: "\f003"; 203 | } 204 | .fa-heart:before { 205 | content: "\f004"; 206 | } 207 | .fa-star:before { 208 | content: "\f005"; 209 | } 210 | .fa-star-o:before { 211 | content: "\f006"; 212 | } 213 | .fa-user:before { 214 | content: "\f007"; 215 | } 216 | .fa-film:before { 217 | content: "\f008"; 218 | } 219 | .fa-th-large:before { 220 | content: "\f009"; 221 | } 222 | .fa-th:before { 223 | content: "\f00a"; 224 | } 225 | .fa-th-list:before { 226 | content: "\f00b"; 227 | } 228 | .fa-check:before { 229 | content: "\f00c"; 230 | } 231 | .fa-times:before { 232 | content: "\f00d"; 233 | } 234 | .fa-search-plus:before { 235 | content: "\f00e"; 236 | } 237 | .fa-search-minus:before { 238 | content: "\f010"; 239 | } 240 | .fa-power-off:before { 241 | content: "\f011"; 242 | } 243 | .fa-signal:before { 244 | content: "\f012"; 245 | } 246 | .fa-gear:before, 247 | .fa-cog:before { 248 | content: "\f013"; 249 | } 250 | .fa-trash-o:before { 251 | content: "\f014"; 252 | } 253 | .fa-home:before { 254 | content: "\f015"; 255 | } 256 | .fa-file-o:before { 257 | content: "\f016"; 258 | } 259 | .fa-clock-o:before { 260 | content: "\f017"; 261 | } 262 | .fa-road:before { 263 | content: "\f018"; 264 | } 265 | .fa-download:before { 266 | content: "\f019"; 267 | } 268 | .fa-arrow-circle-o-down:before { 269 | content: "\f01a"; 270 | } 271 | .fa-arrow-circle-o-up:before { 272 | content: "\f01b"; 273 | } 274 | .fa-inbox:before { 275 | content: "\f01c"; 276 | } 277 | .fa-play-circle-o:before { 278 | content: "\f01d"; 279 | } 280 | .fa-rotate-right:before, 281 | .fa-repeat:before { 282 | content: "\f01e"; 283 | } 284 | .fa-refresh:before { 285 | content: "\f021"; 286 | } 287 | .fa-list-alt:before { 288 | content: "\f022"; 289 | } 290 | .fa-lock:before { 291 | content: "\f023"; 292 | } 293 | .fa-flag:before { 294 | content: "\f024"; 295 | } 296 | .fa-headphones:before { 297 | content: "\f025"; 298 | } 299 | .fa-volume-off:before { 300 | content: "\f026"; 301 | } 302 | .fa-volume-down:before { 303 | content: "\f027"; 304 | } 305 | .fa-volume-up:before { 306 | content: "\f028"; 307 | } 308 | .fa-qrcode:before { 309 | content: "\f029"; 310 | } 311 | .fa-barcode:before { 312 | content: "\f02a"; 313 | } 314 | .fa-tag:before { 315 | content: "\f02b"; 316 | } 317 | .fa-tags:before { 318 | content: "\f02c"; 319 | } 320 | .fa-book:before { 321 | content: "\f02d"; 322 | } 323 | .fa-bookmark:before { 324 | content: "\f02e"; 325 | } 326 | .fa-print:before { 327 | content: "\f02f"; 328 | } 329 | .fa-camera:before { 330 | content: "\f030"; 331 | } 332 | .fa-font:before { 333 | content: "\f031"; 334 | } 335 | .fa-bold:before { 336 | content: "\f032"; 337 | } 338 | .fa-italic:before { 339 | content: "\f033"; 340 | } 341 | .fa-text-height:before { 342 | content: "\f034"; 343 | } 344 | .fa-text-width:before { 345 | content: "\f035"; 346 | } 347 | .fa-align-left:before { 348 | content: "\f036"; 349 | } 350 | .fa-align-center:before { 351 | content: "\f037"; 352 | } 353 | .fa-align-right:before { 354 | content: "\f038"; 355 | } 356 | .fa-align-justify:before { 357 | content: "\f039"; 358 | } 359 | .fa-list:before { 360 | content: "\f03a"; 361 | } 362 | .fa-dedent:before, 363 | .fa-outdent:before { 364 | content: "\f03b"; 365 | } 366 | .fa-indent:before { 367 | content: "\f03c"; 368 | } 369 | .fa-video-camera:before { 370 | content: "\f03d"; 371 | } 372 | .fa-picture-o:before { 373 | content: "\f03e"; 374 | } 375 | .fa-pencil:before { 376 | content: "\f040"; 377 | } 378 | .fa-map-marker:before { 379 | content: "\f041"; 380 | } 381 | .fa-adjust:before { 382 | content: "\f042"; 383 | } 384 | .fa-tint:before { 385 | content: "\f043"; 386 | } 387 | .fa-edit:before, 388 | .fa-pencil-square-o:before { 389 | content: "\f044"; 390 | } 391 | .fa-share-square-o:before { 392 | content: "\f045"; 393 | } 394 | .fa-check-square-o:before { 395 | content: "\f046"; 396 | } 397 | .fa-arrows:before { 398 | content: "\f047"; 399 | } 400 | .fa-step-backward:before { 401 | content: "\f048"; 402 | } 403 | .fa-fast-backward:before { 404 | content: "\f049"; 405 | } 406 | .fa-backward:before { 407 | content: "\f04a"; 408 | } 409 | .fa-play:before { 410 | content: "\f04b"; 411 | } 412 | .fa-pause:before { 413 | content: "\f04c"; 414 | } 415 | .fa-stop:before { 416 | content: "\f04d"; 417 | } 418 | .fa-forward:before { 419 | content: "\f04e"; 420 | } 421 | .fa-fast-forward:before { 422 | content: "\f050"; 423 | } 424 | .fa-step-forward:before { 425 | content: "\f051"; 426 | } 427 | .fa-eject:before { 428 | content: "\f052"; 429 | } 430 | .fa-chevron-left:before { 431 | content: "\f053"; 432 | } 433 | .fa-chevron-right:before { 434 | content: "\f054"; 435 | } 436 | .fa-plus-circle:before { 437 | content: "\f055"; 438 | } 439 | .fa-minus-circle:before { 440 | content: "\f056"; 441 | } 442 | .fa-times-circle:before { 443 | content: "\f057"; 444 | } 445 | .fa-check-circle:before { 446 | content: "\f058"; 447 | } 448 | .fa-question-circle:before { 449 | content: "\f059"; 450 | } 451 | .fa-info-circle:before { 452 | content: "\f05a"; 453 | } 454 | .fa-crosshairs:before { 455 | content: "\f05b"; 456 | } 457 | .fa-times-circle-o:before { 458 | content: "\f05c"; 459 | } 460 | .fa-check-circle-o:before { 461 | content: "\f05d"; 462 | } 463 | .fa-ban:before { 464 | content: "\f05e"; 465 | } 466 | .fa-arrow-left:before { 467 | content: "\f060"; 468 | } 469 | .fa-arrow-right:before { 470 | content: "\f061"; 471 | } 472 | .fa-arrow-up:before { 473 | content: "\f062"; 474 | } 475 | .fa-arrow-down:before { 476 | content: "\f063"; 477 | } 478 | .fa-mail-forward:before, 479 | .fa-share:before { 480 | content: "\f064"; 481 | } 482 | .fa-expand:before { 483 | content: "\f065"; 484 | } 485 | .fa-compress:before { 486 | content: "\f066"; 487 | } 488 | .fa-plus:before { 489 | content: "\f067"; 490 | } 491 | .fa-minus:before { 492 | content: "\f068"; 493 | } 494 | .fa-asterisk:before { 495 | content: "\f069"; 496 | } 497 | .fa-exclamation-circle:before { 498 | content: "\f06a"; 499 | } 500 | .fa-gift:before { 501 | content: "\f06b"; 502 | } 503 | .fa-leaf:before { 504 | content: "\f06c"; 505 | } 506 | .fa-fire:before { 507 | content: "\f06d"; 508 | } 509 | .fa-eye:before { 510 | content: "\f06e"; 511 | } 512 | .fa-eye-slash:before { 513 | content: "\f070"; 514 | } 515 | .fa-warning:before, 516 | .fa-exclamation-triangle:before { 517 | content: "\f071"; 518 | } 519 | .fa-plane:before { 520 | content: "\f072"; 521 | } 522 | .fa-calendar:before { 523 | content: "\f073"; 524 | } 525 | .fa-random:before { 526 | content: "\f074"; 527 | } 528 | .fa-comment:before { 529 | content: "\f075"; 530 | } 531 | .fa-magnet:before { 532 | content: "\f076"; 533 | } 534 | .fa-chevron-up:before { 535 | content: "\f077"; 536 | } 537 | .fa-chevron-down:before { 538 | content: "\f078"; 539 | } 540 | .fa-retweet:before { 541 | content: "\f079"; 542 | } 543 | .fa-shopping-cart:before { 544 | content: "\f07a"; 545 | } 546 | .fa-folder:before { 547 | content: "\f07b"; 548 | } 549 | .fa-folder-open:before { 550 | content: "\f07c"; 551 | } 552 | .fa-arrows-v:before { 553 | content: "\f07d"; 554 | } 555 | .fa-arrows-h:before { 556 | content: "\f07e"; 557 | } 558 | .fa-bar-chart-o:before { 559 | content: "\f080"; 560 | } 561 | .fa-twitter-square:before { 562 | content: "\f081"; 563 | } 564 | .fa-facebook-square:before { 565 | content: "\f082"; 566 | } 567 | .fa-camera-retro:before { 568 | content: "\f083"; 569 | } 570 | .fa-key:before { 571 | content: "\f084"; 572 | } 573 | .fa-gears:before, 574 | .fa-cogs:before { 575 | content: "\f085"; 576 | } 577 | .fa-comments:before { 578 | content: "\f086"; 579 | } 580 | .fa-thumbs-o-up:before { 581 | content: "\f087"; 582 | } 583 | .fa-thumbs-o-down:before { 584 | content: "\f088"; 585 | } 586 | .fa-star-half:before { 587 | content: "\f089"; 588 | } 589 | .fa-heart-o:before { 590 | content: "\f08a"; 591 | } 592 | .fa-sign-out:before { 593 | content: "\f08b"; 594 | } 595 | .fa-linkedin-square:before { 596 | content: "\f08c"; 597 | } 598 | .fa-thumb-tack:before { 599 | content: "\f08d"; 600 | } 601 | .fa-external-link:before { 602 | content: "\f08e"; 603 | } 604 | .fa-sign-in:before { 605 | content: "\f090"; 606 | } 607 | .fa-trophy:before { 608 | content: "\f091"; 609 | } 610 | .fa-github-square:before { 611 | content: "\f092"; 612 | } 613 | .fa-upload:before { 614 | content: "\f093"; 615 | } 616 | .fa-lemon-o:before { 617 | content: "\f094"; 618 | } 619 | .fa-phone:before { 620 | content: "\f095"; 621 | } 622 | .fa-square-o:before { 623 | content: "\f096"; 624 | } 625 | .fa-bookmark-o:before { 626 | content: "\f097"; 627 | } 628 | .fa-phone-square:before { 629 | content: "\f098"; 630 | } 631 | .fa-twitter:before { 632 | content: "\f099"; 633 | } 634 | .fa-facebook:before { 635 | content: "\f09a"; 636 | } 637 | .fa-github:before { 638 | content: "\f09b"; 639 | } 640 | .fa-unlock:before { 641 | content: "\f09c"; 642 | } 643 | .fa-credit-card:before { 644 | content: "\f09d"; 645 | } 646 | .fa-rss:before { 647 | content: "\f09e"; 648 | } 649 | .fa-hdd-o:before { 650 | content: "\f0a0"; 651 | } 652 | .fa-bullhorn:before { 653 | content: "\f0a1"; 654 | } 655 | .fa-bell:before { 656 | content: "\f0f3"; 657 | } 658 | .fa-certificate:before { 659 | content: "\f0a3"; 660 | } 661 | .fa-hand-o-right:before { 662 | content: "\f0a4"; 663 | } 664 | .fa-hand-o-left:before { 665 | content: "\f0a5"; 666 | } 667 | .fa-hand-o-up:before { 668 | content: "\f0a6"; 669 | } 670 | .fa-hand-o-down:before { 671 | content: "\f0a7"; 672 | } 673 | .fa-arrow-circle-left:before { 674 | content: "\f0a8"; 675 | } 676 | .fa-arrow-circle-right:before { 677 | content: "\f0a9"; 678 | } 679 | .fa-arrow-circle-up:before { 680 | content: "\f0aa"; 681 | } 682 | .fa-arrow-circle-down:before { 683 | content: "\f0ab"; 684 | } 685 | .fa-globe:before { 686 | content: "\f0ac"; 687 | } 688 | .fa-wrench:before { 689 | content: "\f0ad"; 690 | } 691 | .fa-tasks:before { 692 | content: "\f0ae"; 693 | } 694 | .fa-filter:before { 695 | content: "\f0b0"; 696 | } 697 | .fa-briefcase:before { 698 | content: "\f0b1"; 699 | } 700 | .fa-arrows-alt:before { 701 | content: "\f0b2"; 702 | } 703 | .fa-group:before, 704 | .fa-users:before { 705 | content: "\f0c0"; 706 | } 707 | .fa-chain:before, 708 | .fa-link:before { 709 | content: "\f0c1"; 710 | } 711 | .fa-cloud:before { 712 | content: "\f0c2"; 713 | } 714 | .fa-flask:before { 715 | content: "\f0c3"; 716 | } 717 | .fa-cut:before, 718 | .fa-scissors:before { 719 | content: "\f0c4"; 720 | } 721 | .fa-copy:before, 722 | .fa-files-o:before { 723 | content: "\f0c5"; 724 | } 725 | .fa-paperclip:before { 726 | content: "\f0c6"; 727 | } 728 | .fa-save:before, 729 | .fa-floppy-o:before { 730 | content: "\f0c7"; 731 | } 732 | .fa-square:before { 733 | content: "\f0c8"; 734 | } 735 | .fa-bars:before { 736 | content: "\f0c9"; 737 | } 738 | .fa-list-ul:before { 739 | content: "\f0ca"; 740 | } 741 | .fa-list-ol:before { 742 | content: "\f0cb"; 743 | } 744 | .fa-strikethrough:before { 745 | content: "\f0cc"; 746 | } 747 | .fa-underline:before { 748 | content: "\f0cd"; 749 | } 750 | .fa-table:before { 751 | content: "\f0ce"; 752 | } 753 | .fa-magic:before { 754 | content: "\f0d0"; 755 | } 756 | .fa-truck:before { 757 | content: "\f0d1"; 758 | } 759 | .fa-pinterest:before { 760 | content: "\f0d2"; 761 | } 762 | .fa-pinterest-square:before { 763 | content: "\f0d3"; 764 | } 765 | .fa-google-plus-square:before { 766 | content: "\f0d4"; 767 | } 768 | .fa-google-plus:before { 769 | content: "\f0d5"; 770 | } 771 | .fa-money:before { 772 | content: "\f0d6"; 773 | } 774 | .fa-caret-down:before { 775 | content: "\f0d7"; 776 | } 777 | .fa-caret-up:before { 778 | content: "\f0d8"; 779 | } 780 | .fa-caret-left:before { 781 | content: "\f0d9"; 782 | } 783 | .fa-caret-right:before { 784 | content: "\f0da"; 785 | } 786 | .fa-columns:before { 787 | content: "\f0db"; 788 | } 789 | .fa-unsorted:before, 790 | .fa-sort:before { 791 | content: "\f0dc"; 792 | } 793 | .fa-sort-down:before, 794 | .fa-sort-asc:before { 795 | content: "\f0dd"; 796 | } 797 | .fa-sort-up:before, 798 | .fa-sort-desc:before { 799 | content: "\f0de"; 800 | } 801 | .fa-envelope:before { 802 | content: "\f0e0"; 803 | } 804 | .fa-linkedin:before { 805 | content: "\f0e1"; 806 | } 807 | .fa-rotate-left:before, 808 | .fa-undo:before { 809 | content: "\f0e2"; 810 | } 811 | .fa-legal:before, 812 | .fa-gavel:before { 813 | content: "\f0e3"; 814 | } 815 | .fa-dashboard:before, 816 | .fa-tachometer:before { 817 | content: "\f0e4"; 818 | } 819 | .fa-comment-o:before { 820 | content: "\f0e5"; 821 | } 822 | .fa-comments-o:before { 823 | content: "\f0e6"; 824 | } 825 | .fa-flash:before, 826 | .fa-bolt:before { 827 | content: "\f0e7"; 828 | } 829 | .fa-sitemap:before { 830 | content: "\f0e8"; 831 | } 832 | .fa-umbrella:before { 833 | content: "\f0e9"; 834 | } 835 | .fa-paste:before, 836 | .fa-clipboard:before { 837 | content: "\f0ea"; 838 | } 839 | .fa-lightbulb-o:before { 840 | content: "\f0eb"; 841 | } 842 | .fa-exchange:before { 843 | content: "\f0ec"; 844 | } 845 | .fa-cloud-download:before { 846 | content: "\f0ed"; 847 | } 848 | .fa-cloud-upload:before { 849 | content: "\f0ee"; 850 | } 851 | .fa-user-md:before { 852 | content: "\f0f0"; 853 | } 854 | .fa-stethoscope:before { 855 | content: "\f0f1"; 856 | } 857 | .fa-suitcase:before { 858 | content: "\f0f2"; 859 | } 860 | .fa-bell-o:before { 861 | content: "\f0a2"; 862 | } 863 | .fa-coffee:before { 864 | content: "\f0f4"; 865 | } 866 | .fa-cutlery:before { 867 | content: "\f0f5"; 868 | } 869 | .fa-file-text-o:before { 870 | content: "\f0f6"; 871 | } 872 | .fa-building-o:before { 873 | content: "\f0f7"; 874 | } 875 | .fa-hospital-o:before { 876 | content: "\f0f8"; 877 | } 878 | .fa-ambulance:before { 879 | content: "\f0f9"; 880 | } 881 | .fa-medkit:before { 882 | content: "\f0fa"; 883 | } 884 | .fa-fighter-jet:before { 885 | content: "\f0fb"; 886 | } 887 | .fa-beer:before { 888 | content: "\f0fc"; 889 | } 890 | .fa-h-square:before { 891 | content: "\f0fd"; 892 | } 893 | .fa-plus-square:before { 894 | content: "\f0fe"; 895 | } 896 | .fa-angle-double-left:before { 897 | content: "\f100"; 898 | } 899 | .fa-angle-double-right:before { 900 | content: "\f101"; 901 | } 902 | .fa-angle-double-up:before { 903 | content: "\f102"; 904 | } 905 | .fa-angle-double-down:before { 906 | content: "\f103"; 907 | } 908 | .fa-angle-left:before { 909 | content: "\f104"; 910 | } 911 | .fa-angle-right:before { 912 | content: "\f105"; 913 | } 914 | .fa-angle-up:before { 915 | content: "\f106"; 916 | } 917 | .fa-angle-down:before { 918 | content: "\f107"; 919 | } 920 | .fa-desktop:before { 921 | content: "\f108"; 922 | } 923 | .fa-laptop:before { 924 | content: "\f109"; 925 | } 926 | .fa-tablet:before { 927 | content: "\f10a"; 928 | } 929 | .fa-mobile-phone:before, 930 | .fa-mobile:before { 931 | content: "\f10b"; 932 | } 933 | .fa-circle-o:before { 934 | content: "\f10c"; 935 | } 936 | .fa-quote-left:before { 937 | content: "\f10d"; 938 | } 939 | .fa-quote-right:before { 940 | content: "\f10e"; 941 | } 942 | .fa-spinner:before { 943 | content: "\f110"; 944 | } 945 | .fa-circle:before { 946 | content: "\f111"; 947 | } 948 | .fa-mail-reply:before, 949 | .fa-reply:before { 950 | content: "\f112"; 951 | } 952 | .fa-github-alt:before { 953 | content: "\f113"; 954 | } 955 | .fa-folder-o:before { 956 | content: "\f114"; 957 | } 958 | .fa-folder-open-o:before { 959 | content: "\f115"; 960 | } 961 | .fa-smile-o:before { 962 | content: "\f118"; 963 | } 964 | .fa-frown-o:before { 965 | content: "\f119"; 966 | } 967 | .fa-meh-o:before { 968 | content: "\f11a"; 969 | } 970 | .fa-gamepad:before { 971 | content: "\f11b"; 972 | } 973 | .fa-keyboard-o:before { 974 | content: "\f11c"; 975 | } 976 | .fa-flag-o:before { 977 | content: "\f11d"; 978 | } 979 | .fa-flag-checkered:before { 980 | content: "\f11e"; 981 | } 982 | .fa-terminal:before { 983 | content: "\f120"; 984 | } 985 | .fa-code:before { 986 | content: "\f121"; 987 | } 988 | .fa-reply-all:before { 989 | content: "\f122"; 990 | } 991 | .fa-mail-reply-all:before { 992 | content: "\f122"; 993 | } 994 | .fa-star-half-empty:before, 995 | .fa-star-half-full:before, 996 | .fa-star-half-o:before { 997 | content: "\f123"; 998 | } 999 | .fa-location-arrow:before { 1000 | content: "\f124"; 1001 | } 1002 | .fa-crop:before { 1003 | content: "\f125"; 1004 | } 1005 | .fa-code-fork:before { 1006 | content: "\f126"; 1007 | } 1008 | .fa-unlink:before, 1009 | .fa-chain-broken:before { 1010 | content: "\f127"; 1011 | } 1012 | .fa-question:before { 1013 | content: "\f128"; 1014 | } 1015 | .fa-info:before { 1016 | content: "\f129"; 1017 | } 1018 | .fa-exclamation:before { 1019 | content: "\f12a"; 1020 | } 1021 | .fa-superscript:before { 1022 | content: "\f12b"; 1023 | } 1024 | .fa-subscript:before { 1025 | content: "\f12c"; 1026 | } 1027 | .fa-eraser:before { 1028 | content: "\f12d"; 1029 | } 1030 | .fa-puzzle-piece:before { 1031 | content: "\f12e"; 1032 | } 1033 | .fa-microphone:before { 1034 | content: "\f130"; 1035 | } 1036 | .fa-microphone-slash:before { 1037 | content: "\f131"; 1038 | } 1039 | .fa-shield:before { 1040 | content: "\f132"; 1041 | } 1042 | .fa-calendar-o:before { 1043 | content: "\f133"; 1044 | } 1045 | .fa-fire-extinguisher:before { 1046 | content: "\f134"; 1047 | } 1048 | .fa-rocket:before { 1049 | content: "\f135"; 1050 | } 1051 | .fa-maxcdn:before { 1052 | content: "\f136"; 1053 | } 1054 | .fa-chevron-circle-left:before { 1055 | content: "\f137"; 1056 | } 1057 | .fa-chevron-circle-right:before { 1058 | content: "\f138"; 1059 | } 1060 | .fa-chevron-circle-up:before { 1061 | content: "\f139"; 1062 | } 1063 | .fa-chevron-circle-down:before { 1064 | content: "\f13a"; 1065 | } 1066 | .fa-html5:before { 1067 | content: "\f13b"; 1068 | } 1069 | .fa-css3:before { 1070 | content: "\f13c"; 1071 | } 1072 | .fa-anchor:before { 1073 | content: "\f13d"; 1074 | } 1075 | .fa-unlock-alt:before { 1076 | content: "\f13e"; 1077 | } 1078 | .fa-bullseye:before { 1079 | content: "\f140"; 1080 | } 1081 | .fa-ellipsis-h:before { 1082 | content: "\f141"; 1083 | } 1084 | .fa-ellipsis-v:before { 1085 | content: "\f142"; 1086 | } 1087 | .fa-rss-square:before { 1088 | content: "\f143"; 1089 | } 1090 | .fa-play-circle:before { 1091 | content: "\f144"; 1092 | } 1093 | .fa-ticket:before { 1094 | content: "\f145"; 1095 | } 1096 | .fa-minus-square:before { 1097 | content: "\f146"; 1098 | } 1099 | .fa-minus-square-o:before { 1100 | content: "\f147"; 1101 | } 1102 | .fa-level-up:before { 1103 | content: "\f148"; 1104 | } 1105 | .fa-level-down:before { 1106 | content: "\f149"; 1107 | } 1108 | .fa-check-square:before { 1109 | content: "\f14a"; 1110 | } 1111 | .fa-pencil-square:before { 1112 | content: "\f14b"; 1113 | } 1114 | .fa-external-link-square:before { 1115 | content: "\f14c"; 1116 | } 1117 | .fa-share-square:before { 1118 | content: "\f14d"; 1119 | } 1120 | .fa-compass:before { 1121 | content: "\f14e"; 1122 | } 1123 | .fa-toggle-down:before, 1124 | .fa-caret-square-o-down:before { 1125 | content: "\f150"; 1126 | } 1127 | .fa-toggle-up:before, 1128 | .fa-caret-square-o-up:before { 1129 | content: "\f151"; 1130 | } 1131 | .fa-toggle-right:before, 1132 | .fa-caret-square-o-right:before { 1133 | content: "\f152"; 1134 | } 1135 | .fa-euro:before, 1136 | .fa-eur:before { 1137 | content: "\f153"; 1138 | } 1139 | .fa-gbp:before { 1140 | content: "\f154"; 1141 | } 1142 | .fa-dollar:before, 1143 | .fa-usd:before { 1144 | content: "\f155"; 1145 | } 1146 | .fa-rupee:before, 1147 | .fa-inr:before { 1148 | content: "\f156"; 1149 | } 1150 | .fa-cny:before, 1151 | .fa-rmb:before, 1152 | .fa-yen:before, 1153 | .fa-jpy:before { 1154 | content: "\f157"; 1155 | } 1156 | .fa-ruble:before, 1157 | .fa-rouble:before, 1158 | .fa-rub:before { 1159 | content: "\f158"; 1160 | } 1161 | .fa-won:before, 1162 | .fa-krw:before { 1163 | content: "\f159"; 1164 | } 1165 | .fa-bitcoin:before, 1166 | .fa-btc:before { 1167 | content: "\f15a"; 1168 | } 1169 | .fa-file:before { 1170 | content: "\f15b"; 1171 | } 1172 | .fa-file-text:before { 1173 | content: "\f15c"; 1174 | } 1175 | .fa-sort-alpha-asc:before { 1176 | content: "\f15d"; 1177 | } 1178 | .fa-sort-alpha-desc:before { 1179 | content: "\f15e"; 1180 | } 1181 | .fa-sort-amount-asc:before { 1182 | content: "\f160"; 1183 | } 1184 | .fa-sort-amount-desc:before { 1185 | content: "\f161"; 1186 | } 1187 | .fa-sort-numeric-asc:before { 1188 | content: "\f162"; 1189 | } 1190 | .fa-sort-numeric-desc:before { 1191 | content: "\f163"; 1192 | } 1193 | .fa-thumbs-up:before { 1194 | content: "\f164"; 1195 | } 1196 | .fa-thumbs-down:before { 1197 | content: "\f165"; 1198 | } 1199 | .fa-youtube-square:before { 1200 | content: "\f166"; 1201 | } 1202 | .fa-youtube:before { 1203 | content: "\f167"; 1204 | } 1205 | .fa-xing:before { 1206 | content: "\f168"; 1207 | } 1208 | .fa-xing-square:before { 1209 | content: "\f169"; 1210 | } 1211 | .fa-youtube-play:before { 1212 | content: "\f16a"; 1213 | } 1214 | .fa-dropbox:before { 1215 | content: "\f16b"; 1216 | } 1217 | .fa-stack-overflow:before { 1218 | content: "\f16c"; 1219 | } 1220 | .fa-instagram:before { 1221 | content: "\f16d"; 1222 | } 1223 | .fa-flickr:before { 1224 | content: "\f16e"; 1225 | } 1226 | .fa-adn:before { 1227 | content: "\f170"; 1228 | } 1229 | .fa-bitbucket:before { 1230 | content: "\f171"; 1231 | } 1232 | .fa-bitbucket-square:before { 1233 | content: "\f172"; 1234 | } 1235 | .fa-tumblr:before { 1236 | content: "\f173"; 1237 | } 1238 | .fa-tumblr-square:before { 1239 | content: "\f174"; 1240 | } 1241 | .fa-long-arrow-down:before { 1242 | content: "\f175"; 1243 | } 1244 | .fa-long-arrow-up:before { 1245 | content: "\f176"; 1246 | } 1247 | .fa-long-arrow-left:before { 1248 | content: "\f177"; 1249 | } 1250 | .fa-long-arrow-right:before { 1251 | content: "\f178"; 1252 | } 1253 | .fa-apple:before { 1254 | content: "\f179"; 1255 | } 1256 | .fa-windows:before { 1257 | content: "\f17a"; 1258 | } 1259 | .fa-android:before { 1260 | content: "\f17b"; 1261 | } 1262 | .fa-linux:before { 1263 | content: "\f17c"; 1264 | } 1265 | .fa-dribbble:before { 1266 | content: "\f17d"; 1267 | } 1268 | .fa-skype:before { 1269 | content: "\f17e"; 1270 | } 1271 | .fa-foursquare:before { 1272 | content: "\f180"; 1273 | } 1274 | .fa-trello:before { 1275 | content: "\f181"; 1276 | } 1277 | .fa-female:before { 1278 | content: "\f182"; 1279 | } 1280 | .fa-male:before { 1281 | content: "\f183"; 1282 | } 1283 | .fa-gittip:before { 1284 | content: "\f184"; 1285 | } 1286 | .fa-sun-o:before { 1287 | content: "\f185"; 1288 | } 1289 | .fa-moon-o:before { 1290 | content: "\f186"; 1291 | } 1292 | .fa-archive:before { 1293 | content: "\f187"; 1294 | } 1295 | .fa-bug:before { 1296 | content: "\f188"; 1297 | } 1298 | .fa-vk:before { 1299 | content: "\f189"; 1300 | } 1301 | .fa-weibo:before { 1302 | content: "\f18a"; 1303 | } 1304 | .fa-renren:before { 1305 | content: "\f18b"; 1306 | } 1307 | .fa-pagelines:before { 1308 | content: "\f18c"; 1309 | } 1310 | .fa-stack-exchange:before { 1311 | content: "\f18d"; 1312 | } 1313 | .fa-arrow-circle-o-right:before { 1314 | content: "\f18e"; 1315 | } 1316 | .fa-arrow-circle-o-left:before { 1317 | content: "\f190"; 1318 | } 1319 | .fa-toggle-left:before, 1320 | .fa-caret-square-o-left:before { 1321 | content: "\f191"; 1322 | } 1323 | .fa-dot-circle-o:before { 1324 | content: "\f192"; 1325 | } 1326 | .fa-wheelchair:before { 1327 | content: "\f193"; 1328 | } 1329 | .fa-vimeo-square:before { 1330 | content: "\f194"; 1331 | } 1332 | .fa-turkish-lira:before, 1333 | .fa-try:before { 1334 | content: "\f195"; 1335 | } 1336 | .fa-plus-square-o:before { 1337 | content: "\f196"; 1338 | } 1339 | -------------------------------------------------------------------------------- /angular-editor/javascripts/simditor/simditor.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BlockquoteButton, BoldButton, Button, CodeButton, CodePopover, Formatter, HrButton, ImageButton, ImagePopover, IndentButton, InputManager, ItalicButton, Keystroke, LinkButton, LinkPopover, ListButton, OrderListButton, OutdentButton, Popover, Selection, Simditor, StrikethroughButton, TableButton, Test, TestPlugin, TitleButton, Toolbar, UnderlineButton, UndoManager, UnorderListButton, Util, _ref, _ref1, _ref10, _ref11, _ref12, _ref13, _ref14, _ref15, _ref16, _ref17, _ref18, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, 3 | __hasProp = {}.hasOwnProperty, 4 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, 5 | __slice = [].slice, 6 | __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; 7 | 8 | Selection = (function(_super) { 9 | __extends(Selection, _super); 10 | 11 | Selection.className = 'Selection'; 12 | 13 | function Selection() { 14 | var args; 15 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 16 | Selection.__super__.constructor.apply(this, args); 17 | this.sel = document.getSelection(); 18 | this.editor = this.widget; 19 | } 20 | 21 | Selection.prototype._init = function() {}; 22 | 23 | Selection.prototype.clear = function() { 24 | var e; 25 | try { 26 | return this.sel.removeAllRanges(); 27 | } catch (_error) { 28 | e = _error; 29 | } 30 | }; 31 | 32 | Selection.prototype.getRange = function() { 33 | if (!this.editor.inputManager.focused || !this.sel.rangeCount) { 34 | return null; 35 | } 36 | return this.sel.getRangeAt(0); 37 | }; 38 | 39 | Selection.prototype.selectRange = function(range) { 40 | this.clear(); 41 | return this.sel.addRange(range); 42 | }; 43 | 44 | Selection.prototype.rangeAtEndOf = function(node, range) { 45 | var endNode, endNodeLength, result, 46 | _this = this; 47 | if (range == null) { 48 | range = this.getRange(); 49 | } 50 | if (!((range != null) && range.collapsed)) { 51 | return; 52 | } 53 | node = $(node)[0]; 54 | endNode = range.endContainer; 55 | endNodeLength = this.editor.util.getNodeLength(endNode); 56 | if (!(range.endOffset === endNodeLength - 1 && $(endNode).contents().last().is('br')) && range.endOffset !== endNodeLength) { 57 | return false; 58 | } 59 | if (node === endNode) { 60 | return true; 61 | } else if (!$.contains(node, endNode)) { 62 | return false; 63 | } 64 | result = true; 65 | $(endNode).parentsUntil(node).addBack().each(function(i, n) { 66 | var $lastChild, nodes; 67 | nodes = $(n).parent().contents().filter(function() { 68 | return !(this !== n && this.nodeType === 3 && !this.nodeValue); 69 | }); 70 | $lastChild = nodes.last(); 71 | if (!($lastChild.get(0) === n || ($lastChild.is('br') && $lastChild.prev().get(0) === n))) { 72 | result = false; 73 | return false; 74 | } 75 | }); 76 | return result; 77 | }; 78 | 79 | Selection.prototype.rangeAtStartOf = function(node, range) { 80 | var result, startNode, 81 | _this = this; 82 | if (range == null) { 83 | range = this.getRange(); 84 | } 85 | if (!((range != null) && range.collapsed)) { 86 | return; 87 | } 88 | node = $(node)[0]; 89 | startNode = range.startContainer; 90 | if (range.startOffset !== 0) { 91 | return false; 92 | } 93 | if (node === startNode) { 94 | return true; 95 | } else if (!$.contains(node, startNode)) { 96 | return false; 97 | } 98 | result = true; 99 | $(startNode).parentsUntil(node).addBack().each(function(i, n) { 100 | var nodes; 101 | nodes = $(n).parent().contents().filter(function() { 102 | return !(this !== n && this.nodeType === 3 && !this.nodeValue); 103 | }); 104 | if (nodes.first().get(0) !== n) { 105 | return result = false; 106 | } 107 | }); 108 | return result; 109 | }; 110 | 111 | Selection.prototype.insertNode = function(node, range) { 112 | if (range == null) { 113 | range = this.getRange(); 114 | } 115 | if (range == null) { 116 | return; 117 | } 118 | node = $(node)[0]; 119 | range.insertNode(node); 120 | return this.setRangeAfter(node, range); 121 | }; 122 | 123 | Selection.prototype.setRangeAfter = function(node, range) { 124 | if (range == null) { 125 | range = this.getRange(); 126 | } 127 | if (range == null) { 128 | return; 129 | } 130 | node = $(node)[0]; 131 | range.setEndAfter(node); 132 | range.collapse(false); 133 | return this.selectRange(range); 134 | }; 135 | 136 | Selection.prototype.setRangeBefore = function(node, range) { 137 | if (range == null) { 138 | range = this.getRange(); 139 | } 140 | if (range == null) { 141 | return; 142 | } 143 | node = $(node)[0]; 144 | range.setEndBefore(node); 145 | range.collapse(false); 146 | return this.selectRange(range); 147 | }; 148 | 149 | Selection.prototype.setRangeAtStartOf = function(node, range) { 150 | if (range == null) { 151 | range = this.getRange(); 152 | } 153 | node = $(node).get(0); 154 | range.setEnd(node, 0); 155 | range.collapse(false); 156 | return this.selectRange(range); 157 | }; 158 | 159 | Selection.prototype.setRangeAtEndOf = function(node, range) { 160 | var $node, contents, lastChild, lastText, nodeLength; 161 | if (range == null) { 162 | range = this.getRange(); 163 | } 164 | $node = $(node); 165 | node = $node.get(0); 166 | if ($node.is('pre')) { 167 | contents = $node.contents(); 168 | if (contents.length > 0) { 169 | lastChild = contents.last(); 170 | lastText = lastChild.text(); 171 | if (lastText.charAt(lastText.length - 1) === '\n') { 172 | range.setEnd(lastChild[0], this.editor.util.getNodeLength(lastChild[0]) - 1); 173 | } else { 174 | range.setEnd(lastChild[0], this.editor.util.getNodeLength(lastChild[0])); 175 | } 176 | } else { 177 | range.setEnd(node, 0); 178 | } 179 | } else { 180 | nodeLength = this.editor.util.getNodeLength(node); 181 | if (node.nodeType !== 3 && nodeLength > 0 && $(node).contents().last().is('br')) { 182 | nodeLength -= 1; 183 | } 184 | range.setEnd(node, nodeLength); 185 | } 186 | range.collapse(false); 187 | return this.selectRange(range); 188 | }; 189 | 190 | Selection.prototype.deleteRangeContents = function(range) { 191 | if (range == null) { 192 | range = this.getRange(); 193 | } 194 | return range.deleteContents(); 195 | }; 196 | 197 | Selection.prototype.breakBlockEl = function(el, range) { 198 | var $el; 199 | if (range == null) { 200 | range = this.getRange(); 201 | } 202 | $el = $(el); 203 | if (!range.collapsed) { 204 | return $el; 205 | } 206 | range.setStartBefore($el.get(0)); 207 | if (range.collapsed) { 208 | return $el; 209 | } 210 | return $el.before(range.extractContents()); 211 | }; 212 | 213 | Selection.prototype.save = function() { 214 | var endCaret, range, startCaret; 215 | if (this._selectionSaved) { 216 | return; 217 | } 218 | range = this.getRange(); 219 | startCaret = $('').addClass('simditor-caret-start'); 220 | endCaret = $('').addClass('simditor-caret-end'); 221 | range.insertNode(startCaret[0]); 222 | range.collapse(false); 223 | range.insertNode(endCaret[0]); 224 | this.clear(); 225 | return this._selectionSaved = true; 226 | }; 227 | 228 | Selection.prototype.restore = function() { 229 | var endCaret, endContainer, endOffset, range, startCaret, startContainer, startOffset; 230 | if (!this._selectionSaved) { 231 | return false; 232 | } 233 | startCaret = this.editor.body.find('.simditor-caret-start'); 234 | endCaret = this.editor.body.find('.simditor-caret-end'); 235 | if (startCaret.length && endCaret.length) { 236 | startContainer = startCaret.parent(); 237 | startOffset = startContainer.contents().index(startCaret); 238 | endContainer = endCaret.parent(); 239 | endOffset = endContainer.contents().index(endCaret); 240 | if (startContainer[0] === endContainer[0]) { 241 | endOffset -= 1; 242 | } 243 | range = document.createRange(); 244 | range.setStart(startContainer.get(0), startOffset); 245 | range.setEnd(endContainer.get(0), endOffset); 246 | startCaret.remove(); 247 | endCaret.remove(); 248 | this.selectRange(range); 249 | if (this.editor.util.browser.firefox) { 250 | this.editor.body.focus(); 251 | } 252 | } else { 253 | startCaret.remove(); 254 | endCaret.remove(); 255 | } 256 | this._selectionSaved = false; 257 | return range; 258 | }; 259 | 260 | return Selection; 261 | 262 | })(Plugin); 263 | 264 | Formatter = (function(_super) { 265 | __extends(Formatter, _super); 266 | 267 | Formatter.className = 'Formatter'; 268 | 269 | function Formatter() { 270 | var args; 271 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 272 | Formatter.__super__.constructor.apply(this, args); 273 | this.editor = this.widget; 274 | } 275 | 276 | Formatter.prototype._init = function() { 277 | var _this = this; 278 | return this.editor.body.on('click', 'a', function(e) { 279 | return false; 280 | }); 281 | }; 282 | 283 | Formatter.prototype._allowedTags = ['br', 'a', 'img', 'b', 'strong', 'i', 'u', 'p', 'ul', 'ol', 'li', 'blockquote', 'pre', 'h1', 'h2', 'h3', 'h4', 'hr']; 284 | 285 | Formatter.prototype._allowedAttributes = { 286 | img: ['src', 'alt', 'width', 'height', 'data-origin-src', 'data-origin-size', 'data-origin-name'], 287 | a: ['href', 'target'], 288 | pre: ['data-lang'], 289 | p: ['data-indent'], 290 | h1: ['data-indent'], 291 | h2: ['data-indent'], 292 | h3: ['data-indent'], 293 | h4: ['data-indent'] 294 | }; 295 | 296 | Formatter.prototype.decorate = function($el) { 297 | if ($el == null) { 298 | $el = this.editor.body; 299 | } 300 | return this.editor.trigger('decorate', [$el]); 301 | }; 302 | 303 | Formatter.prototype.undecorate = function($el) { 304 | if ($el == null) { 305 | $el = this.editor.body.clone(); 306 | } 307 | this.editor.trigger('undecorate', [$el]); 308 | return $.trim($el.html()); 309 | }; 310 | 311 | Formatter.prototype.autolink = function($el) { 312 | var $node, findLinkNode, lastIndex, linkNodes, match, re, replaceEls, text, uri, _i, _len; 313 | if ($el == null) { 314 | $el = this.editor.body; 315 | } 316 | linkNodes = []; 317 | findLinkNode = function($parentNode) { 318 | return $parentNode.contents().each(function(i, node) { 319 | var $node, text; 320 | $node = $(node); 321 | if ($node.is('a') || $node.closest('a', $el).length) { 322 | return; 323 | } 324 | if ($node.contents().length) { 325 | return findLinkNode($node); 326 | } else if ((text = $node.text()) && /https?:\/\/|www\./ig.test(text)) { 327 | return linkNodes.push($node); 328 | } 329 | }); 330 | }; 331 | findLinkNode($el); 332 | re = /(https?:\/\/|www\.)[\w\-\.\?&=\/#%:]+/ig; 333 | for (_i = 0, _len = linkNodes.length; _i < _len; _i++) { 334 | $node = linkNodes[_i]; 335 | text = $node.text(); 336 | replaceEls = []; 337 | match = null; 338 | lastIndex = 0; 339 | while ((match = re.exec(text)) !== null) { 340 | replaceEls.push(document.createTextNode(text.substring(lastIndex, match.index))); 341 | lastIndex = re.lastIndex; 342 | uri = /^(http(s)?:\/\/|\/)/.test(match[0]) ? match[0] : 'http://' + match[0]; 343 | replaceEls.push($('' + match[0] + '')[0]); 344 | } 345 | replaceEls.push(document.createTextNode(text.substring(lastIndex))); 346 | $node.replaceWith($(replaceEls)); 347 | } 348 | return $el; 349 | }; 350 | 351 | Formatter.prototype.format = function($el) { 352 | var $node, blockNode, n, node, _i, _j, _len, _len1, _ref, _ref1; 353 | if ($el == null) { 354 | $el = this.editor.body; 355 | } 356 | if ($el.is(':empty')) { 357 | $el.append('

' + this.editor.util.phBr + '

'); 358 | return $el; 359 | } 360 | _ref = $el.contents(); 361 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 362 | n = _ref[_i]; 363 | this.cleanNode(n, true); 364 | } 365 | _ref1 = $el.contents(); 366 | for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { 367 | node = _ref1[_j]; 368 | $node = $(node); 369 | if ($node.is('br')) { 370 | if (typeof blockNode !== "undefined" && blockNode !== null) { 371 | blockNode = null; 372 | } 373 | $node.remove(); 374 | } else if (this.editor.util.isBlockNode(node) || $node.is('img')) { 375 | if ($node.is('li')) { 376 | if (blockNode && blockNode.is('ul, ol')) { 377 | blockNode.append(node); 378 | } else { 379 | blockNode = $('
    ').insertBefore(node); 380 | blockNode.append(node); 381 | } 382 | } else { 383 | blockNode = null; 384 | } 385 | } else { 386 | if (!blockNode || blockNode.is('ul, ol')) { 387 | blockNode = $('

    ').insertBefore(node); 388 | } 389 | blockNode.append(node); 390 | } 391 | } 392 | return $el; 393 | }; 394 | 395 | Formatter.prototype.cleanNode = function(node, recursive) { 396 | var $node, $p, $td, allowedAttributes, attr, contents, isDecoration, n, text, textNode, _i, _j, _len, _len1, _ref, _ref1, 397 | _this = this; 398 | $node = $(node); 399 | if ($node[0].nodeType === 3) { 400 | text = $node.text().replace(/(\r\n|\n|\r)/gm, ''); 401 | if (text) { 402 | textNode = document.createTextNode(text); 403 | $node.replaceWith(textNode); 404 | } else { 405 | $node.remove(); 406 | } 407 | return; 408 | } 409 | contents = $node.contents(); 410 | isDecoration = $node.is('[class^="simditor-"]'); 411 | if ($node.is(this._allowedTags.join(',')) || isDecoration) { 412 | if ($node.is('a') && $node.find('img').length > 0) { 413 | contents.first().unwrap(); 414 | } 415 | if (!isDecoration) { 416 | allowedAttributes = this._allowedAttributes[$node[0].tagName.toLowerCase()]; 417 | _ref = $.makeArray($node[0].attributes); 418 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 419 | attr = _ref[_i]; 420 | if (!((allowedAttributes != null) && (_ref1 = attr.name, __indexOf.call(allowedAttributes, _ref1) >= 0))) { 421 | $node.removeAttr(attr.name); 422 | } 423 | } 424 | } 425 | } else if ($node[0].nodeType === 1 && !$node.is(':empty')) { 426 | if ($node.is('div, article, dl, header, footer, tr')) { 427 | $node.append('
    '); 428 | contents.first().unwrap(); 429 | } else if ($node.is('table')) { 430 | $p = $('

    '); 431 | $node.find('tr').each(function(i, tr) { 432 | return $p.append($(tr).text() + '
    '); 433 | }); 434 | $node.replaceWith($p); 435 | contents = null; 436 | } else if ($node.is('thead, tfoot')) { 437 | $node.remove(); 438 | contents = null; 439 | } else if ($node.is('th')) { 440 | $td = $('').append($node.contents()); 441 | $node.replaceWith($td); 442 | } else { 443 | contents.first().unwrap(); 444 | } 445 | } else { 446 | $node.remove(); 447 | contents = null; 448 | } 449 | if (recursive && (contents != null) && !$node.is('pre')) { 450 | for (_j = 0, _len1 = contents.length; _j < _len1; _j++) { 451 | n = contents[_j]; 452 | this.cleanNode(n, true); 453 | } 454 | } 455 | return null; 456 | }; 457 | 458 | Formatter.prototype.clearHtml = function(html, lineBreak) { 459 | var container, result, 460 | _this = this; 461 | if (lineBreak == null) { 462 | lineBreak = true; 463 | } 464 | container = $('

    ').append(html); 465 | result = ''; 466 | container.contents().each(function(i, node) { 467 | var $node, contents; 468 | if (node.nodeType === 3) { 469 | return result += node.nodeValue; 470 | } else if (node.nodeType === 1) { 471 | $node = $(node); 472 | contents = $node.contents(); 473 | if (contents.length > 0) { 474 | result += _this.clearHtml(contents); 475 | } 476 | if (lineBreak && $node.is('br, p, div, li, tr, pre, address, artticle, aside, dl, figcaption, footer, h1, h2, h3, h4, header')) { 477 | return result += '\n'; 478 | } 479 | } 480 | }); 481 | return result; 482 | }; 483 | 484 | Formatter.prototype.beautify = function($contents) { 485 | var uselessP, 486 | _this = this; 487 | uselessP = function($el) { 488 | return !!($el.is('p') && !$el.text() && $el.children(':not(br)').length < 1); 489 | }; 490 | return $contents.each(function(i, el) { 491 | var $el; 492 | $el = $(el); 493 | if ($el.is(':not(img, br, col, td, hr, [class^="simditor-"]):empty')) { 494 | $el.remove(); 495 | } 496 | if (uselessP($el)) { 497 | $el.remove(); 498 | } 499 | return $el.find(':not(img, br, col, td, hr, [class^="simditor-"]):empty').remove(); 500 | }); 501 | }; 502 | 503 | return Formatter; 504 | 505 | })(Plugin); 506 | 507 | InputManager = (function(_super) { 508 | __extends(InputManager, _super); 509 | 510 | InputManager.className = 'InputManager'; 511 | 512 | InputManager.prototype.opts = { 513 | pasteImage: false 514 | }; 515 | 516 | function InputManager() { 517 | var args; 518 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 519 | InputManager.__super__.constructor.apply(this, args); 520 | this.editor = this.widget; 521 | if (this.opts.pasteImage && typeof this.opts.pasteImage !== 'string') { 522 | this.opts.pasteImage = 'inline'; 523 | } 524 | } 525 | 526 | InputManager.prototype._modifierKeys = [16, 17, 18, 91, 93, 224]; 527 | 528 | InputManager.prototype._arrowKeys = [37, 38, 39, 40]; 529 | 530 | InputManager.prototype._init = function() { 531 | var _this = this; 532 | this._pasteArea = $('
    ').css({ 533 | width: '1px', 534 | height: '1px', 535 | overflow: 'hidden', 536 | position: 'fixed', 537 | right: '0', 538 | bottom: '100px' 539 | }).attr({ 540 | tabIndex: '-1', 541 | contentEditable: true 542 | }).addClass('simditor-paste-area').appendTo(this.editor.el); 543 | this.editor.on('valuechanged', function() { 544 | return _this.editor.body.find('hr, pre, .simditor-image, .simditor-table').each(function(i, el) { 545 | var $el; 546 | $el = $(el); 547 | if ($el.parent().is('blockquote') || $el.parent()[0] === _this.editor.body[0]) { 548 | if ($el.next().length === 0) { 549 | $('

    ').append(_this.editor.util.phBr).insertAfter($el); 550 | } 551 | if ($el.prev().length === 0) { 552 | return $('

    ').append(_this.editor.util.phBr).insertBefore($el); 553 | } 554 | } 555 | }); 556 | }); 557 | this.editor.body.on('keydown', $.proxy(this._onKeyDown, this)).on('keypress', $.proxy(this._onKeyPress, this)).on('keyup', $.proxy(this._onKeyUp, this)).on('mouseup', $.proxy(this._onMouseUp, this)).on('focus', $.proxy(this._onFocus, this)).on('blur', $.proxy(this._onBlur, this)).on('paste', $.proxy(this._onPaste, this)); 558 | if (this.editor.util.browser.firefox) { 559 | this.addShortcut('cmd+37', function(e) { 560 | e.preventDefault(); 561 | _this.editor.selection.sel.modify('move', 'backward', 'lineboundary'); 562 | return false; 563 | }); 564 | this.addShortcut('cmd+39', function(e) { 565 | e.preventDefault(); 566 | _this.editor.selection.sel.modify('move', 'forward', 'lineboundary'); 567 | return false; 568 | }); 569 | } 570 | if (this.editor.textarea.attr('autofocus')) { 571 | return setTimeout(function() { 572 | return _this.editor.focus(); 573 | }, 0); 574 | } 575 | }; 576 | 577 | InputManager.prototype._onFocus = function(e) { 578 | var _this = this; 579 | this.editor.el.addClass('focus').removeClass('error'); 580 | this.focused = true; 581 | this.lastCaretPosition = null; 582 | this.editor.body.find('.selected').removeClass('selected'); 583 | return setTimeout(function() { 584 | return _this.editor.triggerHandler('focus'); 585 | }, 0); 586 | }; 587 | 588 | InputManager.prototype._onBlur = function(e) { 589 | var _ref; 590 | this.editor.el.removeClass('focus'); 591 | this.editor.sync(); 592 | this.focused = false; 593 | this.lastCaretPosition = (_ref = this.editor.undoManager.currentState()) != null ? _ref.caret : void 0; 594 | return this.editor.triggerHandler('blur'); 595 | }; 596 | 597 | InputManager.prototype._onMouseUp = function(e) { 598 | if ($(e.target).is('img, .simditor-image')) { 599 | return; 600 | } 601 | this.editor.trigger('selectionchanged'); 602 | return this.editor.undoManager.update(); 603 | }; 604 | 605 | InputManager.prototype._onKeyDown = function(e) { 606 | var $blockEl, metaKey, result, shortcutKey, _base, _ref, _ref1, 607 | _this = this; 608 | if (this.editor.triggerHandler(e) === false) { 609 | return false; 610 | } 611 | shortcutKey = this.editor.util.getShortcutKey(e); 612 | if (this._shortcuts[shortcutKey]) { 613 | return this._shortcuts[shortcutKey].call(this, e); 614 | } 615 | if (e.which in this._keystrokeHandlers) { 616 | result = typeof (_base = this._keystrokeHandlers[e.which])['*'] === "function" ? _base['*'](e) : void 0; 617 | if (result) { 618 | this.editor.trigger('valuechanged'); 619 | this.editor.trigger('selectionchanged'); 620 | return false; 621 | } 622 | this.editor.util.traverseUp(function(node) { 623 | var handler, _ref; 624 | if (node.nodeType !== 1) { 625 | return; 626 | } 627 | handler = (_ref = _this._keystrokeHandlers[e.which]) != null ? _ref[node.tagName.toLowerCase()] : void 0; 628 | result = typeof handler === "function" ? handler(e, $(node)) : void 0; 629 | return !result; 630 | }); 631 | if (result) { 632 | this.editor.trigger('valuechanged'); 633 | this.editor.trigger('selectionchanged'); 634 | return false; 635 | } 636 | } 637 | if ((_ref = e.which, __indexOf.call(this._modifierKeys, _ref) >= 0) || (_ref1 = e.which, __indexOf.call(this._arrowKeys, _ref1) >= 0)) { 638 | return; 639 | } 640 | metaKey = this.editor.util.metaKey(e); 641 | $blockEl = this.editor.util.closestBlockEl(); 642 | if (metaKey && e.which === 86) { 643 | return; 644 | } 645 | if (this._typing) { 646 | if (this._typing !== true) { 647 | clearTimeout(this._typing); 648 | } 649 | this._typing = setTimeout(function() { 650 | _this.editor.trigger('valuechanged'); 651 | _this.editor.trigger('selectionchanged'); 652 | return _this._typing = false; 653 | }, 200); 654 | } else { 655 | setTimeout(function() { 656 | _this.editor.trigger('valuechanged'); 657 | return _this.editor.trigger('selectionchanged'); 658 | }, 10); 659 | this._typing = true; 660 | } 661 | return null; 662 | }; 663 | 664 | InputManager.prototype._onKeyPress = function(e) { 665 | var cmd, hook, _i, _len, _ref, _results; 666 | if (this.editor.triggerHandler(e) === false) { 667 | return false; 668 | } 669 | if (e.which === 13) { 670 | this._hookStack.length = 0; 671 | } 672 | if (e.which === 32) { 673 | cmd = this._hookStack.join(''); 674 | this._hookStack.length = 0; 675 | _ref = this._inputHooks; 676 | _results = []; 677 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 678 | hook = _ref[_i]; 679 | if ((hook.cmd instanceof RegExp && hook.cmd.test(cmd)) || hook.cmd === cmd) { 680 | hook.callback(e, hook, cmd); 681 | break; 682 | } else { 683 | _results.push(void 0); 684 | } 685 | } 686 | return _results; 687 | } else if (this._hookKeyMap[e.which]) { 688 | this._hookStack.push(this._hookKeyMap[e.which]); 689 | if (this._hookStack.length > 10) { 690 | return this._hookStack.shift(); 691 | } 692 | } 693 | }; 694 | 695 | InputManager.prototype._onKeyUp = function(e) { 696 | var p, _ref; 697 | if (this.editor.triggerHandler(e) === false) { 698 | return false; 699 | } 700 | if (_ref = e.which, __indexOf.call(this._arrowKeys, _ref) >= 0) { 701 | this.editor.trigger('selectionchanged'); 702 | this.editor.undoManager.update(); 703 | return; 704 | } 705 | if (e.which === 8 && (this.editor.body.is(':empty') || (this.editor.body.children().length === 1 && this.editor.body.children().is('br')))) { 706 | this.editor.body.empty(); 707 | p = $('

    ').append(this.editor.util.phBr).appendTo(this.editor.body); 708 | this.editor.selection.setRangeAtStartOf(p); 709 | } 710 | }; 711 | 712 | InputManager.prototype._onPaste = function(e) { 713 | var $blockEl, cleanPaste, imageFile, pasteItem, uploadOpt, _ref, 714 | _this = this; 715 | if (this.editor.triggerHandler(e) === false) { 716 | return false; 717 | } 718 | if (e.originalEvent.clipboardData && e.originalEvent.clipboardData.items && e.originalEvent.clipboardData.items.length > 0) { 719 | pasteItem = e.originalEvent.clipboardData.items[0]; 720 | if (/^image\//.test(pasteItem.type)) { 721 | imageFile = pasteItem.getAsFile(); 722 | if (!((imageFile != null) && this.opts.pasteImage)) { 723 | return; 724 | } 725 | if (!imageFile.name) { 726 | imageFile.name = "来自剪贴板的图片.png"; 727 | } 728 | uploadOpt = {}; 729 | uploadOpt[this.opts.pasteImage] = true; 730 | if ((_ref = this.editor.uploader) != null) { 731 | _ref.upload(imageFile, uploadOpt); 732 | } 733 | return false; 734 | } 735 | } 736 | $blockEl = this.editor.util.closestBlockEl(); 737 | cleanPaste = $blockEl.is('pre, table'); 738 | this.editor.selection.deleteRangeContents(); 739 | this.editor.selection.save(); 740 | this._pasteArea.focus(); 741 | return setTimeout(function() { 742 | var $img, blob, children, insertPosition, node, pasteContent, range, _i, _j, _len, _len1, _ref1, _ref2; 743 | if (_this._pasteArea.is(':empty')) { 744 | pasteContent = null; 745 | } else if (cleanPaste) { 746 | pasteContent = _this.editor.formatter.clearHtml(_this._pasteArea.html()); 747 | if ($blockEl.is('table')) { 748 | pasteContent = pasteContent.replace(/\n/g, '
    '); 749 | } 750 | } else { 751 | pasteContent = $('

    ').append(_this._pasteArea.contents()); 752 | _this.editor.formatter.format(pasteContent); 753 | _this.editor.formatter.decorate(pasteContent); 754 | _this.editor.formatter.beautify(pasteContent.children()); 755 | pasteContent = pasteContent.contents(); 756 | } 757 | _this._pasteArea.empty(); 758 | range = _this.editor.selection.restore(); 759 | if (_this.editor.triggerHandler('pasting', [pasteContent]) === false) { 760 | return; 761 | } 762 | if (!pasteContent) { 763 | return; 764 | } else if (cleanPaste) { 765 | pasteContent = $('
    ').append(pasteContent); 766 | _ref1 = pasteContent.contents(); 767 | for (_i = 0, _len = _ref1.length; _i < _len; _i++) { 768 | node = _ref1[_i]; 769 | _this.editor.selection.insertNode($(node)[0], range); 770 | } 771 | } else if (pasteContent.length < 1) { 772 | return; 773 | } else if (pasteContent.length === 1) { 774 | if (pasteContent.is('p')) { 775 | children = pasteContent.contents(); 776 | for (_j = 0, _len1 = children.length; _j < _len1; _j++) { 777 | node = children[_j]; 778 | _this.editor.selection.insertNode(node, range); 779 | } 780 | } else if (pasteContent.is('.simditor-image')) { 781 | $img = pasteContent.find('img'); 782 | if (dataURLtoBlob && $img.is('img[src^="data:image/png;base64"]')) { 783 | if (!_this.opts.pasteImage) { 784 | return; 785 | } 786 | blob = dataURLtoBlob($img.attr("src")); 787 | blob.name = "来自剪贴板的图片.png"; 788 | uploadOpt = {}; 789 | uploadOpt[_this.opts.pasteImage] = true; 790 | if ((_ref2 = _this.editor.uploader) != null) { 791 | _ref2.upload(blob, uploadOpt); 792 | } 793 | return; 794 | } else if (imgEl.is('img[src^="webkit-fake-url://"]')) { 795 | return; 796 | } 797 | } else if ($blockEl.is('p') && _this.editor.util.isEmptyNode($blockEl)) { 798 | $blockEl.replaceWith(pasteContent); 799 | _this.editor.selection.setRangeAtEndOf(pasteContent, range); 800 | } else if (pasteContent.is('ul, ol') && $blockEl.is('li')) { 801 | $blockEl.parent().after(pasteContent); 802 | _this.editor.selection.setRangeAtEndOf(pasteContent, range); 803 | } else { 804 | $blockEl.after(pasteContent); 805 | _this.editor.selection.setRangeAtEndOf(pasteContent, range); 806 | } 807 | } else { 808 | if ($blockEl.is('li')) { 809 | $blockEl = $blockEl.parent(); 810 | } 811 | if (_this.editor.selection.rangeAtStartOf($blockEl, range)) { 812 | insertPosition = 'before'; 813 | } else if (_this.editor.selection.rangeAtEndOf($blockEl, range)) { 814 | insertPosition = 'after'; 815 | } else { 816 | _this.editor.selection.breakBlockEl($blockEl, range); 817 | insertPosition = 'before'; 818 | } 819 | $blockEl[insertPosition](pasteContent); 820 | _this.editor.selection.setRangeAtEndOf(pasteContent.last(), range); 821 | } 822 | _this.editor.trigger('valuechanged'); 823 | return _this.editor.trigger('selectionchanged'); 824 | }, 10); 825 | }; 826 | 827 | InputManager.prototype._keystrokeHandlers = {}; 828 | 829 | InputManager.prototype.addKeystrokeHandler = function(key, node, handler) { 830 | if (!this._keystrokeHandlers[key]) { 831 | this._keystrokeHandlers[key] = {}; 832 | } 833 | return this._keystrokeHandlers[key][node] = handler; 834 | }; 835 | 836 | InputManager.prototype._inputHooks = []; 837 | 838 | InputManager.prototype._hookKeyMap = {}; 839 | 840 | InputManager.prototype._hookStack = []; 841 | 842 | InputManager.prototype.addInputHook = function(hookOpt) { 843 | $.extend(this._hookKeyMap, hookOpt.key); 844 | return this._inputHooks.push(hookOpt); 845 | }; 846 | 847 | InputManager.prototype._shortcuts = { 848 | 'cmd+13': function(e) { 849 | this.editor.el.closest('form').find('button:submit').click(); 850 | return false; 851 | } 852 | }; 853 | 854 | InputManager.prototype.addShortcut = function(keys, handler) { 855 | return this._shortcuts[keys] = $.proxy(handler, this); 856 | }; 857 | 858 | return InputManager; 859 | 860 | })(Plugin); 861 | 862 | Keystroke = (function(_super) { 863 | __extends(Keystroke, _super); 864 | 865 | Keystroke.className = 'Keystroke'; 866 | 867 | function Keystroke() { 868 | var args; 869 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 870 | Keystroke.__super__.constructor.apply(this, args); 871 | this.editor = this.widget; 872 | } 873 | 874 | Keystroke.prototype._init = function() { 875 | var _this = this; 876 | if (this.editor.util.browser.safari) { 877 | this.editor.inputManager.addKeystrokeHandler('13', '*', function(e) { 878 | var $br; 879 | if (!e.shiftKey) { 880 | return; 881 | } 882 | $br = $('
    '); 883 | if (_this.editor.selection.rangeAtEndOf($blockEl)) { 884 | _this.editor.selection.insertNode($br); 885 | _this.editor.selection.insertNode($('
    ')); 886 | _this.editor.selection.setRangeBefore($br); 887 | } else { 888 | _this.editor.selection.insertNode($br); 889 | } 890 | return true; 891 | }); 892 | } 893 | this.editor.inputManager.addKeystrokeHandler('8', '*', function(e) { 894 | var $prevBlockEl, $rootBlock; 895 | $rootBlock = _this.editor.util.furthestBlockEl(); 896 | $prevBlockEl = $rootBlock.prev(); 897 | if ($prevBlockEl.is('hr, .simditor-image') && _this.editor.selection.rangeAtStartOf($rootBlock)) { 898 | _this.editor.selection.save(); 899 | $prevBlockEl.remove(); 900 | _this.editor.selection.restore(); 901 | return true; 902 | } 903 | }); 904 | this.editor.inputManager.addKeystrokeHandler('9', '*', function(e) { 905 | if (!_this.editor.opts.tabIndent) { 906 | return; 907 | } 908 | if (e.shiftKey) { 909 | _this.editor.util.outdent(); 910 | } else { 911 | _this.editor.util.indent(); 912 | } 913 | return true; 914 | }); 915 | this.editor.inputManager.addKeystrokeHandler('13', 'li', function(e, $node) { 916 | var $cloneNode, listEl, newBlockEl, newListEl; 917 | $cloneNode = $node.clone(); 918 | $cloneNode.find('ul, ol').remove(); 919 | if (!(_this.editor.util.isEmptyNode($cloneNode) && $node.is(_this.editor.util.closestBlockEl()))) { 920 | return; 921 | } 922 | listEl = $node.parent(); 923 | if ($node.next('li').length > 0) { 924 | if (!_this.editor.util.isEmptyNode($node)) { 925 | return; 926 | } 927 | if (listEl.parent('li').length > 0) { 928 | newBlockEl = $('
  • ').append(_this.editor.util.phBr).insertAfter(listEl.parent('li')); 929 | newListEl = $('<' + listEl[0].tagName + '/>').append($node.nextAll('li')); 930 | newBlockEl.append(newListEl); 931 | } else { 932 | newBlockEl = $('

    ').append(_this.editor.util.phBr).insertAfter(listEl); 933 | newListEl = $('<' + listEl[0].tagName + '/>').append($node.nextAll('li')); 934 | newBlockEl.after(newListEl); 935 | } 936 | } else { 937 | if (listEl.parent('li').length > 0) { 938 | newBlockEl = $('

  • ').insertAfter(listEl.parent('li')); 939 | if ($node.contents().length > 0) { 940 | newBlockEl.append($node.contents()); 941 | } else { 942 | newBlockEl.append(_this.editor.util.phBr); 943 | } 944 | } else { 945 | newBlockEl = $('

    ').append(_this.editor.util.phBr).insertAfter(listEl); 946 | if ($node.children('ul, ol').length > 0) { 947 | newBlockEl.after($node.children('ul, ol')); 948 | } 949 | } 950 | } 951 | if ($node.prev('li').length) { 952 | $node.remove(); 953 | } else { 954 | listEl.remove(); 955 | } 956 | _this.editor.selection.setRangeAtStartOf(newBlockEl); 957 | return true; 958 | }); 959 | this.editor.inputManager.addKeystrokeHandler('13', 'pre', function(e, $node) { 960 | var breakNode, range; 961 | e.preventDefault(); 962 | range = _this.editor.selection.getRange(); 963 | breakNode = null; 964 | range.deleteContents(); 965 | if (!_this.editor.util.browser.msie && _this.editor.selection.rangeAtEndOf($node)) { 966 | breakNode = document.createTextNode('\n\n'); 967 | range.insertNode(breakNode); 968 | range.setEnd(breakNode, 1); 969 | } else { 970 | breakNode = document.createTextNode('\n'); 971 | range.insertNode(breakNode); 972 | range.setStartAfter(breakNode); 973 | } 974 | range.collapse(false); 975 | _this.editor.selection.selectRange(range); 976 | return true; 977 | }); 978 | this.editor.inputManager.addKeystrokeHandler('13', 'blockquote', function(e, $node) { 979 | var $closestBlock; 980 | $closestBlock = _this.editor.util.closestBlockEl(); 981 | if (!($closestBlock.is('p') && !$closestBlock.next().length && _this.editor.util.isEmptyNode($closestBlock))) { 982 | return; 983 | } 984 | $node.after($closestBlock); 985 | _this.editor.selection.setRangeAtStartOf($closestBlock); 986 | return true; 987 | }); 988 | this.editor.inputManager.addKeystrokeHandler('8', 'li', function(e, $node) { 989 | var $br, $childList, $newLi, $prevChildList, $prevNode, $textNode, range, text; 990 | $childList = $node.children('ul, ol'); 991 | $prevNode = $node.prev('li'); 992 | if (!($childList.length > 0 && $prevNode.length > 0)) { 993 | return; 994 | } 995 | text = ''; 996 | $textNode = null; 997 | $node.contents().each(function(i, n) { 998 | if (n.nodeType === 3 && n.nodeValue) { 999 | text += n.nodeValue; 1000 | return $textNode = $(n); 1001 | } 1002 | }); 1003 | if ($textNode && text.length === 1 && _this.editor.util.browser.firefox && !$textNode.next('br').length) { 1004 | $br = $(_this.editor.util.phBr).insertAfter($textNode); 1005 | $textNode.remove(); 1006 | _this.editor.selection.setRangeBefore($br); 1007 | return true; 1008 | } else if (text.length > 0) { 1009 | return; 1010 | } 1011 | range = document.createRange(); 1012 | $prevChildList = $prevNode.children('ul, ol'); 1013 | if ($prevChildList.length > 0) { 1014 | $newLi = $('

  • ').append(_this.editor.util.phBr).appendTo($prevChildList); 1015 | $prevChildList.append($childList.children('li')); 1016 | $node.remove(); 1017 | _this.editor.selection.setRangeAtEndOf($newLi, range); 1018 | } else { 1019 | _this.editor.selection.setRangeAtEndOf($prevNode, range); 1020 | $prevNode.append($childList); 1021 | $node.remove(); 1022 | _this.editor.selection.selectRange(range); 1023 | } 1024 | return true; 1025 | }); 1026 | this.editor.inputManager.addKeystrokeHandler('8', 'pre', function(e, $node) { 1027 | var $newNode, codeStr; 1028 | if (!_this.editor.selection.rangeAtStartOf($node)) { 1029 | return; 1030 | } 1031 | codeStr = $node.html().replace('\n', '
    '); 1032 | $newNode = $('

    ').append(codeStr || _this.editor.util.phBr).insertAfter($node); 1033 | $node.remove(); 1034 | _this.editor.selection.setRangeAtStartOf($newNode); 1035 | return true; 1036 | }); 1037 | return this.editor.inputManager.addKeystrokeHandler('8', 'blockquote', function(e, $node) { 1038 | var $firstChild; 1039 | if (!_this.editor.selection.rangeAtStartOf($node)) { 1040 | return; 1041 | } 1042 | $firstChild = $node.children().first().unwrap(); 1043 | _this.editor.selection.setRangeAtStartOf($firstChild); 1044 | return true; 1045 | }); 1046 | }; 1047 | 1048 | return Keystroke; 1049 | 1050 | })(Plugin); 1051 | 1052 | UndoManager = (function(_super) { 1053 | __extends(UndoManager, _super); 1054 | 1055 | UndoManager.className = 'UndoManager'; 1056 | 1057 | UndoManager.prototype._stack = []; 1058 | 1059 | UndoManager.prototype._index = -1; 1060 | 1061 | UndoManager.prototype._capacity = 50; 1062 | 1063 | UndoManager.prototype._timer = null; 1064 | 1065 | function UndoManager() { 1066 | var args; 1067 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 1068 | UndoManager.__super__.constructor.apply(this, args); 1069 | this.editor = this.widget; 1070 | } 1071 | 1072 | UndoManager.prototype._init = function() { 1073 | var redoShortcut, undoShortcut, 1074 | _this = this; 1075 | if (this.editor.util.os.mac) { 1076 | undoShortcut = 'cmd+90'; 1077 | redoShortcut = 'shift+cmd+90'; 1078 | } else { 1079 | undoShortcut = 'ctrl+90'; 1080 | redoShortcut = 'ctrl+89'; 1081 | } 1082 | this.editor.inputManager.addShortcut(undoShortcut, function(e) { 1083 | e.preventDefault(); 1084 | _this.undo(); 1085 | return false; 1086 | }); 1087 | this.editor.inputManager.addShortcut(redoShortcut, function(e) { 1088 | e.preventDefault(); 1089 | _this.redo(); 1090 | return false; 1091 | }); 1092 | return this.editor.on('valuechanged', function(e, src) { 1093 | if (src === 'undo') { 1094 | return; 1095 | } 1096 | if (_this._timer) { 1097 | clearTimeout(_this._timer); 1098 | _this._timer = null; 1099 | } 1100 | return _this._timer = setTimeout(function() { 1101 | return _this._pushUndoState(); 1102 | }, 200); 1103 | }); 1104 | }; 1105 | 1106 | UndoManager.prototype._pushUndoState = function() { 1107 | var currentState, html; 1108 | currentState = this.currentState(); 1109 | html = this.editor.body.html(); 1110 | if (currentState && currentState.html === html) { 1111 | return; 1112 | } 1113 | this._index += 1; 1114 | this._stack.length = this._index; 1115 | this._stack.push({ 1116 | html: html, 1117 | caret: this.caretPosition() 1118 | }); 1119 | if (this._stack.length > this._capacity) { 1120 | this._stack.shift(); 1121 | return this._index -= 1; 1122 | } 1123 | }; 1124 | 1125 | UndoManager.prototype.currentState = function() { 1126 | if (this._stack.length && this._index > -1) { 1127 | return this._stack[this._index]; 1128 | } else { 1129 | return null; 1130 | } 1131 | }; 1132 | 1133 | UndoManager.prototype.undo = function() { 1134 | var state; 1135 | if (this._index < 1 || this._stack.length < 2) { 1136 | return; 1137 | } 1138 | this.editor.hidePopover(); 1139 | this._index -= 1; 1140 | state = this._stack[this._index]; 1141 | this.editor.body.html(state.html); 1142 | this.caretPosition(state.caret); 1143 | this.editor.find('.selected').removeClass('selected'); 1144 | this.editor.sync(); 1145 | this.editor.trigger('valuechanged', ['undo']); 1146 | return this.editor.trigger('selectionchanged', ['undo']); 1147 | }; 1148 | 1149 | UndoManager.prototype.redo = function() { 1150 | var state; 1151 | if (this._index < 0 || this._stack.length < this._index + 2) { 1152 | return; 1153 | } 1154 | this.editor.hidePopover(); 1155 | this._index += 1; 1156 | state = this._stack[this._index]; 1157 | this.editor.body.html(state.html); 1158 | this.caretPosition(state.caret); 1159 | this.editor.find('.selected').removeClass('selected'); 1160 | this.editor.sync(); 1161 | this.editor.trigger('valuechanged', ['undo']); 1162 | return this.editor.trigger('selectionchanged', ['undo']); 1163 | }; 1164 | 1165 | UndoManager.prototype.update = function() { 1166 | var currentState, html; 1167 | currentState = this.currentState(); 1168 | if (!currentState) { 1169 | return; 1170 | } 1171 | html = this.editor.body.html(); 1172 | currentState.html = html; 1173 | return currentState.caret = this.caretPosition(); 1174 | }; 1175 | 1176 | UndoManager.prototype._getNodeOffset = function(node, index) { 1177 | var $parent, merging, offset, 1178 | _this = this; 1179 | if (index) { 1180 | $parent = $(node); 1181 | } else { 1182 | $parent = $(node).parent(); 1183 | } 1184 | offset = 0; 1185 | merging = false; 1186 | $parent.contents().each(function(i, child) { 1187 | if (index === i || node === child) { 1188 | return false; 1189 | } 1190 | if (child.nodeType === 3) { 1191 | if (!merging) { 1192 | offset += 1; 1193 | merging = true; 1194 | } 1195 | } else { 1196 | offset += 1; 1197 | merging = false; 1198 | } 1199 | return null; 1200 | }); 1201 | return offset; 1202 | }; 1203 | 1204 | UndoManager.prototype._getNodePosition = function(node, offset) { 1205 | var position, prevNode, 1206 | _this = this; 1207 | if (node.nodeType === 3) { 1208 | prevNode = node.previousSibling; 1209 | while (prevNode && prevNode.nodeType === 3) { 1210 | node = prevNode; 1211 | offset += this.editor.util.getNodeLength(prevNode); 1212 | prevNode = prevNode.previousSibling; 1213 | } 1214 | } else { 1215 | offset = this._getNodeOffset(node, offset); 1216 | } 1217 | position = []; 1218 | position.unshift(offset); 1219 | this.editor.util.traverseUp(function(n) { 1220 | return position.unshift(_this._getNodeOffset(n)); 1221 | }, node); 1222 | return position; 1223 | }; 1224 | 1225 | UndoManager.prototype._getNodeByPosition = function(position) { 1226 | var child, childNodes, i, node, offset, _i, _len, _ref; 1227 | node = this.editor.body[0]; 1228 | _ref = position.slice(0, position.length - 1); 1229 | for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { 1230 | offset = _ref[i]; 1231 | childNodes = node.childNodes; 1232 | if (offset > childNodes.length - 1) { 1233 | if (i === position.length - 2 && $(node).is('pre')) { 1234 | child = document.createTextNode(''); 1235 | node.appendChild(child); 1236 | childNodes = node.childNodes; 1237 | } else { 1238 | node = null; 1239 | break; 1240 | } 1241 | } 1242 | node = childNodes[offset]; 1243 | } 1244 | return node; 1245 | }; 1246 | 1247 | UndoManager.prototype.caretPosition = function(caret) { 1248 | var endContainer, endOffset, range, startContainer, startOffset; 1249 | if (!caret) { 1250 | range = this.editor.selection.getRange(); 1251 | if (!(this.editor.inputManager.focused && (range != null))) { 1252 | return {}; 1253 | } 1254 | caret = { 1255 | start: [], 1256 | end: null, 1257 | collapsed: true 1258 | }; 1259 | caret.start = this._getNodePosition(range.startContainer, range.startOffset); 1260 | if (!range.collapsed) { 1261 | caret.end = this._getNodePosition(range.endContainer, range.endOffset); 1262 | caret.collapsed = false; 1263 | } 1264 | return caret; 1265 | } else { 1266 | if (!this.editor.inputManager.focused) { 1267 | this.editor.body.focus(); 1268 | } 1269 | if (!caret.start) { 1270 | this.editor.body.blur(); 1271 | return; 1272 | } 1273 | startContainer = this._getNodeByPosition(caret.start); 1274 | startOffset = caret.start[caret.start.length - 1]; 1275 | if (caret.collapsed) { 1276 | endContainer = startContainer; 1277 | endOffset = startOffset; 1278 | } else { 1279 | endContainer = this._getNodeByPosition(caret.end); 1280 | endOffset = caret.start[caret.start.length - 1]; 1281 | } 1282 | if (!startContainer || !endContainer) { 1283 | throw new Error('simditor: invalid caret state'); 1284 | return; 1285 | } 1286 | range = document.createRange(); 1287 | range.setStart(startContainer, startOffset); 1288 | range.setEnd(endContainer, endOffset); 1289 | return this.editor.selection.selectRange(range); 1290 | } 1291 | }; 1292 | 1293 | return UndoManager; 1294 | 1295 | })(Plugin); 1296 | 1297 | Util = (function(_super) { 1298 | __extends(Util, _super); 1299 | 1300 | Util.className = 'Util'; 1301 | 1302 | function Util() { 1303 | var args; 1304 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 1305 | Util.__super__.constructor.apply(this, args); 1306 | if (this.browser.msie && this.browser.version < 11) { 1307 | this.phBr = ''; 1308 | } 1309 | this.editor = this.widget; 1310 | } 1311 | 1312 | Util.prototype._init = function() {}; 1313 | 1314 | Util.prototype.phBr = '
    '; 1315 | 1316 | Util.prototype.os = (function() { 1317 | if (/Mac/.test(navigator.appVersion)) { 1318 | return { 1319 | mac: true 1320 | }; 1321 | } else if (/Linux/.test(navigator.appVersion)) { 1322 | return { 1323 | linux: true 1324 | }; 1325 | } else if (/Win/.test(navigator.appVersion)) { 1326 | return { 1327 | win: true 1328 | }; 1329 | } else if (/X11/.test(navigator.appVersion)) { 1330 | return { 1331 | unix: true 1332 | }; 1333 | } else { 1334 | return {}; 1335 | } 1336 | })(); 1337 | 1338 | Util.prototype.browser = (function() { 1339 | var chrome, firefox, ie, safari, ua; 1340 | ua = navigator.userAgent; 1341 | ie = /(msie|trident)/i.test(ua); 1342 | chrome = /chrome|crios/i.test(ua); 1343 | safari = /safari/i.test(ua) && !chrome; 1344 | firefox = /firefox/i.test(ua); 1345 | if (ie) { 1346 | return { 1347 | msie: true, 1348 | version: ua.match(/(msie |rv:)(\d+(\.\d+)?)/i)[2] 1349 | }; 1350 | } else if (chrome) { 1351 | return { 1352 | webkit: true, 1353 | chrome: true, 1354 | version: ua.match(/(?:chrome|crios)\/(\d+(\.\d+)?)/i)[1] 1355 | }; 1356 | } else if (safari) { 1357 | return { 1358 | webkit: true, 1359 | safari: true, 1360 | version: ua.match(/version\/(\d+(\.\d+)?)/i)[1] 1361 | }; 1362 | } else if (firefox) { 1363 | return { 1364 | mozilla: true, 1365 | firefox: true, 1366 | version: ua.match(/firefox\/(\d+(\.\d+)?)/i)[1] 1367 | }; 1368 | } else { 1369 | return {}; 1370 | } 1371 | })(); 1372 | 1373 | Util.prototype.metaKey = function(e) { 1374 | var isMac; 1375 | isMac = /Mac/.test(navigator.userAgent); 1376 | if (isMac) { 1377 | return e.metaKey; 1378 | } else { 1379 | return e.ctrlKey; 1380 | } 1381 | }; 1382 | 1383 | Util.prototype.isEmptyNode = function(node) { 1384 | var $node; 1385 | $node = $(node); 1386 | return !$node.text() && !$node.find(':not(br, span)').length; 1387 | }; 1388 | 1389 | Util.prototype.isBlockNode = function(node) { 1390 | node = $(node)[0]; 1391 | if (!node || node.nodeType === 3) { 1392 | return false; 1393 | } 1394 | return /^(div|p|ul|ol|li|blockquote|hr|pre|h1|h2|h3|h4|table)$/.test(node.nodeName.toLowerCase()); 1395 | }; 1396 | 1397 | Util.prototype.closestBlockEl = function(node) { 1398 | var $node, blockEl, range, 1399 | _this = this; 1400 | if (node == null) { 1401 | range = this.editor.selection.getRange(); 1402 | node = range != null ? range.commonAncestorContainer : void 0; 1403 | } 1404 | $node = $(node); 1405 | if (!$node.length) { 1406 | return null; 1407 | } 1408 | blockEl = $node.parentsUntil(this.editor.body).addBack(); 1409 | blockEl = blockEl.filter(function(i) { 1410 | return _this.isBlockNode(blockEl.eq(i)); 1411 | }); 1412 | if (blockEl.length) { 1413 | return blockEl.last(); 1414 | } else { 1415 | return null; 1416 | } 1417 | }; 1418 | 1419 | Util.prototype.furthestNode = function(node, filter) { 1420 | var $node, blockEl, range, 1421 | _this = this; 1422 | if (node == null) { 1423 | range = this.editor.selection.getRange(); 1424 | node = range != null ? range.commonAncestorContainer : void 0; 1425 | } 1426 | $node = $(node); 1427 | if (!$node.length) { 1428 | return null; 1429 | } 1430 | blockEl = $node.parentsUntil(this.editor.body).addBack(); 1431 | blockEl = blockEl.filter(function(i) { 1432 | var $n; 1433 | $n = blockEl.eq(i); 1434 | if ($.isFunction(filter)) { 1435 | return filter($n); 1436 | } else { 1437 | return $n.is(filter); 1438 | } 1439 | }); 1440 | if (blockEl.length) { 1441 | return blockEl.first(); 1442 | } else { 1443 | return null; 1444 | } 1445 | }; 1446 | 1447 | Util.prototype.furthestBlockEl = function(node) { 1448 | return this.furthestNode(node, this.isBlockNode); 1449 | }; 1450 | 1451 | Util.prototype.getNodeLength = function(node) { 1452 | switch (node.nodeType) { 1453 | case 7: 1454 | case 10: 1455 | return 0; 1456 | case 3: 1457 | case 8: 1458 | return node.length; 1459 | default: 1460 | return node.childNodes.length; 1461 | } 1462 | }; 1463 | 1464 | Util.prototype.traverseUp = function(callback, node) { 1465 | var n, nodes, range, result, _i, _len, _results; 1466 | if (node == null) { 1467 | range = this.editor.selection.getRange(); 1468 | node = range != null ? range.commonAncestorContainer : void 0; 1469 | } 1470 | if ((node == null) || !$.contains(this.editor.body[0], node)) { 1471 | return false; 1472 | } 1473 | nodes = $(node).parentsUntil(this.editor.body).get(); 1474 | nodes.unshift(node); 1475 | _results = []; 1476 | for (_i = 0, _len = nodes.length; _i < _len; _i++) { 1477 | n = nodes[_i]; 1478 | result = callback(n); 1479 | if (result === false) { 1480 | break; 1481 | } else { 1482 | _results.push(void 0); 1483 | } 1484 | } 1485 | return _results; 1486 | }; 1487 | 1488 | Util.prototype.getShortcutKey = function(e) { 1489 | var shortcutName; 1490 | shortcutName = []; 1491 | if (e.shiftKey) { 1492 | shortcutName.push('shift'); 1493 | } 1494 | if (e.ctrlKey) { 1495 | shortcutName.push('ctrl'); 1496 | } 1497 | if (e.altKey) { 1498 | shortcutName.push('alt'); 1499 | } 1500 | if (e.metaKey) { 1501 | shortcutName.push('cmd'); 1502 | } 1503 | shortcutName.push(e.which); 1504 | return shortcutName.join('+'); 1505 | }; 1506 | 1507 | Util.prototype.indent = function() { 1508 | var $blockEl, $childList, $nextTd, $parentLi, $td, indentLevel, range, spaceNode, tagName, _ref; 1509 | $blockEl = this.editor.util.closestBlockEl(); 1510 | if (!($blockEl && $blockEl.length > 0)) { 1511 | return false; 1512 | } 1513 | if ($blockEl.is('pre')) { 1514 | spaceNode = document.createTextNode('\u00A0\u00A0'); 1515 | this.editor.selection.insertNode(spaceNode); 1516 | } else if ($blockEl.is('li')) { 1517 | $parentLi = $blockEl.prev('li'); 1518 | if ($parentLi.length < 1) { 1519 | return false; 1520 | } 1521 | this.editor.selection.save(); 1522 | tagName = $blockEl.parent()[0].tagName; 1523 | $childList = $parentLi.children('ul, ol'); 1524 | if ($childList.length > 0) { 1525 | $childList.append($blockEl); 1526 | } else { 1527 | $('<' + tagName + '/>').append($blockEl).appendTo($parentLi); 1528 | } 1529 | this.editor.selection.restore(); 1530 | } else if ($blockEl.is('p, h1, h2, h3, h4')) { 1531 | indentLevel = (_ref = $blockEl.attr('data-indent')) != null ? _ref : 0; 1532 | indentLevel = indentLevel * 1 + 1; 1533 | if (indentLevel > 10) { 1534 | indentLevel = 10; 1535 | } 1536 | $blockEl.attr('data-indent', indentLevel); 1537 | } else if ($blockEl.is('table')) { 1538 | range = this.editor.selection.getRange(); 1539 | $td = $(range.commonAncestorContainer).closest('td'); 1540 | $nextTd = $td.next('td'); 1541 | if (!($nextTd.length > 0)) { 1542 | $nextTd = $td.parent('tr').next('tr').find('td:first'); 1543 | } 1544 | if (!($td.length > 0 && $nextTd.length > 0)) { 1545 | return false; 1546 | } 1547 | this.editor.selection.setRangeAtEndOf($nextTd); 1548 | } else { 1549 | spaceNode = document.createTextNode('\u00A0\u00A0\u00A0\u00A0'); 1550 | this.editor.selection.insertNode(spaceNode); 1551 | } 1552 | this.editor.trigger('valuechanged'); 1553 | this.editor.trigger('selectionchanged'); 1554 | return true; 1555 | }; 1556 | 1557 | Util.prototype.outdent = function() { 1558 | var $blockEl, $parent, $parentLi, $prevTd, $td, button, indentLevel, range, _ref; 1559 | $blockEl = this.editor.util.closestBlockEl(); 1560 | if (!($blockEl && $blockEl.length > 0)) { 1561 | return false; 1562 | } 1563 | if ($blockEl.is('pre')) { 1564 | return false; 1565 | } else if ($blockEl.is('li')) { 1566 | $parent = $blockEl.parent(); 1567 | $parentLi = $parent.parent('li'); 1568 | if ($parentLi.length < 1) { 1569 | button = this.editor.toolbar.findButton($parent[0].tagName.toLowerCase()); 1570 | if (button != null) { 1571 | button.command(); 1572 | } 1573 | return false; 1574 | } 1575 | this.editor.selection.save(); 1576 | if ($blockEl.next('li').length > 0) { 1577 | $('<' + $parent[0].tagName + '/>').append($blockEl.nextAll('li')).appendTo($blockEl); 1578 | } 1579 | $blockEl.insertAfter($parentLi); 1580 | if ($parent.children('li').length < 1) { 1581 | $parent.remove(); 1582 | } 1583 | this.editor.selection.restore(); 1584 | } else if ($blockEl.is('p, h1, h2, h3, h4')) { 1585 | indentLevel = (_ref = $blockEl.attr('data-indent')) != null ? _ref : 0; 1586 | indentLevel = indentLevel * 1 - 1; 1587 | if (indentLevel < 0) { 1588 | indentLevel = 0; 1589 | } 1590 | $blockEl.attr('data-indent', indentLevel); 1591 | } else if ($blockEl.is('table')) { 1592 | range = this.editor.selection.getRange(); 1593 | $td = $(range.commonAncestorContainer).closest('td'); 1594 | $prevTd = $td.prev('td'); 1595 | if (!($prevTd.length > 0)) { 1596 | $prevTd = $td.parent('tr').prev('tr').find('td:last'); 1597 | } 1598 | if (!($td.length > 0 && $prevTd.length > 0)) { 1599 | return false; 1600 | } 1601 | this.editor.selection.setRangeAtEndOf($prevTd); 1602 | } else { 1603 | return false; 1604 | } 1605 | this.editor.trigger('valuechanged'); 1606 | this.editor.trigger('selectionchanged'); 1607 | return true; 1608 | }; 1609 | 1610 | return Util; 1611 | 1612 | })(Plugin); 1613 | 1614 | Toolbar = (function(_super) { 1615 | __extends(Toolbar, _super); 1616 | 1617 | Toolbar.className = 'Toolbar'; 1618 | 1619 | Toolbar.prototype.opts = { 1620 | toolbar: true, 1621 | toolbarFloat: true 1622 | }; 1623 | 1624 | Toolbar.prototype._tpl = { 1625 | wrapper: '

      ', 1626 | separator: '
    • ' 1627 | }; 1628 | 1629 | function Toolbar() { 1630 | var args; 1631 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 1632 | Toolbar.__super__.constructor.apply(this, args); 1633 | this.editor = this.widget; 1634 | } 1635 | 1636 | Toolbar.prototype._init = function() { 1637 | var _this = this; 1638 | if (!this.opts.toolbar) { 1639 | return; 1640 | } 1641 | if (!$.isArray(this.opts.toolbar)) { 1642 | this.opts.toolbar = ['bold', 'italic', 'underline', 'strikethrough', '|', 'ol', 'ul', 'blockquote', 'code', '|', 'link', 'image', '|', 'indent', 'outdent']; 1643 | } 1644 | this._render(); 1645 | this.list.on('click', function(e) { 1646 | return false; 1647 | }); 1648 | this.wrapper.on('mousedown', function(e) { 1649 | return _this.list.find('.menu-on').removeClass('.menu-on'); 1650 | }); 1651 | $(document).on('mousedown.simditor', function(e) { 1652 | return _this.list.find('.menu-on').removeClass('.menu-on'); 1653 | }); 1654 | if (this.opts.toolbarFloat) { 1655 | this.wrapper.width(this.wrapper.outerWidth()); 1656 | this.wrapper.css('left', this.wrapper.offset().left); 1657 | $(window).on('scroll.simditor-' + this.editor.id, function(e) { 1658 | var bottomEdge, scrollTop, topEdge; 1659 | topEdge = _this.editor.wrapper.offset().top; 1660 | bottomEdge = topEdge + _this.editor.wrapper.outerHeight() - 80; 1661 | scrollTop = $(document).scrollTop(); 1662 | if (scrollTop <= topEdge || scrollTop >= bottomEdge) { 1663 | return _this.editor.wrapper.removeClass('toolbar-floating'); 1664 | } else { 1665 | return _this.editor.wrapper.addClass('toolbar-floating'); 1666 | } 1667 | }); 1668 | } 1669 | this.editor.on('selectionchanged focus', function() { 1670 | return _this.toolbarStatus(); 1671 | }); 1672 | this.editor.on('destroy', function() { 1673 | return _this.buttons.length = 0; 1674 | }); 1675 | return $(document).on('mousedown.simditor-' + this.editor.id, function(e) { 1676 | return _this.list.find('li.menu-on').removeClass('menu-on'); 1677 | }); 1678 | }; 1679 | 1680 | Toolbar.prototype._render = function() { 1681 | var name, _i, _len, _ref, _results; 1682 | this.buttons = []; 1683 | this.wrapper = $(this._tpl.wrapper).prependTo(this.editor.wrapper); 1684 | this.list = this.wrapper.find('ul'); 1685 | _ref = this.opts.toolbar; 1686 | _results = []; 1687 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 1688 | name = _ref[_i]; 1689 | if (name === '|') { 1690 | $(this._tpl.separator).appendTo(this.list); 1691 | continue; 1692 | } 1693 | if (!this.constructor.buttons[name]) { 1694 | throw new Error('simditor: invalid toolbar button "' + name + '"'); 1695 | continue; 1696 | } 1697 | _results.push(this.buttons.push(new this.constructor.buttons[name](this.editor))); 1698 | } 1699 | return _results; 1700 | }; 1701 | 1702 | Toolbar.prototype.toolbarStatus = function(name) { 1703 | var buttons, 1704 | _this = this; 1705 | if (!this.editor.inputManager.focused) { 1706 | return; 1707 | } 1708 | buttons = this.buttons.slice(0); 1709 | return this.editor.util.traverseUp(function(node) { 1710 | var button, i, removeButtons, _i, _j, _len, _len1; 1711 | removeButtons = []; 1712 | for (i = _i = 0, _len = buttons.length; _i < _len; i = ++_i) { 1713 | button = buttons[i]; 1714 | if ((name != null) && button.name !== name) { 1715 | continue; 1716 | } 1717 | if (!button.status || button.status($(node)) === true) { 1718 | removeButtons.push(button); 1719 | } 1720 | } 1721 | for (_j = 0, _len1 = removeButtons.length; _j < _len1; _j++) { 1722 | button = removeButtons[_j]; 1723 | i = $.inArray(button, buttons); 1724 | buttons.splice(i, 1); 1725 | } 1726 | if (buttons.length === 0) { 1727 | return false; 1728 | } 1729 | }); 1730 | }; 1731 | 1732 | Toolbar.prototype.findButton = function(name) { 1733 | var button; 1734 | button = this.list.find('.toolbar-item-' + name).data('button'); 1735 | return button != null ? button : null; 1736 | }; 1737 | 1738 | Toolbar.addButton = function(btn) { 1739 | return this.buttons[btn.prototype.name] = btn; 1740 | }; 1741 | 1742 | Toolbar.buttons = {}; 1743 | 1744 | return Toolbar; 1745 | 1746 | })(Plugin); 1747 | 1748 | Simditor = (function(_super) { 1749 | __extends(Simditor, _super); 1750 | 1751 | function Simditor() { 1752 | _ref = Simditor.__super__.constructor.apply(this, arguments); 1753 | return _ref; 1754 | } 1755 | 1756 | Simditor.connect(Util); 1757 | 1758 | Simditor.connect(UndoManager); 1759 | 1760 | Simditor.connect(InputManager); 1761 | 1762 | Simditor.connect(Keystroke); 1763 | 1764 | Simditor.connect(Formatter); 1765 | 1766 | Simditor.connect(Selection); 1767 | 1768 | Simditor.connect(Toolbar); 1769 | 1770 | Simditor.count = 0; 1771 | 1772 | Simditor.prototype.opts = { 1773 | textarea: null, 1774 | placeholder: '', 1775 | defaultImage: 'images/image.png', 1776 | params: {}, 1777 | upload: false, 1778 | tabIndent: true 1779 | }; 1780 | 1781 | Simditor.prototype._init = function() { 1782 | var editor, form, uploadOpts, _ref1, 1783 | _this = this; 1784 | this.textarea = $(this.opts.textarea); 1785 | this.opts.placeholder = (_ref1 = this.opts.placeholder) != null ? _ref1 : this.textarea.attr('placeholder'); 1786 | if (!this.textarea.length) { 1787 | throw new Error('simditor: param textarea is required.'); 1788 | return; 1789 | } 1790 | editor = this.textarea.data('simditor'); 1791 | if (editor != null) { 1792 | editor.destroy(); 1793 | } 1794 | this.id = ++Simditor.count; 1795 | this._render(); 1796 | if (this.opts.upload && (typeof simple !== "undefined" && simple !== null ? simple.uploader : void 0)) { 1797 | uploadOpts = typeof this.opts.upload === 'object' ? this.opts.upload : {}; 1798 | this.uploader = simple.uploader(uploadOpts); 1799 | } 1800 | form = this.textarea.closest('form'); 1801 | if (form.length) { 1802 | form.on('submit.simditor-' + this.id, function() { 1803 | return _this.sync(); 1804 | }); 1805 | form.on('reset.simditor-' + this.id, function() { 1806 | return _this.setValue(''); 1807 | }); 1808 | } 1809 | return this.on('pluginconnected', function() { 1810 | _this.setValue(_this.textarea.val() || ''); 1811 | if (_this.opts.placeholder) { 1812 | _this.on('valuechanged', function() { 1813 | return _this._placeholder(); 1814 | }); 1815 | } 1816 | return setTimeout(function() { 1817 | return _this.trigger('valuechanged'); 1818 | }, 0); 1819 | }); 1820 | }; 1821 | 1822 | Simditor.prototype._tpl = "
      \n
      \n
      \n
      \n
      \n
      \n
      "; 1823 | 1824 | Simditor.prototype._render = function() { 1825 | var key, val, _ref1, _results; 1826 | this.el = $(this._tpl).insertBefore(this.textarea); 1827 | this.wrapper = this.el.find('.simditor-wrapper'); 1828 | this.body = this.wrapper.find('.simditor-body'); 1829 | this.placeholderEl = this.wrapper.find('.simditor-placeholder').append(this.opts.placeholder); 1830 | this.el.append(this.textarea).data('simditor', this); 1831 | this.textarea.data('simditor', this).hide().blur(); 1832 | this.body.attr('tabindex', this.textarea.attr('tabindex')); 1833 | if (this.util.os.mac) { 1834 | this.el.addClass('simditor-mac'); 1835 | } else if (this.util.os.linux) { 1836 | this.el.addClass('simditor-linux'); 1837 | } 1838 | if (this.opts.params) { 1839 | _ref1 = this.opts.params; 1840 | _results = []; 1841 | for (key in _ref1) { 1842 | val = _ref1[key]; 1843 | _results.push($('', { 1844 | type: 'hidden', 1845 | name: key, 1846 | value: val 1847 | }).insertAfter(this.textarea)); 1848 | } 1849 | return _results; 1850 | } 1851 | }; 1852 | 1853 | Simditor.prototype._placeholder = function() { 1854 | var children, _ref1; 1855 | children = this.body.children(); 1856 | if (children.length === 0 || (children.length === 1 && this.util.isEmptyNode(children) && ((_ref1 = children.data('indent')) != null ? _ref1 : 0) < 1)) { 1857 | return this.placeholderEl.show(); 1858 | } else { 1859 | return this.placeholderEl.hide(); 1860 | } 1861 | }; 1862 | 1863 | Simditor.prototype.setValue = function(val) { 1864 | this.textarea.val(val); 1865 | this.body.html(val); 1866 | this.formatter.format(); 1867 | return this.formatter.decorate(); 1868 | }; 1869 | 1870 | Simditor.prototype.getValue = function() { 1871 | return this.sync(); 1872 | }; 1873 | 1874 | Simditor.prototype.sync = function() { 1875 | var children, cloneBody, emptyP, firstP, lastP, val; 1876 | cloneBody = this.body.clone(); 1877 | this.formatter.undecorate(cloneBody); 1878 | this.formatter.format(cloneBody); 1879 | this.formatter.autolink(cloneBody); 1880 | children = cloneBody.children(); 1881 | lastP = children.last('p'); 1882 | firstP = children.first('p'); 1883 | while (lastP.is('p') && !lastP.text() && !lastP.find('img').length) { 1884 | emptyP = lastP; 1885 | lastP = lastP.prev('p'); 1886 | emptyP.remove(); 1887 | } 1888 | while (firstP.is('p') && !firstP.text() && !firstP.find('img').length) { 1889 | emptyP = firstP; 1890 | firstP = lastP.next('p'); 1891 | emptyP.remove(); 1892 | } 1893 | val = $.trim(cloneBody.html()); 1894 | this.textarea.val(val); 1895 | return val; 1896 | }; 1897 | 1898 | Simditor.prototype.focus = function() { 1899 | var $blockEl, range; 1900 | $blockEl = this.body.find('p, li, pre, h1, h2, h3, h4, td').first(); 1901 | if (!($blockEl.length > 0)) { 1902 | return; 1903 | } 1904 | range = document.createRange(); 1905 | this.selection.setRangeAtStartOf($blockEl, range); 1906 | return this.body.focus(); 1907 | }; 1908 | 1909 | Simditor.prototype.blur = function() { 1910 | return this.body.blur(); 1911 | }; 1912 | 1913 | Simditor.prototype.hidePopover = function() { 1914 | var _this = this; 1915 | return this.wrapper.find('.simditor-popover').each(function(i, popover) { 1916 | popover = $(popover).data('popover'); 1917 | if (popover.active) { 1918 | return popover.hide(); 1919 | } 1920 | }); 1921 | }; 1922 | 1923 | Simditor.prototype.destroy = function() { 1924 | this.triggerHandler('destroy'); 1925 | this.textarea.closest('form').off('.simditor .simditor-' + this.id); 1926 | this.selection.clear(); 1927 | this.textarea.insertBefore(this.el).hide().val('').removeData('simditor'); 1928 | this.el.remove(); 1929 | $(document).off('.simditor-' + this.id); 1930 | $(window).off('.simditor-' + this.id); 1931 | return this.off(); 1932 | }; 1933 | 1934 | return Simditor; 1935 | 1936 | })(Widget); 1937 | 1938 | window.Simditor = Simditor; 1939 | 1940 | TestPlugin = (function(_super) { 1941 | __extends(TestPlugin, _super); 1942 | 1943 | function TestPlugin() { 1944 | _ref1 = TestPlugin.__super__.constructor.apply(this, arguments); 1945 | return _ref1; 1946 | } 1947 | 1948 | return TestPlugin; 1949 | 1950 | })(Plugin); 1951 | 1952 | Test = (function(_super) { 1953 | __extends(Test, _super); 1954 | 1955 | function Test() { 1956 | _ref2 = Test.__super__.constructor.apply(this, arguments); 1957 | return _ref2; 1958 | } 1959 | 1960 | Test.connect(TestPlugin); 1961 | 1962 | return Test; 1963 | 1964 | })(Widget); 1965 | 1966 | Button = (function(_super) { 1967 | __extends(Button, _super); 1968 | 1969 | Button.prototype._tpl = { 1970 | item: '
    • ', 1971 | menuWrapper: '
      ', 1972 | menuItem: '
    • ', 1973 | separator: '
    • ' 1974 | }; 1975 | 1976 | Button.prototype.name = ''; 1977 | 1978 | Button.prototype.icon = ''; 1979 | 1980 | Button.prototype.title = ''; 1981 | 1982 | Button.prototype.text = ''; 1983 | 1984 | Button.prototype.htmlTag = ''; 1985 | 1986 | Button.prototype.disableTag = ''; 1987 | 1988 | Button.prototype.menu = false; 1989 | 1990 | Button.prototype.active = false; 1991 | 1992 | Button.prototype.disabled = false; 1993 | 1994 | Button.prototype.needFocus = true; 1995 | 1996 | Button.prototype.shortcut = null; 1997 | 1998 | function Button(editor) { 1999 | var tag, _i, _len, _ref3, 2000 | _this = this; 2001 | this.editor = editor; 2002 | this.render(); 2003 | this.el.on('mousedown', function(e) { 2004 | var param; 2005 | e.preventDefault(); 2006 | if (_this.menu) { 2007 | _this.wrapper.toggleClass('menu-on').siblings('li').removeClass('menu-on'); 2008 | return false; 2009 | } 2010 | if (_this.el.hasClass('disabled') || (_this.needFocus && !_this.editor.inputManager.focused)) { 2011 | return false; 2012 | } 2013 | param = _this.el.data('param'); 2014 | _this.command(param); 2015 | return false; 2016 | }); 2017 | this.wrapper.on('click', 'a.menu-item', function(e) { 2018 | var btn, param; 2019 | e.preventDefault(); 2020 | btn = $(e.currentTarget); 2021 | _this.wrapper.removeClass('menu-on'); 2022 | if (btn.hasClass('disabled') || (_this.needFocus && !_this.editor.inputManager.focused)) { 2023 | return false; 2024 | } 2025 | _this.editor.toolbar.wrapper.removeClass('menu-on'); 2026 | param = btn.data('param'); 2027 | _this.command(param); 2028 | return false; 2029 | }); 2030 | this.wrapper.on('mousedown', 'a.menu-item', function(e) { 2031 | return false; 2032 | }); 2033 | this.editor.on('blur', function() { 2034 | _this.setActive(false); 2035 | return _this.setDisabled(false); 2036 | }); 2037 | if (this.shortcut != null) { 2038 | this.editor.inputManager.addShortcut(this.shortcut, function(e) { 2039 | _this.el.mousedown(); 2040 | return false; 2041 | }); 2042 | } 2043 | _ref3 = this.htmlTag.split(','); 2044 | for (_i = 0, _len = _ref3.length; _i < _len; _i++) { 2045 | tag = _ref3[_i]; 2046 | tag = $.trim(tag); 2047 | if (tag && $.inArray(tag, this.editor.formatter._allowedTags) < 0) { 2048 | this.editor.formatter._allowedTags.push(tag); 2049 | } 2050 | } 2051 | } 2052 | 2053 | Button.prototype.render = function() { 2054 | this.wrapper = $(this._tpl.item).appendTo(this.editor.toolbar.list); 2055 | this.el = this.wrapper.find('a.toolbar-item'); 2056 | this.el.attr('title', this.title).addClass('toolbar-item-' + this.name).data('button', this); 2057 | this.el.find('span').addClass(this.icon ? 'fa fa-' + this.icon : '').text(this.text); 2058 | if (!this.menu) { 2059 | return; 2060 | } 2061 | this.menuWrapper = $(this._tpl.menuWrapper).appendTo(this.wrapper); 2062 | this.menuWrapper.addClass('toolbar-menu-' + this.name); 2063 | return this.renderMenu(); 2064 | }; 2065 | 2066 | Button.prototype.renderMenu = function() { 2067 | var $menuBtntnEl, $menuItemEl, menuItem, _i, _len, _ref3, _ref4, _results; 2068 | if (!$.isArray(this.menu)) { 2069 | return; 2070 | } 2071 | this.menuEl = $('
        ').appendTo(this.menuWrapper); 2072 | _ref3 = this.menu; 2073 | _results = []; 2074 | for (_i = 0, _len = _ref3.length; _i < _len; _i++) { 2075 | menuItem = _ref3[_i]; 2076 | if (menuItem === '|') { 2077 | $(this._tpl.separator).appendTo(this.menuEl); 2078 | continue; 2079 | } 2080 | $menuItemEl = $(this._tpl.menuItem).appendTo(this.menuEl); 2081 | _results.push($menuBtntnEl = $menuItemEl.find('a.menu-item').attr({ 2082 | 'title': (_ref4 = menuItem.title) != null ? _ref4 : menuItem.text, 2083 | 'data-param': menuItem.param 2084 | }).addClass('menu-item-' + menuItem.name).find('span').text(menuItem.text)); 2085 | } 2086 | return _results; 2087 | }; 2088 | 2089 | Button.prototype.setActive = function(active) { 2090 | this.active = active; 2091 | return this.el.toggleClass('active', this.active); 2092 | }; 2093 | 2094 | Button.prototype.setDisabled = function(disabled) { 2095 | this.disabled = disabled; 2096 | return this.el.toggleClass('disabled', this.disabled); 2097 | }; 2098 | 2099 | Button.prototype.status = function($node) { 2100 | if ($node != null) { 2101 | this.setDisabled($node.is(this.disableTag)); 2102 | } 2103 | if (this.disabled) { 2104 | return true; 2105 | } 2106 | if ($node != null) { 2107 | this.setActive($node.is(this.htmlTag)); 2108 | } 2109 | return this.active; 2110 | }; 2111 | 2112 | Button.prototype.command = function(param) {}; 2113 | 2114 | return Button; 2115 | 2116 | })(Module); 2117 | 2118 | window.SimditorButton = Button; 2119 | 2120 | Popover = (function(_super) { 2121 | __extends(Popover, _super); 2122 | 2123 | Popover.prototype.offset = { 2124 | top: 4, 2125 | left: 0 2126 | }; 2127 | 2128 | Popover.prototype.target = null; 2129 | 2130 | Popover.prototype.active = false; 2131 | 2132 | function Popover(editor) { 2133 | var _this = this; 2134 | this.editor = editor; 2135 | this.el = $('
        ').appendTo(this.editor.wrapper).data('popover', this); 2136 | this.render(); 2137 | this.editor.on('blur.linkpopover', function() { 2138 | if (_this.active && (_this.target != null)) { 2139 | return _this.target.addClass('selected'); 2140 | } 2141 | }); 2142 | this.el.on('mouseenter', function(e) { 2143 | return _this.el.addClass('hover'); 2144 | }); 2145 | this.el.on('mouseleave', function(e) { 2146 | return _this.el.removeClass('hover'); 2147 | }); 2148 | } 2149 | 2150 | Popover.prototype.render = function() {}; 2151 | 2152 | Popover.prototype.show = function($target, position) { 2153 | var _this = this; 2154 | if (position == null) { 2155 | position = 'bottom'; 2156 | } 2157 | if ($target == null) { 2158 | return; 2159 | } 2160 | this.target = $target; 2161 | this.el.siblings('.simditor-popover').each(function(i, el) { 2162 | var popover; 2163 | popover = $(el).data('popover'); 2164 | return popover.hide(); 2165 | }); 2166 | if (this.active) { 2167 | this.refresh(position); 2168 | return this.trigger('popovershow'); 2169 | } else { 2170 | this.active = true; 2171 | this.el.css({ 2172 | left: -9999 2173 | }).show(); 2174 | return setTimeout(function() { 2175 | _this.refresh(position); 2176 | return _this.trigger('popovershow'); 2177 | }, 0); 2178 | } 2179 | }; 2180 | 2181 | Popover.prototype.hide = function() { 2182 | if (!this.active) { 2183 | return; 2184 | } 2185 | if (this.target) { 2186 | this.target.removeClass('selected'); 2187 | } 2188 | this.target = null; 2189 | this.active = false; 2190 | this.el.hide(); 2191 | return this.trigger('popoverhide'); 2192 | }; 2193 | 2194 | Popover.prototype.refresh = function(position) { 2195 | var left, targetH, targetOffset, top, wrapperOffset; 2196 | if (position == null) { 2197 | position = 'bottom'; 2198 | } 2199 | wrapperOffset = this.editor.wrapper.offset(); 2200 | targetOffset = this.target.offset(); 2201 | targetH = this.target.outerHeight(); 2202 | if (position === 'bottom') { 2203 | top = targetOffset.top - wrapperOffset.top + targetH; 2204 | } else if (position === 'top') { 2205 | top = targetOffset.top - wrapperOffset.top - this.el.height(); 2206 | } 2207 | left = Math.min(targetOffset.left - wrapperOffset.left, this.editor.wrapper.width() - this.el.outerWidth() - 10); 2208 | return this.el.css({ 2209 | top: top + this.offset.top, 2210 | left: left + this.offset.left 2211 | }); 2212 | }; 2213 | 2214 | Popover.prototype.destroy = function() { 2215 | this.target = null; 2216 | this.active = false; 2217 | this.editor.off('.linkpopover'); 2218 | return this.el.remove(); 2219 | }; 2220 | 2221 | return Popover; 2222 | 2223 | })(Module); 2224 | 2225 | TitleButton = (function(_super) { 2226 | __extends(TitleButton, _super); 2227 | 2228 | function TitleButton() { 2229 | _ref3 = TitleButton.__super__.constructor.apply(this, arguments); 2230 | return _ref3; 2231 | } 2232 | 2233 | TitleButton.prototype.name = 'title'; 2234 | 2235 | TitleButton.prototype.title = '标题文字'; 2236 | 2237 | TitleButton.prototype.htmlTag = 'h1, h2, h3, h4'; 2238 | 2239 | TitleButton.prototype.disableTag = 'pre, table'; 2240 | 2241 | TitleButton.prototype.menu = [ 2242 | { 2243 | name: 'normal', 2244 | text: '普通文本', 2245 | param: 'p' 2246 | }, '|', { 2247 | name: 'h1', 2248 | text: '标题 1', 2249 | param: 'h1' 2250 | }, { 2251 | name: 'h2', 2252 | text: '标题 2', 2253 | param: 'h2' 2254 | }, { 2255 | name: 'h3', 2256 | text: '标题 3', 2257 | param: 'h3' 2258 | } 2259 | ]; 2260 | 2261 | TitleButton.prototype.setActive = function(active, param) { 2262 | this.active = active; 2263 | if (active) { 2264 | return this.el.addClass('active active-' + param); 2265 | } else { 2266 | return this.el.removeClass('active active-p active-h1 active-h2 active-h3'); 2267 | } 2268 | }; 2269 | 2270 | TitleButton.prototype.status = function($node) { 2271 | var param, _ref4; 2272 | if ($node != null) { 2273 | this.setDisabled($node.is(this.disableTag)); 2274 | } 2275 | if (this.disabled) { 2276 | return true; 2277 | } 2278 | if ($node != null) { 2279 | param = (_ref4 = $node[0].tagName) != null ? _ref4.toLowerCase() : void 0; 2280 | this.setActive($node.is(this.htmlTag), param); 2281 | } 2282 | return this.active; 2283 | }; 2284 | 2285 | TitleButton.prototype.command = function(param) { 2286 | var $contents, $endBlock, $startBlock, endNode, node, range, results, startNode, _i, _len, _ref4, 2287 | _this = this; 2288 | range = this.editor.selection.getRange(); 2289 | startNode = range.startContainer; 2290 | endNode = range.endContainer; 2291 | $startBlock = this.editor.util.closestBlockEl(startNode); 2292 | $endBlock = this.editor.util.closestBlockEl(endNode); 2293 | this.editor.selection.save(); 2294 | range.setStartBefore($startBlock[0]); 2295 | range.setEndAfter($endBlock[0]); 2296 | $contents = $(range.extractContents()); 2297 | results = []; 2298 | $contents.children().each(function(i, el) { 2299 | var c, converted, _i, _len, _results; 2300 | converted = _this._convertEl(el, param); 2301 | _results = []; 2302 | for (_i = 0, _len = converted.length; _i < _len; _i++) { 2303 | c = converted[_i]; 2304 | _results.push(results.push(c)); 2305 | } 2306 | return _results; 2307 | }); 2308 | _ref4 = results.reverse(); 2309 | for (_i = 0, _len = _ref4.length; _i < _len; _i++) { 2310 | node = _ref4[_i]; 2311 | range.insertNode(node[0]); 2312 | } 2313 | this.editor.selection.restore(); 2314 | this.editor.trigger('valuechanged'); 2315 | return this.editor.trigger('selectionchanged'); 2316 | }; 2317 | 2318 | TitleButton.prototype._convertEl = function(el, param) { 2319 | var $block, $el, results; 2320 | $el = $(el); 2321 | results = []; 2322 | if ($el.is(param)) { 2323 | results.push($el); 2324 | } else { 2325 | $block = $('<' + param + '/>').append($el.contents()); 2326 | results.push($block); 2327 | } 2328 | return results; 2329 | }; 2330 | 2331 | return TitleButton; 2332 | 2333 | })(Button); 2334 | 2335 | Simditor.Toolbar.addButton(TitleButton); 2336 | 2337 | BoldButton = (function(_super) { 2338 | __extends(BoldButton, _super); 2339 | 2340 | function BoldButton() { 2341 | _ref4 = BoldButton.__super__.constructor.apply(this, arguments); 2342 | return _ref4; 2343 | } 2344 | 2345 | BoldButton.prototype.name = 'bold'; 2346 | 2347 | BoldButton.prototype.icon = 'bold'; 2348 | 2349 | BoldButton.prototype.title = '加粗文字'; 2350 | 2351 | BoldButton.prototype.htmlTag = 'b, strong'; 2352 | 2353 | BoldButton.prototype.disableTag = 'pre'; 2354 | 2355 | BoldButton.prototype.shortcut = 'cmd+66'; 2356 | 2357 | BoldButton.prototype.status = function($node) { 2358 | var active; 2359 | if ($node != null) { 2360 | this.setDisabled($node.is(this.disableTag)); 2361 | } 2362 | if (this.disabled) { 2363 | return true; 2364 | } 2365 | active = document.queryCommandState('bold') === true; 2366 | this.setActive(active); 2367 | return active; 2368 | }; 2369 | 2370 | BoldButton.prototype.command = function() { 2371 | document.execCommand('bold'); 2372 | this.editor.trigger('valuechanged'); 2373 | return this.editor.trigger('selectionchanged'); 2374 | }; 2375 | 2376 | return BoldButton; 2377 | 2378 | })(Button); 2379 | 2380 | Simditor.Toolbar.addButton(BoldButton); 2381 | 2382 | ItalicButton = (function(_super) { 2383 | __extends(ItalicButton, _super); 2384 | 2385 | function ItalicButton() { 2386 | _ref5 = ItalicButton.__super__.constructor.apply(this, arguments); 2387 | return _ref5; 2388 | } 2389 | 2390 | ItalicButton.prototype.name = 'italic'; 2391 | 2392 | ItalicButton.prototype.icon = 'italic'; 2393 | 2394 | ItalicButton.prototype.title = '斜体文字'; 2395 | 2396 | ItalicButton.prototype.htmlTag = 'i'; 2397 | 2398 | ItalicButton.prototype.disableTag = 'pre'; 2399 | 2400 | ItalicButton.prototype.shortcut = 'cmd+73'; 2401 | 2402 | ItalicButton.prototype.status = function($node) { 2403 | var active; 2404 | if ($node != null) { 2405 | this.setDisabled($node.is(this.disableTag)); 2406 | } 2407 | if (this.disabled) { 2408 | return this.disabled; 2409 | } 2410 | active = document.queryCommandState('italic') === true; 2411 | this.setActive(active); 2412 | return active; 2413 | }; 2414 | 2415 | ItalicButton.prototype.command = function() { 2416 | document.execCommand('italic'); 2417 | this.editor.trigger('valuechanged'); 2418 | return this.editor.trigger('selectionchanged'); 2419 | }; 2420 | 2421 | return ItalicButton; 2422 | 2423 | })(Button); 2424 | 2425 | Simditor.Toolbar.addButton(ItalicButton); 2426 | 2427 | UnderlineButton = (function(_super) { 2428 | __extends(UnderlineButton, _super); 2429 | 2430 | function UnderlineButton() { 2431 | _ref6 = UnderlineButton.__super__.constructor.apply(this, arguments); 2432 | return _ref6; 2433 | } 2434 | 2435 | UnderlineButton.prototype.name = 'underline'; 2436 | 2437 | UnderlineButton.prototype.icon = 'underline'; 2438 | 2439 | UnderlineButton.prototype.title = '下划线文字'; 2440 | 2441 | UnderlineButton.prototype.htmlTag = 'u'; 2442 | 2443 | UnderlineButton.prototype.disableTag = 'pre'; 2444 | 2445 | UnderlineButton.prototype.shortcut = 'cmd+85'; 2446 | 2447 | UnderlineButton.prototype.status = function($node) { 2448 | var active; 2449 | if ($node != null) { 2450 | this.setDisabled($node.is(this.disableTag)); 2451 | } 2452 | if (this.disabled) { 2453 | return this.disabled; 2454 | } 2455 | active = document.queryCommandState('underline') === true; 2456 | this.setActive(active); 2457 | return active; 2458 | }; 2459 | 2460 | UnderlineButton.prototype.command = function() { 2461 | document.execCommand('underline'); 2462 | this.editor.trigger('valuechanged'); 2463 | return this.editor.trigger('selectionchanged'); 2464 | }; 2465 | 2466 | return UnderlineButton; 2467 | 2468 | })(Button); 2469 | 2470 | Simditor.Toolbar.addButton(UnderlineButton); 2471 | 2472 | ListButton = (function(_super) { 2473 | __extends(ListButton, _super); 2474 | 2475 | function ListButton() { 2476 | _ref7 = ListButton.__super__.constructor.apply(this, arguments); 2477 | return _ref7; 2478 | } 2479 | 2480 | ListButton.prototype.type = ''; 2481 | 2482 | ListButton.prototype.disableTag = 'pre, table'; 2483 | 2484 | ListButton.prototype.status = function($node) { 2485 | var anotherType; 2486 | if ($node != null) { 2487 | this.setDisabled($node.is(this.disableTag)); 2488 | } 2489 | if (this.disabled) { 2490 | return true; 2491 | } 2492 | if ($node == null) { 2493 | return this.active; 2494 | } 2495 | anotherType = this.type === 'ul' ? 'ol' : 'ul'; 2496 | if ($node.is(anotherType)) { 2497 | this.setActive(false); 2498 | return true; 2499 | } else { 2500 | this.setActive($node.is(this.htmlTag)); 2501 | return this.active; 2502 | } 2503 | }; 2504 | 2505 | ListButton.prototype.command = function(param) { 2506 | var $contents, $endBlock, $furthestEnd, $furthestStart, $parent, $startBlock, endLevel, endNode, getListLevel, node, range, results, startLevel, startNode, _i, _len, _ref8, 2507 | _this = this; 2508 | range = this.editor.selection.getRange(); 2509 | startNode = range.startContainer; 2510 | endNode = range.endContainer; 2511 | $startBlock = this.editor.util.closestBlockEl(startNode); 2512 | $endBlock = this.editor.util.closestBlockEl(endNode); 2513 | this.editor.selection.save(); 2514 | range.setStartBefore($startBlock[0]); 2515 | range.setEndAfter($endBlock[0]); 2516 | if ($startBlock.is('li') && $endBlock.is('li')) { 2517 | $furthestStart = this.editor.util.furthestNode($startBlock, 'ul, ol'); 2518 | $furthestEnd = this.editor.util.furthestNode($endBlock, 'ul, ol'); 2519 | if ($furthestStart.is($furthestEnd)) { 2520 | getListLevel = function($li) { 2521 | var lvl; 2522 | lvl = 1; 2523 | while (!$li.parent().is($furthestStart)) { 2524 | lvl += 1; 2525 | $li = $li.parent(); 2526 | } 2527 | return lvl; 2528 | }; 2529 | startLevel = getListLevel($startBlock); 2530 | endLevel = getListLevel($endBlock); 2531 | if (startLevel > endLevel) { 2532 | $parent = $endBlock.parent(); 2533 | } else { 2534 | $parent = $startBlock.parent(); 2535 | } 2536 | range.setStartBefore($parent[0]); 2537 | range.setEndAfter($parent[0]); 2538 | } else { 2539 | range.setStartBefore($furthestStart[0]); 2540 | range.setEndAfter($furthestEnd[0]); 2541 | } 2542 | } 2543 | $contents = $(range.extractContents()); 2544 | results = []; 2545 | $contents.children().each(function(i, el) { 2546 | var c, converted, _i, _len, _results; 2547 | converted = _this._convertEl(el); 2548 | _results = []; 2549 | for (_i = 0, _len = converted.length; _i < _len; _i++) { 2550 | c = converted[_i]; 2551 | if (results.length && results[results.length - 1].is(_this.type) && c.is(_this.type)) { 2552 | _results.push(results[results.length - 1].append(c.children())); 2553 | } else { 2554 | _results.push(results.push(c)); 2555 | } 2556 | } 2557 | return _results; 2558 | }); 2559 | _ref8 = results.reverse(); 2560 | for (_i = 0, _len = _ref8.length; _i < _len; _i++) { 2561 | node = _ref8[_i]; 2562 | range.insertNode(node[0]); 2563 | } 2564 | this.editor.selection.restore(); 2565 | this.editor.trigger('valuechanged'); 2566 | return this.editor.trigger('selectionchanged'); 2567 | }; 2568 | 2569 | ListButton.prototype._convertEl = function(el) { 2570 | var $el, anotherType, block, child, children, results, _i, _len, _ref8, 2571 | _this = this; 2572 | $el = $(el); 2573 | results = []; 2574 | anotherType = this.type === 'ul' ? 'ol' : 'ul'; 2575 | if ($el.is(this.type)) { 2576 | $el.children('li').each(function(i, li) { 2577 | var $childList, $li, block; 2578 | $li = $(li); 2579 | $childList = $li.children('ul, ol').remove(); 2580 | block = $('

        ').append($(li).html() || _this.editor.util.phBr); 2581 | results.push(block); 2582 | if ($childList.length > 0) { 2583 | return results.push($childList); 2584 | } 2585 | }); 2586 | } else if ($el.is(anotherType)) { 2587 | block = $('<' + this.type + '/>').append($el.html()); 2588 | results.push(block); 2589 | } else if ($el.is('blockquote')) { 2590 | _ref8 = $el.children().get(); 2591 | for (_i = 0, _len = _ref8.length; _i < _len; _i++) { 2592 | child = _ref8[_i]; 2593 | children = this._convertEl(child); 2594 | } 2595 | $.merge(results, children); 2596 | } else if ($el.is('table')) { 2597 | 2598 | } else { 2599 | block = $('<' + this.type + '>

      • '); 2600 | block.find('li').append($el.html() || this.editor.util.phBr); 2601 | results.push(block); 2602 | } 2603 | return results; 2604 | }; 2605 | 2606 | return ListButton; 2607 | 2608 | })(Button); 2609 | 2610 | OrderListButton = (function(_super) { 2611 | __extends(OrderListButton, _super); 2612 | 2613 | function OrderListButton() { 2614 | _ref8 = OrderListButton.__super__.constructor.apply(this, arguments); 2615 | return _ref8; 2616 | } 2617 | 2618 | OrderListButton.prototype.type = 'ol'; 2619 | 2620 | OrderListButton.prototype.name = 'ol'; 2621 | 2622 | OrderListButton.prototype.title = '有序列表'; 2623 | 2624 | OrderListButton.prototype.icon = 'list-ol'; 2625 | 2626 | OrderListButton.prototype.htmlTag = 'ol'; 2627 | 2628 | return OrderListButton; 2629 | 2630 | })(ListButton); 2631 | 2632 | UnorderListButton = (function(_super) { 2633 | __extends(UnorderListButton, _super); 2634 | 2635 | function UnorderListButton() { 2636 | _ref9 = UnorderListButton.__super__.constructor.apply(this, arguments); 2637 | return _ref9; 2638 | } 2639 | 2640 | UnorderListButton.prototype.type = 'ul'; 2641 | 2642 | UnorderListButton.prototype.name = 'ul'; 2643 | 2644 | UnorderListButton.prototype.title = '无序列表'; 2645 | 2646 | UnorderListButton.prototype.icon = 'list-ul'; 2647 | 2648 | UnorderListButton.prototype.htmlTag = 'ul'; 2649 | 2650 | return UnorderListButton; 2651 | 2652 | })(ListButton); 2653 | 2654 | Simditor.Toolbar.addButton(OrderListButton); 2655 | 2656 | Simditor.Toolbar.addButton(UnorderListButton); 2657 | 2658 | BlockquoteButton = (function(_super) { 2659 | __extends(BlockquoteButton, _super); 2660 | 2661 | function BlockquoteButton() { 2662 | _ref10 = BlockquoteButton.__super__.constructor.apply(this, arguments); 2663 | return _ref10; 2664 | } 2665 | 2666 | BlockquoteButton.prototype.name = 'blockquote'; 2667 | 2668 | BlockquoteButton.prototype.icon = 'quote-left'; 2669 | 2670 | BlockquoteButton.prototype.title = '引用'; 2671 | 2672 | BlockquoteButton.prototype.htmlTag = 'blockquote'; 2673 | 2674 | BlockquoteButton.prototype.disableTag = 'pre, table'; 2675 | 2676 | BlockquoteButton.prototype.command = function() { 2677 | var $contents, $endBlock, $startBlock, endNode, node, range, results, startNode, _i, _len, _ref11, 2678 | _this = this; 2679 | range = this.editor.selection.getRange(); 2680 | startNode = range.startContainer; 2681 | endNode = range.endContainer; 2682 | $startBlock = this.editor.util.furthestBlockEl(startNode); 2683 | $endBlock = this.editor.util.furthestBlockEl(endNode); 2684 | this.editor.selection.save(); 2685 | range.setStartBefore($startBlock[0]); 2686 | range.setEndAfter($endBlock[0]); 2687 | $contents = $(range.extractContents()); 2688 | results = []; 2689 | $contents.children().each(function(i, el) { 2690 | var c, converted, _i, _len, _results; 2691 | converted = _this._convertEl(el); 2692 | _results = []; 2693 | for (_i = 0, _len = converted.length; _i < _len; _i++) { 2694 | c = converted[_i]; 2695 | if (results.length && results[results.length - 1].is(_this.htmlTag) && c.is(_this.htmlTag)) { 2696 | _results.push(results[results.length - 1].append(c.children())); 2697 | } else { 2698 | _results.push(results.push(c)); 2699 | } 2700 | } 2701 | return _results; 2702 | }); 2703 | _ref11 = results.reverse(); 2704 | for (_i = 0, _len = _ref11.length; _i < _len; _i++) { 2705 | node = _ref11[_i]; 2706 | range.insertNode(node[0]); 2707 | } 2708 | this.editor.selection.restore(); 2709 | this.editor.trigger('valuechanged'); 2710 | return this.editor.trigger('selectionchanged'); 2711 | }; 2712 | 2713 | BlockquoteButton.prototype._convertEl = function(el) { 2714 | var $el, block, results, 2715 | _this = this; 2716 | $el = $(el); 2717 | results = []; 2718 | if ($el.is(this.htmlTag)) { 2719 | $el.children().each(function(i, node) { 2720 | return results.push($(node)); 2721 | }); 2722 | } else { 2723 | block = $('<' + this.htmlTag + '/>').append($el); 2724 | results.push(block); 2725 | } 2726 | return results; 2727 | }; 2728 | 2729 | return BlockquoteButton; 2730 | 2731 | })(Button); 2732 | 2733 | Simditor.Toolbar.addButton(BlockquoteButton); 2734 | 2735 | CodeButton = (function(_super) { 2736 | __extends(CodeButton, _super); 2737 | 2738 | function CodeButton() { 2739 | _ref11 = CodeButton.__super__.constructor.apply(this, arguments); 2740 | return _ref11; 2741 | } 2742 | 2743 | CodeButton.prototype.name = 'code'; 2744 | 2745 | CodeButton.prototype.icon = 'code'; 2746 | 2747 | CodeButton.prototype.title = '插入代码'; 2748 | 2749 | CodeButton.prototype.htmlTag = 'pre'; 2750 | 2751 | CodeButton.prototype.disableTag = 'li, table'; 2752 | 2753 | CodeButton.prototype.render = function() { 2754 | var args; 2755 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 2756 | CodeButton.__super__.render.apply(this, args); 2757 | return this.popover = new CodePopover(this.editor); 2758 | }; 2759 | 2760 | CodeButton.prototype.status = function($node) { 2761 | var result; 2762 | result = CodeButton.__super__.status.call(this, $node); 2763 | if (this.active) { 2764 | this.popover.show($node); 2765 | } else if (this.editor.util.isBlockNode($node)) { 2766 | this.popover.hide(); 2767 | } 2768 | return result; 2769 | }; 2770 | 2771 | CodeButton.prototype.command = function() { 2772 | var $contents, $endBlock, $startBlock, endNode, node, range, results, startNode, _i, _len, _ref12, 2773 | _this = this; 2774 | range = this.editor.selection.getRange(); 2775 | startNode = range.startContainer; 2776 | endNode = range.endContainer; 2777 | $startBlock = this.editor.util.closestBlockEl(startNode); 2778 | $endBlock = this.editor.util.closestBlockEl(endNode); 2779 | range.setStartBefore($startBlock[0]); 2780 | range.setEndAfter($endBlock[0]); 2781 | $contents = $(range.extractContents()); 2782 | results = []; 2783 | $contents.children().each(function(i, el) { 2784 | var c, converted, _i, _len, _results; 2785 | converted = _this._convertEl(el); 2786 | _results = []; 2787 | for (_i = 0, _len = converted.length; _i < _len; _i++) { 2788 | c = converted[_i]; 2789 | if (results.length && results[results.length - 1].is(_this.htmlTag) && c.is(_this.htmlTag)) { 2790 | _results.push(results[results.length - 1].append(c.contents())); 2791 | } else { 2792 | _results.push(results.push(c)); 2793 | } 2794 | } 2795 | return _results; 2796 | }); 2797 | _ref12 = results.reverse(); 2798 | for (_i = 0, _len = _ref12.length; _i < _len; _i++) { 2799 | node = _ref12[_i]; 2800 | range.insertNode(node[0]); 2801 | } 2802 | this.editor.selection.setRangeAtEndOf(results[0]); 2803 | this.editor.trigger('valuechanged'); 2804 | return this.editor.trigger('selectionchanged'); 2805 | }; 2806 | 2807 | CodeButton.prototype._convertEl = function(el) { 2808 | var $el, block, codeStr, results; 2809 | $el = $(el); 2810 | results = []; 2811 | if ($el.is(this.htmlTag)) { 2812 | block = $('

        ').append($el.html().replace('\n', '
        ')); 2813 | results.push(block); 2814 | } else { 2815 | if (!$el.text() && $el.children().length === 1 && $el.children().is('br')) { 2816 | codeStr = '\n'; 2817 | } else { 2818 | codeStr = this.editor.formatter.clearHtml($el); 2819 | } 2820 | block = $('<' + this.htmlTag + '/>').append(codeStr); 2821 | results.push(block); 2822 | } 2823 | return results; 2824 | }; 2825 | 2826 | return CodeButton; 2827 | 2828 | })(Button); 2829 | 2830 | CodePopover = (function(_super) { 2831 | __extends(CodePopover, _super); 2832 | 2833 | function CodePopover() { 2834 | _ref12 = CodePopover.__super__.constructor.apply(this, arguments); 2835 | return _ref12; 2836 | } 2837 | 2838 | CodePopover.prototype._tpl = "

        \n
        \n \n
        \n
        "; 2839 | 2840 | CodePopover.prototype.render = function() { 2841 | var _this = this; 2842 | this.el.addClass('code-popover').append(this._tpl); 2843 | this.selectEl = this.el.find('.select-lang'); 2844 | return this.selectEl.on('change', function(e) { 2845 | var lang, oldLang; 2846 | lang = _this.selectEl.val(); 2847 | oldLang = _this.target.attr('data-lang'); 2848 | _this.target.removeClass('lang-' + oldLang).removeAttr('data-lang'); 2849 | if (_this.lang !== -1) { 2850 | _this.target.addClass('lang-' + lang); 2851 | return _this.target.attr('data-lang', lang); 2852 | } 2853 | }); 2854 | }; 2855 | 2856 | CodePopover.prototype.show = function() { 2857 | var args; 2858 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 2859 | CodePopover.__super__.show.apply(this, args); 2860 | this.lang = this.target.attr('data-lang'); 2861 | if (this.lang != null) { 2862 | return this.selectEl.val(this.lang); 2863 | } 2864 | }; 2865 | 2866 | return CodePopover; 2867 | 2868 | })(Popover); 2869 | 2870 | Simditor.Toolbar.addButton(CodeButton); 2871 | 2872 | LinkButton = (function(_super) { 2873 | __extends(LinkButton, _super); 2874 | 2875 | function LinkButton() { 2876 | _ref13 = LinkButton.__super__.constructor.apply(this, arguments); 2877 | return _ref13; 2878 | } 2879 | 2880 | LinkButton.prototype.name = 'link'; 2881 | 2882 | LinkButton.prototype.icon = 'link'; 2883 | 2884 | LinkButton.prototype.title = '插入链接'; 2885 | 2886 | LinkButton.prototype.htmlTag = 'a'; 2887 | 2888 | LinkButton.prototype.disableTag = 'pre'; 2889 | 2890 | LinkButton.prototype.render = function() { 2891 | var args; 2892 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 2893 | LinkButton.__super__.render.apply(this, args); 2894 | return this.popover = new LinkPopover(this.editor); 2895 | }; 2896 | 2897 | LinkButton.prototype.status = function($node) { 2898 | var showPopover; 2899 | if ($node != null) { 2900 | this.setDisabled($node.is(this.disableTag)); 2901 | } 2902 | if (this.disabled) { 2903 | return true; 2904 | } 2905 | if ($node == null) { 2906 | return this.active; 2907 | } 2908 | showPopover = true; 2909 | if (!$node.is(this.htmlTag) || $node.is('[class^="simditor-"]')) { 2910 | this.setActive(false); 2911 | showPopover = false; 2912 | } else if (this.editor.selection.rangeAtEndOf($node)) { 2913 | this.setActive(true); 2914 | showPopover = false; 2915 | } else { 2916 | this.setActive(true); 2917 | } 2918 | if (showPopover) { 2919 | this.popover.show($node); 2920 | } else if (this.editor.util.isBlockNode($node)) { 2921 | this.popover.hide(); 2922 | } 2923 | return this.active; 2924 | }; 2925 | 2926 | LinkButton.prototype.command = function() { 2927 | var $contents, $endBlock, $link, $newBlock, $startBlock, endNode, linkText, range, startNode, txtNode, 2928 | _this = this; 2929 | range = this.editor.selection.getRange(); 2930 | if (this.active) { 2931 | $link = $(range.commonAncestorContainer).closest('a'); 2932 | txtNode = document.createTextNode($link.text()); 2933 | $link.replaceWith(txtNode); 2934 | range.selectNode(txtNode); 2935 | } else { 2936 | startNode = range.startContainer; 2937 | endNode = range.endContainer; 2938 | $startBlock = this.editor.util.closestBlockEl(startNode); 2939 | $endBlock = this.editor.util.closestBlockEl(endNode); 2940 | $contents = $(range.extractContents()); 2941 | linkText = this.editor.formatter.clearHtml($contents.contents(), false); 2942 | $link = $('', { 2943 | href: 'http://www.example.com', 2944 | target: '_blank', 2945 | text: linkText || '链接文字' 2946 | }); 2947 | if ($startBlock[0] === $endBlock[0]) { 2948 | range.insertNode($link[0]); 2949 | } else { 2950 | $newBlock = $('

        ').append($link); 2951 | range.insertNode($newBlock[0]); 2952 | } 2953 | range.selectNodeContents($link[0]); 2954 | this.popover.one('popovershow', function() { 2955 | if (linkText) { 2956 | _this.popover.urlEl.focus(); 2957 | return _this.popover.urlEl[0].select(); 2958 | } else { 2959 | _this.popover.textEl.focus(); 2960 | return _this.popover.textEl[0].select(); 2961 | } 2962 | }); 2963 | } 2964 | this.editor.selection.selectRange(range); 2965 | this.editor.trigger('valuechanged'); 2966 | return this.editor.trigger('selectionchanged'); 2967 | }; 2968 | 2969 | return LinkButton; 2970 | 2971 | })(Button); 2972 | 2973 | LinkPopover = (function(_super) { 2974 | __extends(LinkPopover, _super); 2975 | 2976 | function LinkPopover() { 2977 | _ref14 = LinkPopover.__super__.constructor.apply(this, arguments); 2978 | return _ref14; 2979 | } 2980 | 2981 | LinkPopover.prototype._tpl = "

        "; 2982 | 2983 | LinkPopover.prototype.render = function() { 2984 | var _this = this; 2985 | this.el.addClass('link-popover').append(this._tpl); 2986 | this.textEl = this.el.find('.link-text'); 2987 | this.urlEl = this.el.find('.link-url'); 2988 | this.unlinkEl = this.el.find('.btn-unlink'); 2989 | this.textEl.on('keyup', function(e) { 2990 | if (e.which === 13) { 2991 | return; 2992 | } 2993 | return _this.target.text(_this.textEl.val()); 2994 | }); 2995 | this.urlEl.on('keyup', function(e) { 2996 | if (e.which === 13) { 2997 | return; 2998 | } 2999 | return _this.target.attr('href', _this.urlEl.val()); 3000 | }); 3001 | $([this.urlEl[0], this.textEl[0]]).on('keydown', function(e) { 3002 | if (e.which === 13 || e.which === 27 || (!e.shiftKey && e.which === 9 && $(e.target).hasClass('link-url'))) { 3003 | e.preventDefault(); 3004 | return setTimeout(function() { 3005 | var range; 3006 | range = document.createRange(); 3007 | _this.editor.selection.setRangeAfter(_this.target, range); 3008 | if (_this.editor.util.browser.firefox) { 3009 | _this.editor.body.focus(); 3010 | } 3011 | _this.hide(); 3012 | _this.editor.trigger('valuechanged'); 3013 | return _this.editor.trigger('selectionchanged'); 3014 | }, 0); 3015 | } 3016 | }); 3017 | return this.unlinkEl.on('click', function(e) { 3018 | var range, txtNode; 3019 | txtNode = document.createTextNode(_this.target.text()); 3020 | _this.target.replaceWith(txtNode); 3021 | _this.hide(); 3022 | range = document.createRange(); 3023 | _this.editor.selection.setRangeAfter(txtNode, range); 3024 | if (_this.editor.util.browser.firefox && !_this.editor.inputManager.focused) { 3025 | _this.editor.body.focus(); 3026 | } 3027 | _this.editor.trigger('valuechanged'); 3028 | return _this.editor.trigger('selectionchanged'); 3029 | }); 3030 | }; 3031 | 3032 | LinkPopover.prototype.show = function() { 3033 | var args; 3034 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 3035 | LinkPopover.__super__.show.apply(this, args); 3036 | this.textEl.val(this.target.text()); 3037 | return this.urlEl.val(this.target.attr('href')); 3038 | }; 3039 | 3040 | return LinkPopover; 3041 | 3042 | })(Popover); 3043 | 3044 | Simditor.Toolbar.addButton(LinkButton); 3045 | 3046 | ImageButton = (function(_super) { 3047 | __extends(ImageButton, _super); 3048 | 3049 | ImageButton.prototype._wrapperTpl = "
        \n
        \n
        \n
        \n
        "; 3050 | 3051 | ImageButton.prototype.name = 'image'; 3052 | 3053 | ImageButton.prototype.icon = 'picture-o'; 3054 | 3055 | ImageButton.prototype.title = '插入图片'; 3056 | 3057 | ImageButton.prototype.htmlTag = 'img'; 3058 | 3059 | ImageButton.prototype.disableTag = 'pre, table'; 3060 | 3061 | ImageButton.prototype.defaultImage = ''; 3062 | 3063 | ImageButton.prototype.maxWidth = 0; 3064 | 3065 | ImageButton.prototype.maxHeight = 0; 3066 | 3067 | ImageButton.prototype.menu = [ 3068 | { 3069 | name: 'upload-image', 3070 | text: '本地图片' 3071 | }, { 3072 | name: 'external-image', 3073 | text: '外链图片' 3074 | } 3075 | ]; 3076 | 3077 | function ImageButton(editor) { 3078 | var _this = this; 3079 | this.editor = editor; 3080 | if (this.editor.uploader == null) { 3081 | this.menu = false; 3082 | } 3083 | ImageButton.__super__.constructor.call(this, this.editor); 3084 | this.defaultImage = this.editor.opts.defaultImage; 3085 | this.maxWidth = this.editor.opts.maxImageWidth || this.editor.body.width(); 3086 | this.maxHeight = this.editor.opts.maxImageHeight || $(window).height(); 3087 | this.editor.on('decorate', function(e, $el) { 3088 | return $el.find('img').each(function(i, img) { 3089 | return _this.decorate($(img)); 3090 | }); 3091 | }); 3092 | this.editor.on('undecorate', function(e, $el) { 3093 | return $el.find('img').each(function(i, img) { 3094 | return _this.undecorate($(img)); 3095 | }); 3096 | }); 3097 | this.editor.body.on('mousedown', '.simditor-image', function(e) { 3098 | var $imgWrapper; 3099 | $imgWrapper = $(e.currentTarget); 3100 | if ($imgWrapper.hasClass('selected')) { 3101 | _this.popover.srcEl.blur(); 3102 | _this.popover.hide(); 3103 | $imgWrapper.removeClass('selected'); 3104 | } else { 3105 | _this.editor.body.blur(); 3106 | _this.editor.body.find('.simditor-image').removeClass('selected'); 3107 | $imgWrapper.addClass('selected').focus(); 3108 | _this.popover.show($imgWrapper); 3109 | } 3110 | return false; 3111 | }); 3112 | this.editor.body.on('click', '.simditor-image', function(e) { 3113 | return false; 3114 | }); 3115 | this.editor.on('selectionchanged.image', function() { 3116 | var $container, range; 3117 | range = _this.editor.selection.getRange(); 3118 | if (range == null) { 3119 | return; 3120 | } 3121 | $container = $(range.commonAncestorContainer); 3122 | if (range.collapsed && $container.is('.simditor-image')) { 3123 | return $container.mousedown(); 3124 | } else if (_this.popover.active) { 3125 | if (_this.popover.active) { 3126 | return _this.popover.hide(); 3127 | } 3128 | } 3129 | }); 3130 | this.editor.body.on('keydown', '.simditor-image', function(e) { 3131 | if (e.which !== 8) { 3132 | return; 3133 | } 3134 | _this.popover.hide(); 3135 | $(e.currentTarget).remove(); 3136 | _this.editor.trigger('valuechanged'); 3137 | return false; 3138 | }); 3139 | } 3140 | 3141 | ImageButton.prototype.render = function() { 3142 | var args; 3143 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 3144 | ImageButton.__super__.render.apply(this, args); 3145 | return this.popover = new ImagePopover(this); 3146 | }; 3147 | 3148 | ImageButton.prototype.renderMenu = function() { 3149 | var $input, $uploadItem, createInput, 3150 | _this = this; 3151 | ImageButton.__super__.renderMenu.call(this); 3152 | $uploadItem = this.menuEl.find('.menu-item-upload-image'); 3153 | $input = null; 3154 | createInput = function() { 3155 | if ($input) { 3156 | $input.remove(); 3157 | } 3158 | return $input = $('').appendTo($uploadItem); 3159 | }; 3160 | createInput(); 3161 | $uploadItem.on('click mousedown', 'input[name=upload_file]', function(e) { 3162 | return e.stopPropagation(); 3163 | }); 3164 | $uploadItem.on('change', 'input[name=upload_file]', function(e) { 3165 | if (_this.editor.inputManager.focused) { 3166 | _this.editor.uploader.upload($input, { 3167 | inline: true 3168 | }); 3169 | createInput(); 3170 | } else if (_this.editor.inputManager.lastCaretPosition) { 3171 | _this.editor.one('focus', function(e) { 3172 | _this.editor.uploader.upload($input, { 3173 | inline: true 3174 | }); 3175 | return createInput(); 3176 | }); 3177 | _this.editor.undoManager.caretPosition(_this.editor.inputManager.lastCaretPosition); 3178 | } 3179 | return _this.wrapper.removeClass('menu-on'); 3180 | }); 3181 | return this._initUploader(); 3182 | }; 3183 | 3184 | ImageButton.prototype._initUploader = function() { 3185 | var _this = this; 3186 | if (this.editor.uploader == null) { 3187 | this.el.find('.btn-upload').remove(); 3188 | return; 3189 | } 3190 | this.editor.uploader.on('beforeupload', function(e, file) { 3191 | var $img; 3192 | if (!file.inline) { 3193 | return; 3194 | } 3195 | if (file.imgWrapper) { 3196 | $img = file.imgWrapper.find("img"); 3197 | } else { 3198 | $img = _this.createImage(); 3199 | $img.mousedown(); 3200 | file.imgWrapper = $img.parent('.simditor-image'); 3201 | } 3202 | return _this.editor.uploader.readImageFile(file.obj, function(img) { 3203 | var prepare; 3204 | prepare = function() { 3205 | var $progress; 3206 | _this.popover.srcEl.val('正在上传...'); 3207 | file.imgWrapper.append('
        '); 3208 | $progress = $('
        ').appendTo(file.imgWrapper); 3209 | if (!_this.editor.uploader.html5) { 3210 | return $progress.addClass('loading'); 3211 | } 3212 | }; 3213 | if (img) { 3214 | return _this.loadImage($img, img.src, function() { 3215 | _this.popover.refresh(); 3216 | return prepare(); 3217 | }); 3218 | } else { 3219 | return prepare(); 3220 | } 3221 | }); 3222 | }); 3223 | this.editor.uploader.on('uploadprogress', function(e, file, loaded, total) { 3224 | var percent; 3225 | if (!file.inline) { 3226 | return; 3227 | } 3228 | percent = loaded / total; 3229 | percent = (percent * 100).toFixed(0); 3230 | if (percent > 99) { 3231 | percent = 99; 3232 | } 3233 | file.imgWrapper.find(".simditor-image-progress span").text(percent); 3234 | return file.imgWrapper.find('.mask').css({ 3235 | top: percent + '%', 3236 | height: (100 - percent) + '%' 3237 | }); 3238 | }); 3239 | this.editor.uploader.on('uploadsuccess', function(e, file, result) { 3240 | var $img; 3241 | if (!file.inline) { 3242 | return; 3243 | } 3244 | $img = file.imgWrapper.find("img"); 3245 | return _this.loadImage($img, result.file_path, function() { 3246 | file.imgWrapper.find(".mask, .simditor-image-progress").remove(); 3247 | _this.popover.srcEl.val(result.file_path); 3248 | return _this.editor.trigger('valuechanged'); 3249 | }); 3250 | }); 3251 | return this.editor.uploader.on('uploaderror', function(e, file, xhr) { 3252 | var $img, msg, result; 3253 | if (!file.inline) { 3254 | return; 3255 | } 3256 | if (xhr.statusText === 'abort') { 3257 | return; 3258 | } 3259 | if (xhr.responseText) { 3260 | try { 3261 | result = $.parseJSON(xhr.responseText); 3262 | msg = result.msg; 3263 | } catch (_error) { 3264 | e = _error; 3265 | msg = '上传出错了'; 3266 | } 3267 | if ((typeof simple !== "undefined" && simple !== null) && (simple.message != null)) { 3268 | simple.message(msg); 3269 | } else { 3270 | alert(msg); 3271 | } 3272 | } 3273 | $img = file.imgWrapper.find("img"); 3274 | return _this.loadImage($img, _this.defaultImage, function() { 3275 | _this.popover.refresh(); 3276 | _this.popover.srcEl.val($img.attr('src')); 3277 | file.imgWrapper.find(".mask, .simditor-image-progress").remove(); 3278 | return _this.editor.trigger('valuechanged'); 3279 | }); 3280 | }); 3281 | }; 3282 | 3283 | ImageButton.prototype.status = function($node) { 3284 | if ($node != null) { 3285 | this.setDisabled($node.is(this.disableTag)); 3286 | } 3287 | if (this.disabled) { 3288 | return true; 3289 | } 3290 | }; 3291 | 3292 | ImageButton.prototype.decorate = function($img) { 3293 | var $parent, $wrapper; 3294 | $parent = $img.parent(); 3295 | if ($parent.is('.simditor-image')) { 3296 | return; 3297 | } 3298 | $wrapper = $(this._wrapperTpl).width($img.width()); 3299 | if ($parent.is('p')) { 3300 | return $wrapper.prepend($img).replaceAll($parent); 3301 | } else { 3302 | return $wrapper.insertBefore($img).prepend($img); 3303 | } 3304 | }; 3305 | 3306 | ImageButton.prototype.undecorate = function($img) { 3307 | var $wrapper; 3308 | $wrapper = $img.parent('.simditor-image'); 3309 | if ($wrapper.length < 1) { 3310 | return; 3311 | } 3312 | if (!$img.is('img[src^="data:image/png;base64"]')) { 3313 | $('

        ').append($img).insertAfter($wrapper); 3314 | } 3315 | return $wrapper.remove(); 3316 | }; 3317 | 3318 | ImageButton.prototype.loadImage = function($img, src, callback) { 3319 | var $wrapper, img, 3320 | _this = this; 3321 | $wrapper = $img.parent('.simditor-image'); 3322 | img = new Image(); 3323 | img.onload = function() { 3324 | var height, width; 3325 | width = img.width; 3326 | height = img.height; 3327 | if (width > _this.maxWidth) { 3328 | height = _this.maxWidth * height / width; 3329 | width = _this.maxWidth; 3330 | } 3331 | if (height > _this.maxHeight) { 3332 | width = _this.maxHeight * width / height; 3333 | height = _this.maxHeight; 3334 | } 3335 | $img.attr({ 3336 | src: src, 3337 | width: width, 3338 | height: height, 3339 | 'data-origin-src': src, 3340 | 'data-origin-name': '图片', 3341 | 'data-origin-size': img.width + ',' + img.height 3342 | }); 3343 | $wrapper.width(width).height(height); 3344 | return callback(true); 3345 | }; 3346 | img.onerror = function() { 3347 | return callback(false); 3348 | }; 3349 | return img.src = src; 3350 | }; 3351 | 3352 | ImageButton.prototype.createImage = function() { 3353 | var $breakedEl, $endBlock, $img, $startBlock, endNode, range, startNode; 3354 | range = this.editor.selection.getRange(); 3355 | startNode = range.startContainer; 3356 | endNode = range.endContainer; 3357 | $startBlock = this.editor.util.closestBlockEl(startNode); 3358 | $endBlock = this.editor.util.closestBlockEl(endNode); 3359 | range.deleteContents(); 3360 | if ($startBlock[0] === $endBlock[0]) { 3361 | if ($startBlock.is('li')) { 3362 | $startBlock = this.editor.util.furthestNode($startBlock, 'ul, ol'); 3363 | $endBlock = $startBlock; 3364 | range.setEndAfter($startBlock[0]); 3365 | range.collapse(false); 3366 | } else if ($startBlock.is('p')) { 3367 | if (this.editor.util.isEmptyNode($startBlock)) { 3368 | range.selectNode($startBlock[0]); 3369 | range.deleteContents(); 3370 | } else if (this.editor.selection.rangeAtEndOf($startBlock, range)) { 3371 | range.setEndAfter($startBlock[0]); 3372 | range.collapse(false); 3373 | } else if (this.editor.selection.rangeAtStartOf($startBlock, range)) { 3374 | range.setEndBefore($startBlock[0]); 3375 | range.collapse(false); 3376 | } else { 3377 | $breakedEl = this.editor.selection.breakBlockEl($startBlock, range); 3378 | range.setEndBefore($breakedEl[0]); 3379 | range.collapse(false); 3380 | } 3381 | } 3382 | } 3383 | $img = $(''); 3384 | range.insertNode($img[0]); 3385 | this.decorate($img); 3386 | return $img; 3387 | }; 3388 | 3389 | ImageButton.prototype.command = function() { 3390 | var $img, 3391 | _this = this; 3392 | $img = this.createImage(); 3393 | return this.loadImage($img, this.defaultImage, function() { 3394 | _this.editor.trigger('valuechanged'); 3395 | $img.mousedown(); 3396 | return _this.popover.one('popovershow', function() { 3397 | _this.popover.srcEl.focus(); 3398 | return _this.popover.srcEl[0].select(); 3399 | }); 3400 | }); 3401 | }; 3402 | 3403 | return ImageButton; 3404 | 3405 | })(Button); 3406 | 3407 | ImagePopover = (function(_super) { 3408 | __extends(ImagePopover, _super); 3409 | 3410 | ImagePopover.prototype._tpl = "

        "; 3411 | 3412 | ImagePopover.prototype.offset = { 3413 | top: 6, 3414 | left: -4 3415 | }; 3416 | 3417 | function ImagePopover(button) { 3418 | this.button = button; 3419 | ImagePopover.__super__.constructor.call(this, this.button.editor); 3420 | } 3421 | 3422 | ImagePopover.prototype.render = function() { 3423 | var _this = this; 3424 | this.el.addClass('image-popover').append(this._tpl); 3425 | this.srcEl = this.el.find('.image-src'); 3426 | this.srcEl.on('keyup', function(e) { 3427 | if (e.which === 13) { 3428 | return; 3429 | } 3430 | if (_this.timer) { 3431 | clearTimeout(_this.timer); 3432 | } 3433 | return _this.timer = setTimeout(function() { 3434 | var $img, src; 3435 | src = _this.srcEl.val(); 3436 | $img = _this.target.find('img'); 3437 | _this.button.loadImage($img, src, function(success) { 3438 | if (!success) { 3439 | return; 3440 | } 3441 | _this.refresh(); 3442 | return _this.editor.trigger('valuechanged'); 3443 | }); 3444 | return _this.timer = null; 3445 | }, 200); 3446 | }); 3447 | this.srcEl.on('keydown', function(e) { 3448 | if (e.which === 13 || e.which === 27 || e.which === 9) { 3449 | e.preventDefault(); 3450 | _this.srcEl.blur(); 3451 | _this.target.removeClass('selected'); 3452 | return _this.hide(); 3453 | } 3454 | }); 3455 | return this._initUploader(); 3456 | }; 3457 | 3458 | ImagePopover.prototype._initUploader = function() { 3459 | var $uploadBtn, createInput, 3460 | _this = this; 3461 | $uploadBtn = this.el.find('.btn-upload'); 3462 | if (this.editor.uploader == null) { 3463 | $uploadBtn.remove(); 3464 | return; 3465 | } 3466 | createInput = function() { 3467 | if (_this.input) { 3468 | _this.input.remove(); 3469 | } 3470 | return _this.input = $('').appendTo($uploadBtn); 3471 | }; 3472 | createInput(); 3473 | this.el.on('click mousedown', 'input[name=upload_file]', function(e) { 3474 | return e.stopPropagation(); 3475 | }); 3476 | return this.el.on('change', 'input[name=upload_file]', function(e) { 3477 | _this.editor.uploader.upload(_this.input, { 3478 | inline: true, 3479 | imgWrapper: _this.target 3480 | }); 3481 | return createInput(); 3482 | }); 3483 | }; 3484 | 3485 | ImagePopover.prototype.show = function() { 3486 | var $img, args; 3487 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 3488 | ImagePopover.__super__.show.apply(this, args); 3489 | $img = this.target.find('img'); 3490 | return this.srcEl.val($img.attr('src')); 3491 | }; 3492 | 3493 | return ImagePopover; 3494 | 3495 | })(Popover); 3496 | 3497 | Simditor.Toolbar.addButton(ImageButton); 3498 | 3499 | IndentButton = (function(_super) { 3500 | __extends(IndentButton, _super); 3501 | 3502 | function IndentButton() { 3503 | _ref15 = IndentButton.__super__.constructor.apply(this, arguments); 3504 | return _ref15; 3505 | } 3506 | 3507 | IndentButton.prototype.name = 'indent'; 3508 | 3509 | IndentButton.prototype.icon = 'indent'; 3510 | 3511 | IndentButton.prototype.title = '向右缩进(Tab)'; 3512 | 3513 | IndentButton.prototype.status = function($node) { 3514 | return true; 3515 | }; 3516 | 3517 | IndentButton.prototype.command = function() { 3518 | return this.editor.util.indent(); 3519 | }; 3520 | 3521 | return IndentButton; 3522 | 3523 | })(Button); 3524 | 3525 | Simditor.Toolbar.addButton(IndentButton); 3526 | 3527 | OutdentButton = (function(_super) { 3528 | __extends(OutdentButton, _super); 3529 | 3530 | function OutdentButton() { 3531 | _ref16 = OutdentButton.__super__.constructor.apply(this, arguments); 3532 | return _ref16; 3533 | } 3534 | 3535 | OutdentButton.prototype.name = 'outdent'; 3536 | 3537 | OutdentButton.prototype.icon = 'outdent'; 3538 | 3539 | OutdentButton.prototype.title = '向左缩进(Shift + Tab)'; 3540 | 3541 | OutdentButton.prototype.status = function($node) { 3542 | return true; 3543 | }; 3544 | 3545 | OutdentButton.prototype.command = function() { 3546 | return this.editor.util.outdent(); 3547 | }; 3548 | 3549 | return OutdentButton; 3550 | 3551 | })(Button); 3552 | 3553 | Simditor.Toolbar.addButton(OutdentButton); 3554 | 3555 | HrButton = (function(_super) { 3556 | __extends(HrButton, _super); 3557 | 3558 | function HrButton() { 3559 | _ref17 = HrButton.__super__.constructor.apply(this, arguments); 3560 | return _ref17; 3561 | } 3562 | 3563 | HrButton.prototype.name = 'hr'; 3564 | 3565 | HrButton.prototype.icon = 'minus'; 3566 | 3567 | HrButton.prototype.title = '分隔线'; 3568 | 3569 | HrButton.prototype.htmlTag = 'hr'; 3570 | 3571 | HrButton.prototype.status = function($node) { 3572 | return true; 3573 | }; 3574 | 3575 | HrButton.prototype.command = function() { 3576 | var $hr, $newBlock, $nextBlock, $rootBlock; 3577 | $rootBlock = this.editor.util.furthestBlockEl(); 3578 | $nextBlock = $rootBlock.next(); 3579 | if ($nextBlock.length > 0) { 3580 | this.editor.selection.save(); 3581 | } else { 3582 | $newBlock = $('

        ').append(this.editor.util.phBr); 3583 | } 3584 | $hr = $('


        ').insertAfter($rootBlock); 3585 | if ($newBlock) { 3586 | $newBlock.insertAfter($hr); 3587 | this.editor.selection.setRangeAtStartOf($newBlock); 3588 | } else { 3589 | this.editor.selection.restore(); 3590 | } 3591 | this.editor.trigger('valuechanged'); 3592 | return this.editor.trigger('selectionchanged'); 3593 | }; 3594 | 3595 | return HrButton; 3596 | 3597 | })(Button); 3598 | 3599 | Simditor.Toolbar.addButton(HrButton); 3600 | 3601 | TableButton = (function(_super) { 3602 | __extends(TableButton, _super); 3603 | 3604 | TableButton.prototype.name = 'table'; 3605 | 3606 | TableButton.prototype.icon = 'table'; 3607 | 3608 | TableButton.prototype.title = '表格'; 3609 | 3610 | TableButton.prototype.htmlTag = 'table'; 3611 | 3612 | TableButton.prototype.disableTag = 'pre, li, blockquote'; 3613 | 3614 | TableButton.prototype.menu = true; 3615 | 3616 | function TableButton() { 3617 | var args, 3618 | _this = this; 3619 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 3620 | TableButton.__super__.constructor.apply(this, args); 3621 | $.merge(this.editor.formatter._allowedTags, ['tbody', 'tr', 'td', 'colgroup', 'col']); 3622 | $.extend(this.editor.formatter._allowedAttributes, { 3623 | td: ['rowspan', 'colspan'], 3624 | col: ['width'] 3625 | }); 3626 | this.editor.on('decorate', function(e, $el) { 3627 | return $el.find('table').each(function(i, table) { 3628 | return _this.decorate($(table)); 3629 | }); 3630 | }); 3631 | this.editor.on('undecorate', function(e, $el) { 3632 | return $el.find('table').each(function(i, table) { 3633 | return _this.undecorate($(table)); 3634 | }); 3635 | }); 3636 | this.editor.on('selectionchanged.table', function(e) { 3637 | var $container, range; 3638 | _this.editor.body.find('.simditor-table td').removeClass('active'); 3639 | range = _this.editor.selection.getRange(); 3640 | if (range == null) { 3641 | return; 3642 | } 3643 | $container = $(range.commonAncestorContainer); 3644 | if (range.collapsed && $container.is('.simditor-table')) { 3645 | if (_this.editor.selection.rangeAtStartOf($container)) { 3646 | $container = $container.find('td:first'); 3647 | } else { 3648 | $container = $container.find('td:last'); 3649 | } 3650 | _this.editor.selection.setRangeAtEndOf($container); 3651 | } 3652 | return $container.closest('td', _this.editor.body).addClass('active'); 3653 | }); 3654 | this.editor.on('blur.table', function(e) { 3655 | return _this.editor.body.find('.simditor-table td').removeClass('active'); 3656 | }); 3657 | this.editor.inputManager.addKeystrokeHandler('38', 'td', function(e, $node) { 3658 | var $prevTr, $tr, index; 3659 | $tr = $node.parent('tr'); 3660 | $prevTr = $tr.prev('tr'); 3661 | if (!($prevTr.length > 0)) { 3662 | return true; 3663 | } 3664 | index = $tr.find('td').index($node); 3665 | _this.editor.selection.setRangeAtEndOf($prevTr.find('td').eq(index)); 3666 | return true; 3667 | }); 3668 | this.editor.inputManager.addKeystrokeHandler('40', 'td', function(e, $node) { 3669 | var $nextTr, $tr, index; 3670 | $tr = $node.parent('tr'); 3671 | $nextTr = $tr.next('tr'); 3672 | if (!($nextTr.length > 0)) { 3673 | return true; 3674 | } 3675 | index = $tr.find('td').index($node); 3676 | _this.editor.selection.setRangeAtEndOf($nextTr.find('td').eq(index)); 3677 | return true; 3678 | }); 3679 | } 3680 | 3681 | TableButton.prototype.initResize = function($table) { 3682 | var $colgroup, $resizeHandle, $wrapper, 3683 | _this = this; 3684 | $wrapper = $table.parent('.simditor-table'); 3685 | $colgroup = $table.find('colgroup'); 3686 | if ($colgroup.length < 1) { 3687 | $colgroup = $('').prependTo($table); 3688 | $table.find('tr:first td').each(function(i, td) { 3689 | var $col; 3690 | return $col = $('').appendTo($colgroup); 3691 | }); 3692 | this.refreshTableWidth($table); 3693 | } 3694 | $resizeHandle = $('
        ').appendTo($wrapper); 3695 | $wrapper.on('mousemove', 'td', function(e) { 3696 | var $col, $td, index, x, _ref18, _ref19; 3697 | if ($wrapper.hasClass('resizing')) { 3698 | return; 3699 | } 3700 | $td = $(e.currentTarget); 3701 | x = e.pageX - $(e.currentTarget).offset().left; 3702 | if (x < 5 && $td.prev().length > 0) { 3703 | $td = $td.prev(); 3704 | } 3705 | if ($td.next('td').length < 1) { 3706 | $resizeHandle.hide(); 3707 | return; 3708 | } 3709 | if ((_ref18 = $resizeHandle.data('td')) != null ? _ref18.is($td) : void 0) { 3710 | $resizeHandle.show(); 3711 | return; 3712 | } 3713 | index = $td.parent().find('td').index($td); 3714 | $col = $colgroup.find('col').eq(index); 3715 | if ((_ref19 = $resizeHandle.data('col')) != null ? _ref19.is($col) : void 0) { 3716 | $resizeHandle.show(); 3717 | return; 3718 | } 3719 | return $resizeHandle.css('left', $td.position().left + $td.outerWidth() - 5).data('td', $td).data('col', $col).show(); 3720 | }); 3721 | $wrapper.on('mouseleave', function(e) { 3722 | return $resizeHandle.hide(); 3723 | }); 3724 | return $wrapper.on('mousedown', '.simditor-resize-handle', function(e) { 3725 | var $handle, $leftCol, $leftTd, $rightCol, $rightTd, minWidth, startHandleLeft, startLeftWidth, startRightWidth, startX, tableWidth; 3726 | $handle = $(e.currentTarget); 3727 | $leftTd = $handle.data('td'); 3728 | $leftCol = $handle.data('col'); 3729 | $rightTd = $leftTd.next('td'); 3730 | $rightCol = $leftCol.next('col'); 3731 | startX = e.pageX; 3732 | startLeftWidth = $leftTd.outerWidth() * 1; 3733 | startRightWidth = $rightTd.outerWidth() * 1; 3734 | startHandleLeft = parseFloat($handle.css('left')); 3735 | tableWidth = $leftTd.closest('table').width(); 3736 | minWidth = 50; 3737 | $(document).on('mousemove.simditor-resize-table', function(e) { 3738 | var deltaX, leftWidth, rightWidth; 3739 | deltaX = e.pageX - startX; 3740 | leftWidth = startLeftWidth + deltaX; 3741 | rightWidth = startRightWidth - deltaX; 3742 | if (leftWidth < minWidth) { 3743 | leftWidth = minWidth; 3744 | deltaX = minWidth - startLeftWidth; 3745 | rightWidth = startRightWidth - deltaX; 3746 | } else if (rightWidth < minWidth) { 3747 | rightWidth = minWidth; 3748 | deltaX = startRightWidth - minWidth; 3749 | leftWidth = startLeftWidth + deltaX; 3750 | } 3751 | $leftCol.attr('width', (leftWidth / tableWidth * 100) + '%'); 3752 | $rightCol.attr('width', (rightWidth / tableWidth * 100) + '%'); 3753 | return $handle.css('left', startHandleLeft + deltaX); 3754 | }); 3755 | $(document).one('mouseup.simditor-resize-table', function(e) { 3756 | $(document).off('.simditor-resize-table'); 3757 | return $wrapper.removeClass('resizing'); 3758 | }); 3759 | $wrapper.addClass('resizing'); 3760 | return false; 3761 | }); 3762 | }; 3763 | 3764 | TableButton.prototype.decorate = function($table) { 3765 | if ($table.parent('.simditor-table').length > 0) { 3766 | this.undecorate($table); 3767 | } 3768 | $table.wrap('
        '); 3769 | this.initResize($table); 3770 | return $table.parent(); 3771 | }; 3772 | 3773 | TableButton.prototype.undecorate = function($table) { 3774 | if (!($table.parent('.simditor-table').length > 0)) { 3775 | return; 3776 | } 3777 | return $table.parent().replaceWith($table); 3778 | }; 3779 | 3780 | TableButton.prototype.renderMenu = function() { 3781 | var _this = this; 3782 | $('\n').appendTo(this.menuWrapper); 3783 | this.createMenu = this.menuWrapper.find('.menu-create-table'); 3784 | this.editMenu = this.menuWrapper.find('.menu-edit-table'); 3785 | this.createTable(6, 6).appendTo(this.createMenu); 3786 | this.createMenu.on('mouseenter', 'td', function(e) { 3787 | var $td, $tr, num; 3788 | _this.createMenu.find('td').removeClass('selected'); 3789 | $td = $(e.currentTarget); 3790 | $tr = $td.parent(); 3791 | num = $tr.find('td').index($td) + 1; 3792 | return $tr.prevAll('tr').addBack().find('td:lt(' + num + ')').addClass('selected'); 3793 | }); 3794 | this.createMenu.on('mouseleave', function(e) { 3795 | return $(e.currentTarget).find('td').removeClass('selected'); 3796 | }); 3797 | return this.createMenu.on('mousedown', 'td', function(e) { 3798 | var $closestBlock, $table, $td, $tr, colNum, rowNum; 3799 | _this.wrapper.removeClass('menu-on'); 3800 | if (!_this.editor.inputManager.focused) { 3801 | return; 3802 | } 3803 | $td = $(e.currentTarget); 3804 | $tr = $td.parent(); 3805 | colNum = $tr.find('td').index($td) + 1; 3806 | rowNum = $tr.prevAll('tr').length + 1; 3807 | $table = _this.createTable(rowNum, colNum, true); 3808 | $closestBlock = _this.editor.util.closestBlockEl(); 3809 | if (_this.editor.util.isEmptyNode($closestBlock)) { 3810 | $closestBlock.replaceWith($table); 3811 | } else { 3812 | $closestBlock.after($table); 3813 | } 3814 | _this.decorate($table); 3815 | _this.editor.selection.setRangeAtStartOf($table.find('td:first')); 3816 | _this.editor.trigger('valuechanged'); 3817 | _this.editor.trigger('selectionchanged'); 3818 | return false; 3819 | }); 3820 | }; 3821 | 3822 | TableButton.prototype.createTable = function(row, col, phBr) { 3823 | var $table, $tbody, $td, $tr, c, r, _i, _j; 3824 | $table = $(''); 3825 | $tbody = $('').appendTo($table); 3826 | for (r = _i = 0; 0 <= row ? _i < row : _i > row; r = 0 <= row ? ++_i : --_i) { 3827 | $tr = $('').appendTo($tbody); 3828 | for (c = _j = 0; 0 <= col ? _j < col : _j > col; c = 0 <= col ? ++_j : --_j) { 3829 | $td = $(''); 3890 | for (i = _i = 1; 1 <= colNum ? _i <= colNum : _i >= colNum; i = 1 <= colNum ? ++_i : --_i) { 3891 | $(''); 3936 | $col[direction]($newCol); 3937 | tableWidth = $table.width(); 3938 | width = Math.max(parseFloat($col.attr('width')) / 2, 50 / tableWidth * 100); 3939 | $col.attr('width', width + '%'); 3940 | $newCol.attr('width', width + '%'); 3941 | this.refreshTableWidth($table); 3942 | $newTd = direction === 'after' ? $td.next('td') : $td.prev('td'); 3943 | return this.editor.selection.setRangeAtStartOf($newTd); 3944 | }; 3945 | 3946 | TableButton.prototype.deleteTable = function($td) { 3947 | var $block, $table; 3948 | $table = $td.closest('.simditor-table'); 3949 | $block = $table.next('p'); 3950 | $table.remove(); 3951 | if ($block.length > 0) { 3952 | return this.editor.selection.setRangeAtStartOf($block); 3953 | } 3954 | }; 3955 | 3956 | TableButton.prototype.command = function(param) { 3957 | var $td, range; 3958 | range = this.editor.selection.getRange(); 3959 | $td = $(range.commonAncestorContainer).closest('td'); 3960 | if (!($td.length > 0)) { 3961 | return; 3962 | } 3963 | if (param === 'deleteRow') { 3964 | this.deleteRow($td); 3965 | } else if (param === 'insertRowAbove') { 3966 | this.insertRow($td, 'before'); 3967 | } else if (param === 'insertRowBelow') { 3968 | this.insertRow($td); 3969 | } else if (param === 'deleteCol') { 3970 | this.deleteCol($td); 3971 | } else if (param === 'insertColLeft') { 3972 | this.insertCol($td, 'before'); 3973 | } else if (param === 'insertColRight') { 3974 | this.insertCol($td); 3975 | } else if (param === 'deleteTable') { 3976 | this.deleteTable($td); 3977 | } else { 3978 | return; 3979 | } 3980 | this.editor.trigger('valuechanged'); 3981 | return this.editor.trigger('selectionchanged'); 3982 | }; 3983 | 3984 | return TableButton; 3985 | 3986 | })(Button); 3987 | 3988 | Simditor.Toolbar.addButton(TableButton); 3989 | 3990 | StrikethroughButton = (function(_super) { 3991 | __extends(StrikethroughButton, _super); 3992 | 3993 | function StrikethroughButton() { 3994 | _ref18 = StrikethroughButton.__super__.constructor.apply(this, arguments); 3995 | return _ref18; 3996 | } 3997 | 3998 | StrikethroughButton.prototype.name = 'strikethrough'; 3999 | 4000 | StrikethroughButton.prototype.icon = 'strikethrough'; 4001 | 4002 | StrikethroughButton.prototype.title = '删除线文字'; 4003 | 4004 | StrikethroughButton.prototype.htmlTag = 'strike'; 4005 | 4006 | StrikethroughButton.prototype.disableTag = 'pre'; 4007 | 4008 | StrikethroughButton.prototype.status = function($node) { 4009 | var active; 4010 | if ($node != null) { 4011 | this.setDisabled($node.is(this.disableTag)); 4012 | } 4013 | if (this.disabled) { 4014 | return true; 4015 | } 4016 | active = document.queryCommandState('strikethrough') === true; 4017 | this.setActive(active); 4018 | return active; 4019 | }; 4020 | 4021 | StrikethroughButton.prototype.command = function() { 4022 | document.execCommand('strikethrough'); 4023 | this.editor.trigger('valuechanged'); 4024 | return this.editor.trigger('selectionchanged'); 4025 | }; 4026 | 4027 | return StrikethroughButton; 4028 | 4029 | })(Button); 4030 | 4031 | Simditor.Toolbar.addButton(StrikethroughButton); 4032 | 4033 | }).call(this); 4034 | --------------------------------------------------------------------------------
        ').appendTo($tr); 3830 | if (phBr) { 3831 | $td.append(this.editor.util.phBr); 3832 | } 3833 | } 3834 | } 3835 | return $table; 3836 | }; 3837 | 3838 | TableButton.prototype.refreshTableWidth = function($table) { 3839 | var cols, tableWidth, 3840 | _this = this; 3841 | tableWidth = $table.width(); 3842 | cols = $table.find('col'); 3843 | return $table.find('tr:first td').each(function(i, td) { 3844 | var $col; 3845 | $col = cols.eq(i); 3846 | return $col.attr('width', ($(td).outerWidth() / tableWidth * 100) + '%'); 3847 | }); 3848 | }; 3849 | 3850 | TableButton.prototype.setActive = function(active) { 3851 | TableButton.__super__.setActive.call(this, active); 3852 | if (active) { 3853 | this.createMenu.hide(); 3854 | return this.editMenu.show(); 3855 | } else { 3856 | this.createMenu.show(); 3857 | return this.editMenu.hide(); 3858 | } 3859 | }; 3860 | 3861 | TableButton.prototype.deleteRow = function($td) { 3862 | var $newTr, $tr, index; 3863 | $tr = $td.parent('tr'); 3864 | if ($tr.siblings('tr').length < 1) { 3865 | return this.deleteTable($td); 3866 | } else { 3867 | $newTr = $tr.next('tr'); 3868 | if (!($newTr.length > 0)) { 3869 | $newTr = $tr.prev('tr'); 3870 | } 3871 | index = $tr.find('td').index($td); 3872 | $tr.remove(); 3873 | return this.editor.selection.setRangeAtEndOf($newTr.find('td').eq(index)); 3874 | } 3875 | }; 3876 | 3877 | TableButton.prototype.insertRow = function($td, direction) { 3878 | var $newTr, $table, $tr, colNum, i, index, _i, 3879 | _this = this; 3880 | if (direction == null) { 3881 | direction = 'after'; 3882 | } 3883 | $tr = $td.parent('tr'); 3884 | $table = $tr.closest('table'); 3885 | colNum = 0; 3886 | $table.find('tr').each(function(i, tr) { 3887 | return colNum = Math.max(colNum, $(tr).find('td').length); 3888 | }); 3889 | $newTr = $('
        ').append(this.editor.util.phBr).appendTo($newTr); 3892 | } 3893 | $tr[direction]($newTr); 3894 | index = $tr.find('td').index($td); 3895 | return this.editor.selection.setRangeAtStartOf($newTr.find('td').eq(index)); 3896 | }; 3897 | 3898 | TableButton.prototype.deleteCol = function($td) { 3899 | var $newTd, $table, $tr, index, 3900 | _this = this; 3901 | $tr = $td.parent('tr'); 3902 | if ($tr.siblings('tr').length < 1 && $td.siblings('td').length < 1) { 3903 | return this.deleteTable($td); 3904 | } else { 3905 | index = $tr.find('td').index($td); 3906 | $newTd = $td.next('td'); 3907 | if (!($newTd.length > 0)) { 3908 | $newTd = $tr.prev('td'); 3909 | } 3910 | $table = $tr.closest('table'); 3911 | $table.find('col').eq(index).remove(); 3912 | $table.find('tr').each(function(i, tr) { 3913 | return $(tr).find('td').eq(index).remove(); 3914 | }); 3915 | this.refreshTableWidth($table); 3916 | return this.editor.selection.setRangeAtEndOf($newTd); 3917 | } 3918 | }; 3919 | 3920 | TableButton.prototype.insertCol = function($td, direction) { 3921 | var $col, $newCol, $newTd, $table, $tr, index, tableWidth, width, 3922 | _this = this; 3923 | if (direction == null) { 3924 | direction = 'after'; 3925 | } 3926 | $tr = $td.parent('tr'); 3927 | index = $tr.find('td').index($td); 3928 | $table = $td.closest('table'); 3929 | $col = $table.find('col').eq(index); 3930 | $table.find('tr').each(function(i, tr) { 3931 | var $newTd; 3932 | $newTd = $('').append(_this.editor.util.phBr); 3933 | return $(tr).find('td').eq(index)[direction]($newTd); 3934 | }); 3935 | $newCol = $('