annotate static/js/tiny_mce/plugins/tabfocus/editor_plugin_src.js @ 312:88b2b9cb8c1f

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