annotate media/js/tiny_mce/plugins/tabfocus/editor_plugin_src.js @ 201:bc958bc3c6eb

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