comparison static/js/tiny_mce/plugins/tabfocus/editor_plugin_src.js @ 312:88b2b9cb8c1f

Fixing #142; cut over to the django.contrib.staticfiles app.
author Brian Neal <bgneal@gmail.com>
date Thu, 27 Jan 2011 02:56:10 +0000
parents
children 6c182ceb7147
comparison
equal deleted inserted replaced
311:b1c39788e511 312:88b2b9cb8c1f
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 f = DOM.getParent(ed.id, 'form');
26 el = f.elements;
27
28 if (f) {
29 each(el, function(e, i) {
30 if (e.id == ed.id) {
31 x = i;
32 return false;
33 }
34 });
35
36 if (d > 0) {
37 for (i = x + 1; i < el.length; i++) {
38 if (el[i].type != 'hidden')
39 return el[i];
40 }
41 } else {
42 for (i = x - 1; i >= 0; i--) {
43 if (el[i].type != 'hidden')
44 return el[i];
45 }
46 }
47 }
48
49 return null;
50 };
51
52 if (e.keyCode === 9) {
53 v = explode(ed.getParam('tab_focus', ed.getParam('tabfocus_elements', ':prev,:next')));
54
55 if (v.length == 1) {
56 v[1] = v[0];
57 v[0] = ':prev';
58 }
59
60 // Find element to focus
61 if (e.shiftKey) {
62 if (v[0] == ':prev')
63 el = find(-1);
64 else
65 el = DOM.get(v[0]);
66 } else {
67 if (v[1] == ':next')
68 el = find(1);
69 else
70 el = DOM.get(v[1]);
71 }
72
73 if (el) {
74 if (ed = tinymce.get(el.id || el.name))
75 ed.focus();
76 else
77 window.setTimeout(function() {window.focus();el.focus();}, 10);
78
79 return Event.cancel(e);
80 }
81 }
82 };
83
84 ed.onKeyUp.add(tabCancel);
85
86 if (tinymce.isGecko) {
87 ed.onKeyPress.add(tabHandler);
88 ed.onKeyDown.add(tabCancel);
89 } else
90 ed.onKeyDown.add(tabHandler);
91
92 ed.onInit.add(function() {
93 each(DOM.select('a:first,a:last', ed.getContainer()), function(n) {
94 Event.add(n, 'focus', function() {ed.focus();});
95 });
96 });
97 },
98
99 getInfo : function() {
100 return {
101 longname : 'Tabfocus',
102 author : 'Moxiecode Systems AB',
103 authorurl : 'http://tinymce.moxiecode.com',
104 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/tabfocus',
105 version : tinymce.majorVersion + "." + tinymce.minorVersion
106 };
107 }
108 });
109
110 // Register plugin
111 tinymce.PluginManager.add('tabfocus', tinymce.plugins.TabFocusPlugin);
112 })();