thomascube
2011-04-20 a9251be2f09fb5f18a85d201c67668c70980efe3
commit | author | age
eeb34b 1 /**
A 2  * editor_plugin_src.js
3  *
4  * Copyright 2009, Moxiecode Systems AB
5  * Released under LGPL License.
6  *
7  * License: http://tinymce.moxiecode.com/license
8  * Contributing: http://tinymce.moxiecode.com/contributing
9  */
10
11 (function() {
12     var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, explode = tinymce.explode;
13
14     tinymce.create('tinymce.plugins.TabFocusPlugin', {
15         init : function(ed, url) {
16             function tabCancel(ed, e) {
17                 if (e.keyCode === 9)
18                     return Event.cancel(e);
19             };
20
21             function tabHandler(ed, e) {
22                 var x, i, f, el, v;
23
24                 function find(d) {
a9251b 25                     el = DOM.select(':input:enabled,*[tabindex]');
T 26                     function canSelect(e) {
27                         return e.type != 'hidden' && 
28                         e.tabIndex != '-1' && 
29                             !(el[i].style.display == "none") && 
30                             !(el[i].style.visibility == "hidden");
31                     }
eeb34b 32
a9251b 33                     each(el, function(e, i) {
T 34                         if (e.id == ed.id) {
35                             x = i;
36                             return false;
37                         }
38                     });
eeb34b 39
a9251b 40                     if (d > 0) {
T 41                         for (i = x + 1; i < el.length; i++) {
42                             if (canSelect(el[i]))
43                                 return el[i];
44                         }
45                     } else {
46                         for (i = x - 1; i >= 0; i--) {
47                             if (canSelect(el[i]))
48                                 return el[i];
eeb34b 49                         }
A 50                     }
51
52                     return null;
53                 };
54
55                 if (e.keyCode === 9) {
56                     v = explode(ed.getParam('tab_focus', ed.getParam('tabfocus_elements', ':prev,:next')));
57
58                     if (v.length == 1) {
59                         v[1] = v[0];
60                         v[0] = ':prev';
61                     }
62
63                     // Find element to focus
64                     if (e.shiftKey) {
65                         if (v[0] == ':prev')
66                             el = find(-1);
67                         else
68                             el = DOM.get(v[0]);
69                     } else {
70                         if (v[1] == ':next')
71                             el = find(1);
72                         else
73                             el = DOM.get(v[1]);
74                     }
75
76                     if (el) {
a9251b 77                         if (el.id && (ed = tinymce.get(el.id || el.name)))
eeb34b 78                             ed.focus();
A 79                         else
a9251b 80                             window.setTimeout(function() {
T 81                                 if (!tinymce.isWebKit)
82                                     window.focus();
83                                 el.focus();
84                             }, 10);
eeb34b 85
A 86                         return Event.cancel(e);
87                     }
88                 }
89             };
90
91             ed.onKeyUp.add(tabCancel);
92
93             if (tinymce.isGecko) {
94                 ed.onKeyPress.add(tabHandler);
95                 ed.onKeyDown.add(tabCancel);
96             } else
97                 ed.onKeyDown.add(tabHandler);
98
99         },
100
101         getInfo : function() {
102             return {
103                 longname : 'Tabfocus',
104                 author : 'Moxiecode Systems AB',
105                 authorurl : 'http://tinymce.moxiecode.com',
106                 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/tabfocus',
107                 version : tinymce.majorVersion + "." + tinymce.minorVersion
108             };
109         }
110     });
111
112     // Register plugin
113     tinymce.PluginManager.add('tabfocus', tinymce.plugins.TabFocusPlugin);
114 })();