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@442: el = DOM.select(':input:enabled,*[tabindex]'); bgneal@442: function canSelect(e) { bgneal@442: return e.type != 'hidden' && bgneal@442: e.tabIndex != '-1' && bgneal@442: !(el[i].style.display == "none") && bgneal@442: !(el[i].style.visibility == "hidden"); bgneal@442: } bgneal@312: bgneal@442: each(el, function(e, i) { bgneal@442: if (e.id == ed.id) { bgneal@442: x = i; bgneal@442: return false; bgneal@442: } bgneal@442: }); bgneal@312: bgneal@442: if (d > 0) { bgneal@442: for (i = x + 1; i < el.length; i++) { bgneal@442: if (canSelect(el[i])) bgneal@442: return el[i]; bgneal@442: } bgneal@442: } else { bgneal@442: for (i = x - 1; i >= 0; i--) { bgneal@442: if (canSelect(el[i])) bgneal@442: return el[i]; 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@442: if (el.id && (ed = tinymce.get(el.id || el.name))) bgneal@312: ed.focus(); bgneal@312: else bgneal@442: window.setTimeout(function() { bgneal@442: if (!tinymce.isWebKit) bgneal@442: window.focus(); bgneal@442: el.focus(); bgneal@442: }, 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: }, 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: })();