]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/tiny_mce/plugins/tabfocus/editor_plugin_src.js
Release 6.2.2
[Github/sugarcrm.git] / include / javascript / tiny_mce / 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                                         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                                     }
32
33                                         each(el, function(e, i) {
34                                                 if (e.id == ed.id) {
35                                                         x = i;
36                                                         return false;
37                                                 }
38                                         });
39
40                                         if (d > 0) {
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];
49                                                 }
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) {
77                                                 if (el.id && (ed = tinymce.get(el.id || el.name)))
78                                                         ed.focus();
79                                                 else
80                                                         window.setTimeout(function() {
81                                                                 if (!tinymce.isWebKit)
82                                                                         window.focus();
83                                                                 el.focus();
84                                                         }, 10);
85
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 })();