X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/653c75b6951e028fe4c68e27cc9852e45fa418a6..687fac27f7a6aacbc140300cd5f40ffe3cc20e89:/project/static/js/editor.js?ds=inline diff --git a/project/static/js/editor.js b/project/static/js/editor.js index 3490b9a1..ac34ac5a 100644 --- a/project/static/js/editor.js +++ b/project/static/js/editor.js @@ -1,3 +1,21 @@ +function Hotkey(code) { + this.code = code + this.has_alt = ((code & 0x01 << 8) != 0) + this.has_ctrl = ((code & 0x01 << 9) != 0) + this.has_shift = ((code & 0x01 << 10) != 0) + this.character = String.fromCharCode(code & 0xff) +} + + +Hotkey.prototype.toString = function() { + mods = [] + if(this.has_alt) mods.push('Alt') + if(this.has_ctrl) mods.push('Ctrl') + if(this.has_shift) mods.push('Shift') + mods.push('"'+this.character+'"') + return mods.join('+') +} + function Panel(panelWrap) { var self = this; self.hotkeys = []; @@ -67,6 +85,10 @@ Panel.prototype.unload = function(event, data) { if( data == this ) { $.log('unloading', this); $(this.contentDiv).html(''); + + // disconnect the toolbar + $('div.panel-toolbar span.panel-toolbar-extra', this.wrap).empty(); + this.callHook('unload'); this.hooks = null; // flush the hooks return false; @@ -119,15 +141,22 @@ Panel.prototype.connectToolbar = function() $.log('Connecting toolbar', toolbar); if(toolbar.length == 0) return; + // move the extra + var extra_buttons = $('span.panel-toolbar-extra', toolbar); + var placeholder = $('div.panel-toolbar span.panel-toolbar-extra', this.wrap); + placeholder.replaceWith(extra_buttons); + + var action_buttons = $('button', extra_buttons); + // connect group-switch buttons var group_buttons = $('*.toolbar-tabs-container button', toolbar); - $.log('Found groups:', group_buttons); + // $.log('Found groups:', group_buttons); group_buttons.each(function() { var group = $(this); var group_name = group.attr('ui:group'); - $.log('Connecting group: ' + group_name); + // $.log('Connecting group: ' + group_name); group.click(function() { // change the active group @@ -147,10 +176,14 @@ Panel.prototype.connectToolbar = function() }); // connect action buttons - var action_buttons = $('*.toolbar-button-groups-container button', toolbar); - action_buttons.each(function() { + var allbuttons = $.makeArray(action_buttons) + $.merge(allbuttons, + $.makeArray($('*.toolbar-button-groups-container button', toolbar)) ); + + $(allbuttons).each(function() { var button = $(this); var hk = button.attr('ui:hotkey'); + if(hk) hk = new Hotkey( parseInt(hk) ); try { var params = $.evalJSON(button.attr('ui:action-params')); @@ -166,15 +199,18 @@ Panel.prototype.connectToolbar = function() // connect button button.click(callback); - + // connect hotkey - if(hk) self.hotkeys[parseInt(hk)] = callback; - + if(hk) { + self.hotkeys[hk.code] = callback; + $.log('hotkey', hk); + } + // tooltip if (button.attr('ui:tooltip') ) { var tooltip = button.attr('ui:tooltip'); - if(hk) tooltip += ' [Alt+'+hk+']'; + if(hk) tooltip += ' ['+hk+']'; button.wTooltip({ delay: 1000, @@ -193,13 +229,24 @@ Panel.prototype.connectToolbar = function() Panel.prototype.hotkeyPressed = function(event) { - var callback = this.hotkeys[event.keyCode]; + code = event.keyCode; + if(event.altKey) code = code | 0x100; + if(event.ctrlKey) code = code | 0x200; + if(event.shiftKey) code = code | 0x400; + + var callback = this.hotkeys[code]; if(callback) callback(); } Panel.prototype.isHotkey = function(event) { - if( event.altKey && (this.hotkeys[event.keyCode] != null) ) + code = event.keyCode; + if(event.altKey) code = code | 0x100; + if(event.ctrlKey) code = code | 0x200; + if(event.shiftKey) code = code | 0x400; + + if(this.hotkeys[code] != null) return true; + return false; } @@ -522,7 +569,7 @@ Editor.prototype.showPopup = function(name, text, timeout) var box = $('#message-box > #' + name); $('*.data', box).html(text || ''); - box.fadeIn(); + box.fadeIn(100); if(timeout > 0) setTimeout( $.fbind(self, self.advancePopupQueue), timeout); @@ -534,14 +581,14 @@ Editor.prototype.advancePopupQueue = function() { if(elem) { var box = $('#message-box > #' + elem[0]); - box.fadeOut(200, function() + box.fadeOut(100, function() { - $('*.data', box).html(); + $('*.data', box).html(''); if( self.popupQueue.length > 0) { var ibox = $('#message-box > #' + self.popupQueue[0][0]); - $('*.data', ibox).html(self.popupQueue[0][1]); - ibox.fadeIn(); + $('*.data', ibox).html(self.popupQueue[0][1] || ''); + ibox.fadeIn(100); if(self.popupQueue[0][2] > 0) setTimeout( $.fbind(self, self.advancePopupQueue), self.popupQueue[0][2]); }