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