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