4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
12 var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, explode = tinymce.explode;
14 tinymce.create('tinymce.plugins.TabFocusPlugin', {
15 init : function(ed, url) {
16 function tabCancel(ed, e) {
18 return Event.cancel(e);
21 function tabHandler(ed, e) {
25 el = DOM.select(':input:enabled,*[tabindex]');
27 function canSelectRecursive(e) {
28 return e.nodeName==="BODY" || (e.type != 'hidden' &&
29 !(e.style.display == "none") &&
30 !(e.style.visibility == "hidden") && canSelectRecursive(e.parentNode));
32 function canSelectInOldIe(el) {
33 return el.attributes["tabIndex"].specified || el.nodeName == "INPUT" || el.nodeName == "TEXTAREA";
36 return tinymce.isIE6 || tinymce.isIE7;
38 function canSelect(el) {
39 return ((!isOldIe() || canSelectInOldIe(el))) && el.getAttribute("tabindex") != '-1' && canSelectRecursive(el);
42 each(el, function(e, i) {
49 for (i = x + 1; i < el.length; i++) {
54 for (i = x - 1; i >= 0; i--) {
63 if (e.keyCode === 9) {
64 v = explode(ed.getParam('tab_focus', ed.getParam('tabfocus_elements', ':prev,:next')));
71 // Find element to focus
85 if (el.id && (ed = tinymce.get(el.id || el.name)))
88 window.setTimeout(function() {
89 if (!tinymce.isWebKit)
94 return Event.cancel(e);
99 ed.onKeyUp.add(tabCancel);
101 if (tinymce.isGecko) {
102 ed.onKeyPress.add(tabHandler);
103 ed.onKeyDown.add(tabCancel);
105 ed.onKeyDown.add(tabHandler);
109 getInfo : function() {
111 longname : 'Tabfocus',
112 author : 'Moxiecode Systems AB',
113 authorurl : 'http://tinymce.moxiecode.com',
114 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/tabfocus',
115 version : tinymce.majorVersion + "." + tinymce.minorVersion
121 tinymce.PluginManager.add('tabfocus', tinymce.plugins.TabFocusPlugin);