From eeb34ba3566ea824c45b918268f57e6c97d60081 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Fri, 27 Aug 2010 06:35:37 -0400
Subject: [PATCH] - Fix Tab key doesn't work in HTML editor in Google Chrome (#1486925)

---
 CHANGELOG                                                 |    1 
 program/js/editor.js                                      |    4 +-
 program/js/tiny_mce/plugins/tabfocus/editor_plugin_src.js |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 program/js/tiny_mce/plugins/tabfocus/editor_plugin.js     |    1 
 4 files changed, 116 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 8bb15ad..83ad13f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,7 @@
 - Fix contacts list page controls when a group is selected (#1486946)
 - Fix SMTP test in Installer (#1486952)
 - Fix "Select all" causes message to be opened in folder with exactly one message (#1486913)
+- Fix Tab key doesn't work in HTML editor in Google Chrome (#1486925)
 
 RELEASE 0.4
 -----------
diff --git a/program/js/editor.js b/program/js/editor.js
index c81ef25..248c794 100644
--- a/program/js/editor.js
+++ b/program/js/editor.js
@@ -24,7 +24,7 @@
       theme : 'advanced',
       language : editor_lang,
       content_css : skin_path + '/editor_content.css',
-      plugins: 'paste',
+      plugins: 'paste,tabfocus',
       theme_advanced_toolbar_location : 'top',
       theme_advanced_toolbar_align : 'left',
       theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,separator,outdent,indent,charmap,hr,link,unlink,code,forecolor',
@@ -42,7 +42,7 @@
       apply_source_formatting : true,
       theme : 'advanced',
       language : editor_lang,
-      plugins : 'paste,emotions,media,nonbreaking,table,searchreplace,visualchars,directionality' + (spellcheck ? ',spellchecker' : ''),
+      plugins : 'paste,emotions,media,nonbreaking,table,searchreplace,visualchars,directionality,tabfocus' + (spellcheck ? ',spellchecker' : ''),
       theme_advanced_buttons1 : 'bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,outdent,indent,ltr,rtl,blockquote,|,forecolor,backcolor,fontselect,fontsizeselect',
       theme_advanced_buttons2 : 'link,unlink,code,|,emotions,charmap,image,media,|,search' + (spellcheck ? ',spellchecker' : '') + ',undo,redo',
       theme_advanced_buttons3 : '',
diff --git a/program/js/tiny_mce/plugins/tabfocus/editor_plugin.js b/program/js/tiny_mce/plugins/tabfocus/editor_plugin.js
new file mode 100644
index 0000000..27d2440
--- /dev/null
+++ b/program/js/tiny_mce/plugins/tabfocus/editor_plugin.js
@@ -0,0 +1 @@
+(function(){var c=tinymce.DOM,a=tinymce.dom.Event,d=tinymce.each,b=tinymce.explode;tinymce.create("tinymce.plugins.TabFocusPlugin",{init:function(f,g){function e(i,j){if(j.keyCode===9){return a.cancel(j)}}function h(l,p){var j,m,o,n,k;function q(i){o=c.getParent(l.id,"form");n=o.elements;if(o){d(n,function(s,r){if(s.id==l.id){j=r;return false}});if(i>0){for(m=j+1;m<n.length;m++){if(n[m].type!="hidden"){return n[m]}}}else{for(m=j-1;m>=0;m--){if(n[m].type!="hidden"){return n[m]}}}}return null}if(p.keyCode===9){k=b(l.getParam("tab_focus",l.getParam("tabfocus_elements",":prev,:next")));if(k.length==1){k[1]=k[0];k[0]=":prev"}if(p.shiftKey){if(k[0]==":prev"){n=q(-1)}else{n=c.get(k[0])}}else{if(k[1]==":next"){n=q(1)}else{n=c.get(k[1])}}if(n){if(l=tinymce.get(n.id||n.name)){l.focus()}else{window.setTimeout(function(){window.focus();n.focus()},10)}return a.cancel(p)}}}f.onKeyUp.add(e);if(tinymce.isGecko){f.onKeyPress.add(h);f.onKeyDown.add(e)}else{f.onKeyDown.add(h)}f.onInit.add(function(){d(c.select("a:first,a:last",f.getContainer()),function(i){a.add(i,"focus",function(){f.focus()})})})},getInfo:function(){return{longname:"Tabfocus",author:"Moxiecode Systems AB",authorurl:"http://tinymce.moxiecode.com",infourl:"http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/tabfocus",version:tinymce.majorVersion+"."+tinymce.minorVersion}}});tinymce.PluginManager.add("tabfocus",tinymce.plugins.TabFocusPlugin)})();
\ No newline at end of file
diff --git a/program/js/tiny_mce/plugins/tabfocus/editor_plugin_src.js b/program/js/tiny_mce/plugins/tabfocus/editor_plugin_src.js
new file mode 100644
index 0000000..c2be2f4
--- /dev/null
+++ b/program/js/tiny_mce/plugins/tabfocus/editor_plugin_src.js
@@ -0,0 +1,112 @@
+/**
+ * editor_plugin_src.js
+ *
+ * Copyright 2009, Moxiecode Systems AB
+ * Released under LGPL License.
+ *
+ * License: http://tinymce.moxiecode.com/license
+ * Contributing: http://tinymce.moxiecode.com/contributing
+ */
+
+(function() {
+	var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, explode = tinymce.explode;
+
+	tinymce.create('tinymce.plugins.TabFocusPlugin', {
+		init : function(ed, url) {
+			function tabCancel(ed, e) {
+				if (e.keyCode === 9)
+					return Event.cancel(e);
+			};
+
+			function tabHandler(ed, e) {
+				var x, i, f, el, v;
+
+				function find(d) {
+					f = DOM.getParent(ed.id, 'form');
+					el = f.elements;
+
+					if (f) {
+						each(el, function(e, i) {
+							if (e.id == ed.id) {
+								x = i;
+								return false;
+							}
+						});
+
+						if (d > 0) {
+							for (i = x + 1; i < el.length; i++) {
+								if (el[i].type != 'hidden')
+									return el[i];
+							}
+						} else {
+							for (i = x - 1; i >= 0; i--) {
+								if (el[i].type != 'hidden')
+									return el[i];
+							}
+						}
+					}
+
+					return null;
+				};
+
+				if (e.keyCode === 9) {
+					v = explode(ed.getParam('tab_focus', ed.getParam('tabfocus_elements', ':prev,:next')));
+
+					if (v.length == 1) {
+						v[1] = v[0];
+						v[0] = ':prev';
+					}
+
+					// Find element to focus
+					if (e.shiftKey) {
+						if (v[0] == ':prev')
+							el = find(-1);
+						else
+							el = DOM.get(v[0]);
+					} else {
+						if (v[1] == ':next')
+							el = find(1);
+						else
+							el = DOM.get(v[1]);
+					}
+
+					if (el) {
+						if (ed = tinymce.get(el.id || el.name))
+							ed.focus();
+						else
+							window.setTimeout(function() {window.focus();el.focus();}, 10);
+
+						return Event.cancel(e);
+					}
+				}
+			};
+
+			ed.onKeyUp.add(tabCancel);
+
+			if (tinymce.isGecko) {
+				ed.onKeyPress.add(tabHandler);
+				ed.onKeyDown.add(tabCancel);
+			} else
+				ed.onKeyDown.add(tabHandler);
+
+			ed.onInit.add(function() {
+				each(DOM.select('a:first,a:last', ed.getContainer()), function(n) {
+					Event.add(n, 'focus', function() {ed.focus();});
+				});
+			});
+		},
+
+		getInfo : function() {
+			return {
+				longname : 'Tabfocus',
+				author : 'Moxiecode Systems AB',
+				authorurl : 'http://tinymce.moxiecode.com',
+				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/tabfocus',
+				version : tinymce.majorVersion + "." + tinymce.minorVersion
+			};
+		}
+	});
+
+	// Register plugin
+	tinymce.PluginManager.add('tabfocus', tinymce.plugins.TabFocusPlugin);
+})();
\ No newline at end of file

--
Gitblit v1.9.1