var DisableContextMenuExtension = MediumEditor.Extension.extend({ name: 'disable-context-menu', init: function () { this.getEditorElements().forEach(function (element) { this.on(element, 'contextmenu', this.handleContextmenu.bind(this)); }, this); //this.subscribe('editableKeydown', this.handleKeydown.bind(this)); }, handleContextmenu: function (event) { if (!event.currentTarget.getAttribute('data-allow-context-menu')) { event.preventDefault(); } }, handleKeydown: function (event, editable) { // If the user hits escape, toggle the data-allow-context-menu attribute if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.ESCAPE)) { if (editable.hasAttribute('data-allow-context-menu')) { editable.removeAttribute('data-allow-context-menu'); } else { editable.setAttribute('data-allow-context-menu', true); } } } }); var KeyboardControlsExtension = MediumEditor.Extension.extend({ name: 'keyboard-controls', mediumDefiningClass: 'medium-editor-element', init: function(){ //PATCH 10/24/2018: fix pre return problem $('.html_code_content').on('keydown', function (e) { //console.log(e.which); switch (e.which) { case 13: document.execCommand('insertHTML', false, '\r\n'); return false; break; case 8: var what = $(this).text() if (!what || what === "") return false; break; } }); $('.html_code_content,.html_content').on('keydown', function(e) { if(e.ctrlKey || e.metaKey) { switch (String.fromCharCode(e.which).toLowerCase()) { case 's': e.preventDefault(); //console.log('ctrl+s'); var inputs = $(this).nextAll('input[type="hidden"]'); if (inputs.length > 0) { var clicker = $('#' + inputs.first().attr('id').replace('hfSetting_HtmlTextBox', 'lbsave')); if (clicker.length > 0) clicker[0].click(); //$(this).nextAll('a[id$="lbSave"]')[0].click(); } return false; break; /*case 'v': e.preventDefault(); break;*/ } } }); $('.html_code_content').on('paste', function(e) { e.preventDefault(); var text = ''; if (e.clipboardData || e.originalEvent.clipboardData) text = (e.originalEvent || e).clipboardData.getData('text/plain'); else if (window.clipboardData) text = window.clipboardData.getData('Text'); text = text.replace(/[\n\r]/g, ''); //if (document.queryCommandSupported('insertHTML')) document.execCommand('insertHTML', false, text); if (document.queryCommandSupported('insertText')) document.execCommand('insertText', false, text); else document.execCommand('paste', false, text); }); } }); var EditBootStrapGridExtension = MediumEditor.Extension.extend({ name: 'edit-bootstrap-grid', mediumDefiningClass: 'medium-editor-element', init: function() { this.getEditorElements().forEach(function(element) { this.on(element, 'keydown', this.handleKeyCheck.bind(this)); }, this); //$('.' + this.mediumDefiningClass + ' div[class*="row"]').on('keydown', this.rowHandler); //$('.' + this.mediumDefiningClass + ' *').on('keydown', this.colHandler); }, handleKeyCheck: function (event) { var target = event.target; }, colHandler: function(event) {}, rowHandler: function(event) {} }); var DisableDragAndDropExtension = MediumEditor.Extension.extend({ name: 'disable-drag-and-drop', init: function() { this.getEditorElements().forEach(function(element){ this.on(element, 'dragstart', this.handleDrag.bind(this)); this.on(element, 'dragover', this.handleOver.bind(this)); this.on(element, 'drop', this.handleDrop.bind(this)); }, this); }, mediumDefiningClass: 'medium-editor-element', dragOverClass: 'draggingover', handleDrag: function (event) { if (!event.target.id) event.target.id = this.name; event.dataTransfer.setData("item", event.target.id); event.dataTransfer.effectAllowed = 'move'; }, handleOver: function (event){ event.preventDefault(); $('.' + this.dragOverClass).removeClass(this.dragOverClass); if (!$(event.target).hasClass(this.mediumDefiningClass)) $(event.target).addClass(this.dragOverClass); event.dataTransfer.dropEffect = "move"; }, handleDrop: function(event) { event.preventDefault(); $('.' + this.dragOverClass).removeClass(this.dragOverClass); var source = document.getElementById(event.dataTransfer.getData("item")); if (source) { //if (!$.contains(event.target, source)) var target = $(event.target); var offset = (event.pageX - target.offset().left) / target.width(); if (target.hasClass(this.mediumDefiningClass) || !target.is('p')) $(source).appendTo(target); else if (offset >= 0.5) target.after(source); else target.before(source); setTimeout(function() { if (source.id == this.name) source.id = ''; source.click(); setTimeout(function() { $('.medium-insert-images:not(:has(img))').remove(); $('.medium-editor-action[data-action="' + ((target.hasClass(this.mediumDefiningClass) || !target.is('p')) ? 'wide' : offset >= 0.5 ? 'right' : 'left') + '"]').click(); }, 100); //medium-editor-action }, 10); } }, handleDragAndDrop: function (event) { event.preventDefault(); alert('Drag and drop is disabled.'); return false; } });