annotate WebContent/jscripts/tiny_mce/plugins/tabfocus/editor_plugin_src.js @ 10:0bdfe01e30b5

checking auth token works now.
author casties
date Tue, 20 Mar 2012 15:55:51 +0100
parents 0be9d53a6967
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
2 * editor_plugin_src.js
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
3 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
4 * Copyright 2009, Moxiecode Systems AB
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
5 * Released under LGPL License.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
6 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
7 * License: http://tinymce.moxiecode.com/license
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
8 * Contributing: http://tinymce.moxiecode.com/contributing
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
9 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
10
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
11 (function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
12 var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, explode = tinymce.explode;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
13
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
14 tinymce.create('tinymce.plugins.TabFocusPlugin', {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
15 init : function(ed, url) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
16 function tabCancel(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
17 if (e.keyCode === 9)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
18 return Event.cancel(e);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
19 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
20
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
21 function tabHandler(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
22 var x, i, f, el, v;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
23
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
24 function find(d) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
25 el = DOM.select(':input:enabled,*[tabindex]');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
26
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
27 function canSelectRecursive(e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
28 return e.nodeName==="BODY" || (e.type != 'hidden' &&
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
29 !(e.style.display == "none") &&
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
30 !(e.style.visibility == "hidden") && canSelectRecursive(e.parentNode));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
31 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
32 function canSelectInOldIe(el) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
33 return el.attributes["tabIndex"].specified || el.nodeName == "INPUT" || el.nodeName == "TEXTAREA";
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
34 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
35 function isOldIe() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
36 return tinymce.isIE6 || tinymce.isIE7;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
37 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
38 function canSelect(el) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
39 return ((!isOldIe() || canSelectInOldIe(el))) && el.getAttribute("tabindex") != '-1' && canSelectRecursive(el);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
40 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
41
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
42 each(el, function(e, i) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
43 if (e.id == ed.id) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
44 x = i;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
45 return false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
46 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
47 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
48 if (d > 0) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
49 for (i = x + 1; i < el.length; i++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
50 if (canSelect(el[i]))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
51 return el[i];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
52 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
53 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
54 for (i = x - 1; i >= 0; i--) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
55 if (canSelect(el[i]))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
56 return el[i];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
57 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
58 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
59
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
60 return null;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
61 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
62
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
63 if (e.keyCode === 9) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
64 v = explode(ed.getParam('tab_focus', ed.getParam('tabfocus_elements', ':prev,:next')));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
65
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
66 if (v.length == 1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
67 v[1] = v[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
68 v[0] = ':prev';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
69 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
70
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
71 // Find element to focus
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
72 if (e.shiftKey) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
73 if (v[0] == ':prev')
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
74 el = find(-1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
75 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
76 el = DOM.get(v[0]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
77 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
78 if (v[1] == ':next')
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
79 el = find(1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
80 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
81 el = DOM.get(v[1]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
82 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
83
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
84 if (el) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
85 if (el.id && (ed = tinymce.get(el.id || el.name)))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
86 ed.focus();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
87 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
88 window.setTimeout(function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
89 if (!tinymce.isWebKit)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
90 window.focus();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
91 el.focus();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
92 }, 10);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
93
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
94 return Event.cancel(e);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
95 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
96 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
97 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
98
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
99 ed.onKeyUp.add(tabCancel);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
100
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
101 if (tinymce.isGecko) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
102 ed.onKeyPress.add(tabHandler);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
103 ed.onKeyDown.add(tabCancel);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
104 } else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
105 ed.onKeyDown.add(tabHandler);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
106
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
107 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
108
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
109 getInfo : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
110 return {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
111 longname : 'Tabfocus',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
112 author : 'Moxiecode Systems AB',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
113 authorurl : 'http://tinymce.moxiecode.com',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
114 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/tabfocus',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
115 version : tinymce.majorVersion + "." + tinymce.minorVersion
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
116 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
117 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
118 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
119
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
120 // Register plugin
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
121 tinymce.PluginManager.add('tabfocus', tinymce.plugins.TabFocusPlugin);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
122 })();