Browse Source

Fix event dispatcher with undo manager

pull/36/head
Artur Arseniev 10 years ago
parent
commit
82d5cc560d
  1. 11
      src/canvas/view/CanvasView.js
  2. 1
      src/commands/view/SelectComponent.js
  3. 11
      src/demo.js
  4. 1
      src/editor/model/Editor.js
  5. 2
      src/rich_text_editor/main.js
  6. 7
      src/rich_text_editor/view/TextEditorView.js

11
src/canvas/view/CanvasView.js

@ -45,6 +45,17 @@ function(Backbone, FrameView) {
body.append('<style>' + frameCss + protCss + '</style>');
this.config.em.trigger('loaded');
this.frame.el.contentWindow.onscroll = this.onFrameScroll.bind(this);
// When the iframe is focused the event dispatcher is not the same so
// I need to delegate all events to the parent document
var doc = document;
var fdoc = this.frame.el.contentDocument;
fdoc.addEventListener('keydown', function(e){
doc.dispatchEvent(new KeyboardEvent(e.type, e));
});
fdoc.addEventListener('keyup', function(e){
doc.dispatchEvent(new KeyboardEvent(e.type, e));
});
}
},

1
src/commands/view/SelectComponent.js

@ -271,7 +271,6 @@ define(function() {
if(!this.selEl)
this.selEl = $(this.getCanvasBody()).find('*');
this.frameOff = this.canvasOff = this.adjScroll = null;
$(this.frameEl.contentWindow).off('keydown');
var frameEl = this.canvas.getFrameEl();
frameEl.contentWindow.onscroll = null;

11
src/demo.js

@ -57,7 +57,16 @@ require(['config/require-config'], function() {
{ type: 'image', src : './img/bg-gr-v.png', date: '2015-02-01',height:1, width:1728},
]
},
/*
panels: {
defaults : [{
id : 'commands',
buttons : [{
id : 'selcomp',
className : 'fa fa fa-mouse-pointer',
command : 'select-comp',
}]}]},
*/
/*
panels: {
defaults : [{

1
src/editor/model/Editor.js

@ -382,6 +382,7 @@ define([
this.UndoManager = this.um;
this.set('UndoManager', this.um);
key('⌘+z, ctrl+z', function(){
console.log('Undo');
that.um.undo(true);
});
key('⌘+shift+z, ctrl+shift+z', function(){

2
src/rich_text_editor/main.js

@ -25,7 +25,7 @@ define(function(require) {
* @param {View} view
* */
attach: function(view){
view.$el.wysiwyg({hotKeys: {}}).focus();
view.$el.wysiwyg({}).focus();
if(c.em){
var u = 'px';

7
src/rich_text_editor/view/TextEditorView.js

@ -41,6 +41,7 @@ define(['jquery'],
document.execCommand(command, 0, args);
updateToolbar();
},
/*
bindHotkeys = function (hotKeys) {
$.each(hotKeys, function (hotkey, command) {
editor.keydown(hotkey, function (e) {
@ -57,6 +58,7 @@ define(['jquery'],
});
});
},
*/
getCurrentRange = function () {
var sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
@ -160,13 +162,12 @@ define(['jquery'],
}
options = $.extend({}, $.fn.wysiwyg.defaults, userOptions);
toolbarBtnSelector = 'a[data-' + options.commandRole + '],button[data-' + options.commandRole + '],input[type=button][data-' + options.commandRole + ']';
bindHotkeys(options.hotKeys);
//bindHotkeys(options.hotKeys);
if (options.dragAndDropImages) {
initFileDrops();
}
bindToolbar($(options.toolbarSelector), options);
editor.attr('contenteditable', true)
.on('mouseup keyup mouseout', function () {
editor.attr('contenteditable', true).on('mouseup keyup mouseout', function () {
saveSelection();
updateToolbar();
});

Loading…
Cancel
Save