├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── bower.json ├── css └── bootstrap-markdown.min.css ├── js └── bootstrap-markdown.js ├── less └── bootstrap-markdown.less ├── locale ├── bootstrap-markdown.ar.js ├── bootstrap-markdown.cs.js ├── bootstrap-markdown.da.js ├── bootstrap-markdown.de.js ├── bootstrap-markdown.es.js ├── bootstrap-markdown.fa.js ├── bootstrap-markdown.fr.js ├── bootstrap-markdown.hu.js ├── bootstrap-markdown.it.js ├── bootstrap-markdown.ja.js ├── bootstrap-markdown.kr.js ├── bootstrap-markdown.nb.js ├── bootstrap-markdown.nl.js ├── bootstrap-markdown.pl.js ├── bootstrap-markdown.ptBR.js ├── bootstrap-markdown.ru.js ├── bootstrap-markdown.sl.js ├── bootstrap-markdown.sv.js ├── bootstrap-markdown.tr.js ├── bootstrap-markdown.ua.js ├── bootstrap-markdown.zh-tw.js └── bootstrap-markdown.zh.js ├── package.json └── scss └── bootstrap-markdown.scss /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_style = space 9 | indent_size = 2 10 | end_of_line = lf 11 | trim_trailing_whitespace = true 12 | insert_final_newline = true 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bower_components 2 | .DS_Store 3 | node_modules/* 4 | .idea 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Bootstrap Markdown 2 | 3 | Markdown editing meets Bootstrap. 4 | 5 | Demo and documentation available at [http://toopay.github.io/bootstrap-markdown/](http://toopay.github.io/bootstrap-markdown/) 6 | 7 | ### Compatibility 8 | 9 | | Version | Compatibility | 10 | | :---: | :---: | 11 | | v2.x | **only** Bootstrap 3.x | 12 | | v1.x | **only** Bootstrap 2.x | 13 | 14 | ### LICENSE 15 | 16 | > Copyright 2013-2016 Taufan Aditya 17 | > 18 | > Licensed under the Apache License, Version 2.0 (the "License"); 19 | > you may not use this file except in compliance with the License. 20 | > You may obtain a copy of the License at 21 | > 22 | > http://www.apache.org/licenses/LICENSE-2.0 23 | > 24 | > Unless required by applicable law or agreed to in writing, software 25 | > distributed under the License is distributed on an "AS IS" BASIS, 26 | > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | > See the License for the specific language governing permissions and 28 | > limitations under the License. 29 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bootstrap-markdown", 3 | "version": "2.10.0", 4 | "main": ["./js/bootstrap-markdown.js", "./css/bootstrap-markdown.min.css"], 5 | "license": "Apache-2.0", 6 | "dependencies": { 7 | "bootstrap": "~3" 8 | }, 9 | "devDependencies": { 10 | "markdown":"~0.4.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /css/bootstrap-markdown.min.css: -------------------------------------------------------------------------------- 1 | .md-editor{display:block;border:1px solid #ddd}.md-editor .md-footer,.md-editor>.md-header{display:block;padding:6px 4px;background:#f5f5f5}.md-editor>.md-header{margin:0}.md-editor>.md-preview{background:#fff;border-top:1px dashed #ddd;border-bottom:1px dashed #ddd;min-height:10px;overflow:auto}.md-editor>textarea{font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:14px;outline:0;margin:0;display:block;padding:0;width:100%;border:0;border-top:1px dashed #ddd;border-bottom:1px dashed #ddd;border-radius:0;box-shadow:none;background:#eee}.md-editor>textarea:focus{box-shadow:none;background:#fff}.md-editor.active{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.md-editor .md-controls{float:right;padding:3px}.md-editor .md-controls .md-control{right:5px;color:#bebebe;padding:3px 3px 3px 10px}.md-editor .md-controls .md-control:hover{color:#333}.md-editor.md-fullscreen-mode{width:100%;height:100%;position:fixed;top:0;left:0;z-index:99999;padding:60px 30px 15px;background:#fff!important;border:0!important}.md-editor.md-fullscreen-mode .md-footer{display:none}.md-editor.md-fullscreen-mode .md-input,.md-editor.md-fullscreen-mode .md-preview{margin:0 auto!important;height:100%!important;font-size:20px!important;padding:20px!important;color:#999;line-height:1.6em!important;resize:none!important;box-shadow:none!important;background:#fff!important;border:0!important}.md-editor.md-fullscreen-mode .md-preview{color:#333;overflow:auto}.md-editor.md-fullscreen-mode .md-input:focus,.md-editor.md-fullscreen-mode .md-input:hover{color:#333;background:#fff!important}.md-editor.md-fullscreen-mode .md-header{background:0 0;text-align:center;position:fixed;width:100%;top:20px}.md-editor.md-fullscreen-mode .btn-group{float:none}.md-editor.md-fullscreen-mode .btn{border:0;background:0 0;color:#b3b3b3}.md-editor.md-fullscreen-mode .btn.active,.md-editor.md-fullscreen-mode .btn:active,.md-editor.md-fullscreen-mode .btn:focus,.md-editor.md-fullscreen-mode .btn:hover{box-shadow:none;color:#333}.md-editor.md-fullscreen-mode .md-fullscreen-controls{position:absolute;top:20px;right:20px;text-align:right;z-index:1002;display:block}.md-editor.md-fullscreen-mode .md-fullscreen-controls a{color:#b3b3b3;clear:right;margin:10px;width:30px;height:30px;text-align:center}.md-editor.md-fullscreen-mode .md-fullscreen-controls a:hover{color:#333;text-decoration:none}.md-editor.md-fullscreen-mode .md-editor{height:100%!important;position:relative}.md-editor .md-fullscreen-controls{display:none}.md-nooverflow{overflow:hidden;position:fixed;width:100%} -------------------------------------------------------------------------------- /js/bootstrap-markdown.js: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * bootstrap-markdown.js v2.10.0 3 | * http://github.com/toopay/bootstrap-markdown 4 | * =================================================== 5 | * Copyright 2013-2016 Taufan Aditya 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ========================================================== */ 19 | (function(factory) { 20 | if (typeof define === "function" && define.amd) { 21 | // RequireJS 22 | define(["jquery"], factory); 23 | } else if (typeof exports === 'object') { 24 | // Backbone.js 25 | factory(require('jquery')); 26 | } else { 27 | // jQuery plugin 28 | factory(jQuery); 29 | } 30 | }(function($) { 31 | "use strict"; 32 | 33 | /* MARKDOWN CLASS DEFINITION 34 | * ========================== */ 35 | 36 | var Markdown = function(element, options) { 37 | // @TODO : remove this BC on next major release 38 | // @see : https://github.com/toopay/bootstrap-markdown/issues/109 39 | var opts = ['autofocus', 'savable', 'hideable', 'width', 40 | 'height', 'resize', 'iconlibrary', 'language', 41 | 'footer', 'fullscreen', 'hiddenButtons', 'disabledButtons' 42 | ]; 43 | $.each(opts, function(_, opt) { 44 | if (typeof $(element).data(opt) !== 'undefined') { 45 | options = typeof options == 'object' ? options : {}; 46 | options[opt] = $(element).data(opt); 47 | } 48 | }); 49 | // End BC 50 | 51 | // Class Properties 52 | this.$ns = 'bootstrap-markdown'; 53 | this.$element = $(element); 54 | this.$editable = { 55 | el: null, 56 | type: null, 57 | attrKeys: [], 58 | attrValues: [], 59 | content: null 60 | }; 61 | this.$options = $.extend(true, {}, $.fn.markdown.defaults, options, this.$element.data('options')); 62 | this.$oldContent = null; 63 | this.$isPreview = false; 64 | this.$isFullscreen = false; 65 | this.$editor = null; 66 | this.$textarea = null; 67 | this.$handler = []; 68 | this.$callback = []; 69 | this.$nextTab = []; 70 | 71 | this.showEditor(); 72 | }; 73 | 74 | Markdown.prototype = { 75 | 76 | constructor: Markdown, 77 | __alterButtons: function(name, alter) { 78 | var handler = this.$handler, 79 | isAll = (name == 'all'), 80 | that = this; 81 | 82 | $.each(handler, function(k, v) { 83 | var halt = true; 84 | if (isAll) { 85 | halt = false; 86 | } else { 87 | halt = v.indexOf(name) < 0; 88 | } 89 | 90 | if (halt === false) { 91 | alter(that.$editor.find('button[data-handler="' + v + '"]')); 92 | } 93 | }); 94 | }, 95 | __buildButtons: function(buttonsArray, container) { 96 | var i, 97 | ns = this.$ns, 98 | handler = this.$handler, 99 | callback = this.$callback; 100 | 101 | for (i = 0; i < buttonsArray.length; i++) { 102 | // Build each group container 103 | var y, btnGroups = buttonsArray[i]; 104 | for (y = 0; y < btnGroups.length; y++) { 105 | // Build each button group 106 | var z, 107 | buttons = btnGroups[y].data, 108 | btnGroupContainer = $('
', { 109 | 'class': 'btn-group' 110 | }); 111 | 112 | for (z = 0; z < buttons.length; z++) { 113 | var button = buttons[z], 114 | buttonContainer, buttonIconContainer, 115 | buttonHandler = ns + '-' + button.name, 116 | buttonIcon = this.__getIcon(button), 117 | btnText = button.btnText ? button.btnText : '', 118 | btnClass = button.btnClass ? button.btnClass : 'btn', 119 | tabIndex = button.tabIndex ? button.tabIndex : '-1', 120 | hotkey = typeof button.hotkey !== 'undefined' ? button.hotkey : '', 121 | hotkeyCaption = typeof jQuery.hotkeys !== 'undefined' && hotkey !== '' ? ' (' + hotkey + ')' : ''; 122 | 123 | // Construct the button object 124 | buttonContainer = $(''); 125 | buttonContainer.text(' ' + this.__localize(btnText)).addClass('btn-default btn-sm').addClass(btnClass); 126 | if (btnClass.match(/btn\-(primary|success|info|warning|danger|link)/)) { 127 | buttonContainer.removeClass('btn-default'); 128 | } 129 | buttonContainer.attr({ 130 | 'type': 'button', 131 | 'title': this.__localize(button.title) + hotkeyCaption, 132 | 'tabindex': tabIndex, 133 | 'data-provider': ns, 134 | 'data-handler': buttonHandler, 135 | 'data-hotkey': hotkey 136 | }); 137 | if (button.toggle === true) { 138 | buttonContainer.attr('data-toggle', 'button'); 139 | } 140 | buttonIconContainer = $(''); 141 | buttonIconContainer.addClass(buttonIcon); 142 | buttonIconContainer.prependTo(buttonContainer); 143 | 144 | // Attach the button object 145 | btnGroupContainer.append(buttonContainer); 146 | 147 | // Register handler and callback 148 | handler.push(buttonHandler); 149 | callback.push(button.callback); 150 | } 151 | 152 | // Attach the button group into container DOM 153 | container.append(btnGroupContainer); 154 | } 155 | } 156 | 157 | return container; 158 | }, 159 | __setListener: function() { 160 | // Set size and resizable Properties 161 | var hasRows = typeof this.$textarea.attr('rows') !== 'undefined', 162 | maxRows = this.$textarea.val().split("\n").length > 5 ? this.$textarea.val().split("\n").length : '5', 163 | rowsVal = hasRows ? this.$textarea.attr('rows') : maxRows; 164 | 165 | this.$textarea.attr('rows', rowsVal); 166 | if (this.$options.resize) { 167 | this.$textarea.css('resize', this.$options.resize); 168 | } 169 | 170 | // Re-attach markdown data 171 | this.$textarea.data('markdown', this); 172 | }, 173 | __setEventListeners: function() { 174 | this.$textarea.on({ 175 | 'focus': $.proxy(this.focus, this), 176 | 'keyup': $.proxy(this.keyup, this), 177 | 'change': $.proxy(this.change, this), 178 | 'select': $.proxy(this.select, this) 179 | }); 180 | 181 | if (this.eventSupported('keydown')) { 182 | this.$textarea.on('keydown', $.proxy(this.keydown, this)); 183 | } 184 | 185 | if (this.eventSupported('keypress')) { 186 | this.$textarea.on('keypress', $.proxy(this.keypress, this)); 187 | } 188 | }, 189 | __handle: function(e) { 190 | var target = $(e.currentTarget), 191 | handler = this.$handler, 192 | callback = this.$callback, 193 | handlerName = target.attr('data-handler'), 194 | callbackIndex = handler.indexOf(handlerName), 195 | callbackHandler = callback[callbackIndex]; 196 | 197 | // Trigger the focusin 198 | $(e.currentTarget).focus(); 199 | 200 | callbackHandler(this); 201 | 202 | // Trigger onChange for each button handle 203 | this.change(this); 204 | 205 | // Unless it was the save handler, 206 | // focusin the textarea 207 | if (handlerName.indexOf('cmdSave') < 0) { 208 | this.$textarea.focus(); 209 | } 210 | 211 | e.preventDefault(); 212 | }, 213 | __localize: function(string) { 214 | var messages = $.fn.markdown.messages, 215 | language = this.$options.language; 216 | if ( 217 | typeof messages !== 'undefined' && 218 | typeof messages[language] !== 'undefined' && 219 | typeof messages[language][string] !== 'undefined' 220 | ) { 221 | return messages[language][string]; 222 | } 223 | return string; 224 | }, 225 | __getIcon: function(src) { 226 | if(typeof src == 'object'){ 227 | var customIcon = this.$options.customIcons[src.name]; 228 | return typeof customIcon == 'undefined' ? src.icon[this.$options.iconlibrary] : customIcon; 229 | } else { 230 | return src; 231 | } 232 | }, 233 | setFullscreen: function(mode) { 234 | var $editor = this.$editor, 235 | $textarea = this.$textarea; 236 | 237 | if (mode === true) { 238 | $editor.addClass('md-fullscreen-mode'); 239 | $('body').addClass('md-nooverflow'); 240 | this.$options.onFullscreen(this); 241 | } else { 242 | $editor.removeClass('md-fullscreen-mode'); 243 | $('body').removeClass('md-nooverflow'); 244 | this.$options.onFullscreenExit(this); 245 | 246 | if (this.$isPreview === true) 247 | this.hidePreview().showPreview(); 248 | } 249 | 250 | this.$isFullscreen = mode; 251 | $textarea.focus(); 252 | }, 253 | showEditor: function() { 254 | var instance = this, 255 | textarea, 256 | ns = this.$ns, 257 | container = this.$element, 258 | originalHeigth = container.css('height'), 259 | originalWidth = container.css('width'), 260 | editable = this.$editable, 261 | handler = this.$handler, 262 | callback = this.$callback, 263 | options = this.$options, 264 | editor = $('
', { 265 | 'class': 'md-editor', 266 | click: function() { 267 | instance.focus(); 268 | } 269 | }); 270 | 271 | // Prepare the editor 272 | if (this.$editor === null) { 273 | // Create the panel 274 | var editorHeader = $('
', { 275 | 'class': 'md-header btn-toolbar' 276 | }); 277 | 278 | // Merge the main & additional button groups together 279 | var allBtnGroups = []; 280 | if (options.buttons.length > 0) allBtnGroups = allBtnGroups.concat(options.buttons[0]); 281 | if (options.additionalButtons.length > 0) { 282 | // iterate the additional button groups 283 | $.each(options.additionalButtons[0], function(idx, buttonGroup) { 284 | 285 | // see if the group name of the additional group matches an existing group 286 | var matchingGroups = $.grep(allBtnGroups, function(allButtonGroup, allIdx) { 287 | return allButtonGroup.name === buttonGroup.name; 288 | }); 289 | 290 | // if it matches add the additional buttons to that group, if not just add it to the all buttons group 291 | if (matchingGroups.length > 0) { 292 | matchingGroups[0].data = matchingGroups[0].data.concat(buttonGroup.data); 293 | } else { 294 | allBtnGroups.push(options.additionalButtons[0][idx]); 295 | } 296 | 297 | }); 298 | } 299 | 300 | // Reduce and/or reorder the button groups 301 | if (options.reorderButtonGroups.length > 0) { 302 | allBtnGroups = allBtnGroups 303 | .filter(function(btnGroup) { 304 | return options.reorderButtonGroups.indexOf(btnGroup.name) > -1; 305 | }) 306 | .sort(function(a, b) { 307 | if (options.reorderButtonGroups.indexOf(a.name) < options.reorderButtonGroups.indexOf(b.name)) return -1; 308 | if (options.reorderButtonGroups.indexOf(a.name) > options.reorderButtonGroups.indexOf(b.name)) return 1; 309 | return 0; 310 | }); 311 | } 312 | 313 | // Build the buttons 314 | if (allBtnGroups.length > 0) { 315 | editorHeader = this.__buildButtons([allBtnGroups], editorHeader); 316 | } 317 | 318 | if (options.fullscreen.enable) { 319 | editorHeader.append('
').on('click', '.md-control-fullscreen', function(e) { 320 | e.preventDefault(); 321 | instance.setFullscreen(true); 322 | }); 323 | } 324 | 325 | editor.append(editorHeader); 326 | 327 | // Wrap the textarea 328 | if (container.is('textarea')) { 329 | container.before(editor); 330 | textarea = container; 331 | textarea.addClass('md-input'); 332 | editor.append(textarea); 333 | } else { 334 | var rawContent = (typeof toMarkdown == 'function') ? toMarkdown(container.html()) : container.html(), 335 | currentContent = $.trim(rawContent); 336 | 337 | // This is some arbitrary content that could be edited 338 | textarea = $('