annotate media/js/tiny_mce/plugins/tabfocus/editor_plugin_src.js @ 81:e356ea79a7a2

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