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