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