]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/js/tinymce/plugins/tabfocus/editor_plugin_src.js
WordPress 3.4
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / tabfocus / editor_plugin_src.js
1 /**
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) {
25                                         el = DOM.select(':input:enabled,*[tabindex]');
26
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));
31                                         }
32                                         function canSelectInOldIe(el) {
33                                                 return el.attributes["tabIndex"].specified || el.nodeName == "INPUT" || el.nodeName == "TEXTAREA";
34                                         }
35                                         function isOldIe() {
36                                                 return tinymce.isIE6 || tinymce.isIE7;
37                                         }
38                                         function canSelect(el) {
39                                                 return ((!isOldIe() || canSelectInOldIe(el))) && el.getAttribute("tabindex") != '-1' && canSelectRecursive(el);
40                                         }
41
42                                         each(el, function(e, i) {
43                                                 if (e.id == ed.id) {
44                                                         x = i;
45                                                         return false;
46                                                 }
47                                         });
48                                         if (d > 0) {
49                                                 for (i = x + 1; i < el.length; i++) {
50                                                         if (canSelect(el[i]))
51                                                                 return el[i];
52                                                 }
53                                         } else {
54                                                 for (i = x - 1; i >= 0; i--) {
55                                                         if (canSelect(el[i]))
56                                                                 return el[i];
57                                                 }
58                                         }
59
60                                         return null;
61                                 }
62
63                                 if (e.keyCode === 9) {
64                                         v = explode(ed.getParam('tab_focus', ed.getParam('tabfocus_elements', ':prev,:next')));
65
66                                         if (v.length == 1) {
67                                                 v[1] = v[0];
68                                                 v[0] = ':prev';
69                                         }
70
71                                         // Find element to focus
72                                         if (e.shiftKey) {
73                                                 if (v[0] == ':prev')
74                                                         el = find(-1);
75                                                 else
76                                                         el = DOM.get(v[0]);
77                                         } else {
78                                                 if (v[1] == ':next')
79                                                         el = find(1);
80                                                 else
81                                                         el = DOM.get(v[1]);
82                                         }
83
84                                         if (el) {
85                                                 if (el.id && (ed = tinymce.get(el.id || el.name)))
86                                                         ed.focus();
87                                                 else
88                                                         window.setTimeout(function() {
89                                                                 if (!tinymce.isWebKit)
90                                                                         window.focus();
91                                                                 el.focus();
92                                                         }, 10);
93
94                                                 return Event.cancel(e);
95                                         }
96                                 }
97                         }
98
99                         ed.onKeyUp.add(tabCancel);
100
101                         if (tinymce.isGecko) {
102                                 ed.onKeyPress.add(tabHandler);
103                                 ed.onKeyDown.add(tabCancel);
104                         } else
105                                 ed.onKeyDown.add(tabHandler);
106
107                 },
108
109                 getInfo : function() {
110                         return {
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
116                         };
117                 }
118         });
119
120         // Register plugin
121         tinymce.PluginManager.add('tabfocus', tinymce.plugins.TabFocusPlugin);
122 })();