bgneal@45: /** bgneal@183: * editor_plugin_src.js bgneal@45: * bgneal@183: * Copyright 2009, Moxiecode Systems AB bgneal@183: * Released under LGPL License. bgneal@183: * bgneal@183: * License: http://tinymce.moxiecode.com/license bgneal@183: * Contributing: http://tinymce.moxiecode.com/contributing bgneal@45: */ bgneal@45: bgneal@45: (function() { bgneal@45: var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, explode = tinymce.explode; bgneal@45: bgneal@45: tinymce.create('tinymce.plugins.TabFocusPlugin', { bgneal@45: init : function(ed, url) { bgneal@45: function tabCancel(ed, e) { bgneal@45: if (e.keyCode === 9) bgneal@45: return Event.cancel(e); bgneal@45: }; bgneal@45: bgneal@45: function tabHandler(ed, e) { bgneal@45: var x, i, f, el, v; bgneal@45: bgneal@45: function find(d) { bgneal@45: f = DOM.getParent(ed.id, 'form'); bgneal@45: el = f.elements; bgneal@45: bgneal@45: if (f) { bgneal@45: each(el, function(e, i) { bgneal@45: if (e.id == ed.id) { bgneal@45: x = i; bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: if (d > 0) { bgneal@45: for (i = x + 1; i < el.length; i++) { bgneal@45: if (el[i].type != 'hidden') bgneal@45: return el[i]; bgneal@45: } bgneal@45: } else { bgneal@45: for (i = x - 1; i >= 0; i--) { bgneal@45: if (el[i].type != 'hidden') bgneal@45: return el[i]; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return null; bgneal@45: }; bgneal@45: bgneal@45: if (e.keyCode === 9) { bgneal@45: v = explode(ed.getParam('tab_focus', ed.getParam('tabfocus_elements', ':prev,:next'))); bgneal@45: bgneal@45: if (v.length == 1) { bgneal@45: v[1] = v[0]; bgneal@45: v[0] = ':prev'; bgneal@45: } bgneal@45: bgneal@45: // Find element to focus bgneal@45: if (e.shiftKey) { bgneal@45: if (v[0] == ':prev') bgneal@45: el = find(-1); bgneal@45: else bgneal@45: el = DOM.get(v[0]); bgneal@45: } else { bgneal@45: if (v[1] == ':next') bgneal@45: el = find(1); bgneal@45: else bgneal@45: el = DOM.get(v[1]); bgneal@45: } bgneal@45: bgneal@45: if (el) { bgneal@183: if (ed = tinymce.get(el.id || el.name)) bgneal@45: ed.focus(); bgneal@45: else bgneal@45: window.setTimeout(function() {window.focus();el.focus();}, 10); bgneal@45: bgneal@45: return Event.cancel(e); bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: ed.onKeyUp.add(tabCancel); bgneal@45: bgneal@45: if (tinymce.isGecko) { bgneal@45: ed.onKeyPress.add(tabHandler); bgneal@45: ed.onKeyDown.add(tabCancel); bgneal@45: } else bgneal@45: ed.onKeyDown.add(tabHandler); bgneal@45: bgneal@45: ed.onInit.add(function() { bgneal@183: each(DOM.select('a:first,a:last', ed.getContainer()), function(n) { bgneal@45: Event.add(n, 'focus', function() {ed.focus();}); bgneal@45: }); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: getInfo : function() { bgneal@45: return { bgneal@45: longname : 'Tabfocus', bgneal@45: author : 'Moxiecode Systems AB', bgneal@45: authorurl : 'http://tinymce.moxiecode.com', bgneal@45: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/tabfocus', bgneal@45: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@45: }; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Register plugin bgneal@45: tinymce.PluginManager.add('tabfocus', tinymce.plugins.TabFocusPlugin); bgneal@45: })();