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