/dev/qulogic/ckeditor: 944187a73817: Add the autogrow plugin to ...

Elliott Sales de Andrade qulogic at pidgin.im
Fri Aug 9 03:13:30 EDT 2013


Changeset: 944187a7381772deafae9e90409256b4cb62d1bb
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2013-08-08 05:38 -0400
Branch:	 default
URL: https://hg.pidgin.im/dev/qulogic/ckeditor/rev/944187a73817

Description:

Add the autogrow plugin to size the ckeditor.

diffstat:

 pidgin/ckeditor/build-config.js |   3 ++-
 pidgin/ckeditor/ckeditor.js     |   5 ++++-
 pidgin/ckeditor/config.js       |   4 ++++
 pidgin/gtkconv.c                |  10 +++++++++-
 pidgin/gtkwebview.c             |  16 ++++++++++++++++
 pidgin/gtkwebview.h             |   9 +++++++++
 6 files changed, 44 insertions(+), 3 deletions(-)

diffs (120 lines):

diff --git a/pidgin/ckeditor/build-config.js b/pidgin/ckeditor/build-config.js
--- a/pidgin/ckeditor/build-config.js
+++ b/pidgin/ckeditor/build-config.js
@@ -44,7 +44,8 @@ var CKBUILDER_CONFIG = {
 		'font' : 1,
 		'horizontalrule' : 1,
 		'removeformat' : 1,
-		'divarea' : 1
+		'divarea' : 1,
+		'autogrow' : 1
 	},
 	languages : {
 		'af' : 1,
diff --git a/pidgin/ckeditor/ckeditor.js b/pidgin/ckeditor/ckeditor.js
--- a/pidgin/ckeditor/ckeditor.js
+++ b/pidgin/ckeditor/ckeditor.js
@@ -648,4 +648,7 @@ CKEDITOR.plugins.add("font",{requires:"r
 CKEDITOR.config.font_defaultLabel="";CKEDITOR.config.font_style={element:"span",styles:{"font-family":"#(family)"},overrides:[{element:"font",attributes:{face:null}}]};CKEDITOR.config.fontSize_sizes="8/8px;9/9px;10/10px;11/11px;12/12px;14/14px;16/16px;18/18px;20/20px;22/22px;24/24px;26/26px;28/28px;36/36px;48/48px;72/72px";CKEDITOR.config.fontSize_defaultLabel="";CKEDITOR.config.fontSize_style={element:"span",styles:{"font-size":"#(size)"},overrides:[{element:"font",attributes:{size:null}}]};(function(){var b={canUndo:!1,exec:function(a){var b=a.document.createElement("hr");a.insertElement(b)},allowedContent:"hr",requiredContent:"hr"};CKEDITOR.plugins.add("horizontalrule",{init:function(a){a.blockless||(a.addCommand("horizontalrule",b),a.ui.addButton&&a.ui.addButton("HorizontalRule",{label:a.lang.horizontalrule.toolbar,command:"horizontalrule",toolbar:"insert,40"}))}})})();CKEDITOR.plugins.add("removeformat",{init:function(a){a.addCommand("removeFormat",CKEDITOR.plugins.removeformat.commands.removeformat);a.ui.addButton&&a.ui.addButton("RemoveFormat",{label:a.lang.removeformat.toolbar,command:"removeFormat",toolbar:"cleanup,10"})}});
 CKEDITOR.plugins.removeformat={commands:{removeformat:{exec:function(a){for(var h=a._.removeFormatRegex||(a._.removeFormatRegex=RegExp("^(?:"+a.config.removeFormatTags.replace(/,/g,"|")+")$","i")),e=a._.removeAttributes||(a._.removeAttributes=a.config.removeFormatAttributes.split(",")),f=CKEDITOR.plugins.removeformat.filter,k=a.getSelection().getRanges(1),l=k.createIterator(),c;c=l.getNextRange();){c.collapsed||c.enlarge(CKEDITOR.ENLARGE_ELEMENT);var i=c.createBookmark(),b=i.startNode,j=i.endNode,
 d=function(b){for(var c=a.elementPath(b),e=c.elements,d=1,g;(g=e[d])&&!g.equals(c.block)&&!g.equals(c.blockLimit);d++)h.test(g.getName())&&f(a,g)&&b.breakParent(g)};d(b);if(j){d(j);for(b=b.getNextSourceNode(!0,CKEDITOR.NODE_ELEMENT);b&&!b.equals(j);)d=b.getNextSourceNode(!1,CKEDITOR.NODE_ELEMENT),!("img"==b.getName()&&b.data("cke-realelement"))&&f(a,b)&&(h.test(b.getName())?b.remove(1):(b.removeAttributes(e),a.fire("removeFormatCleanup",b))),b=d}c.moveToBookmark(i)}a.forceNextSelectionCheck();a.getSelection().selectRanges(k)}}},
-filter:function(a,h){for(var e=a._.removeFormatFilters||[],f=0;f<e.length;f++)if(!1===e[f](h))return!1;return!0}};CKEDITOR.editor.prototype.addRemoveFormatFilter=function(a){this._.removeFormatFilters||(this._.removeFormatFilters=[]);this._.removeFormatFilters.push(a)};CKEDITOR.config.removeFormatTags="b,big,code,del,dfn,em,font,i,ins,kbd,q,s,samp,small,span,strike,strong,sub,sup,tt,u,var";CKEDITOR.config.removeFormatAttributes="class,style,lang,width,height,align,hspace,valign";CKEDITOR.plugins.add("divarea",{afterInit:function(a){a.addMode("wysiwyg",function(c){var b=CKEDITOR.dom.element.createFromHtml('<div class="cke_wysiwyg_div cke_reset" hidefocus="true"></div>');a.ui.space("contents").append(b);b=a.editable(b);b.detach=CKEDITOR.tools.override(b.detach,function(a){return function(){a.apply(this,arguments);this.remove()}});a.setData(a.getData(1),c);a.fire("contentDom")})}});CKEDITOR.config.plugins='basicstyles,dialogui,dialog,clipboard,button,toolbar,enterkey,fakeobjects,link,undo,colordialog,panelbutton,panel,floatpanel,colorbutton,listblock,richcombo,font,horizontalrule,removeformat,divarea';CKEDITOR.config.skin='pidgin';(function() {var setIcons = function(icons, strip) {var path = CKEDITOR.getUrl( 'plugins/' + strip );icons = icons.split( ',' );for ( var i = 0; i < icons.length; i++ )CKEDITOR.skin.icons[ icons[ i ] ] = { path: path, offset: -icons[ ++i ], bgsize : icons[ ++i ] };};if (CKEDITOR.env.hidpi) setIcons('bold,0,,italic,24,,strike,48,,subscript,72,,superscript,96,,underline,120,,copy-rtl,144,,copy,168,,cut-rtl,192,,cut,216,,paste-rtl,240,,paste,264,,anchor-rtl,288,,anchor,312,,link,336,,unlink,360,,redo-rtl,384,,redo,408,,undo-rtl,432,,undo,456,,bgcolor,480,,textcolor,504,,horizontalrule,528,,removeformat,552,','icons_hidpi.png');else setIcons('bold,0,auto,italic,24,auto,strike,48,auto,subscript,72,auto,superscript,96,auto,underline,120,auto,copy-rtl,144,auto,copy,168,auto,cut-rtl,192,auto,cut,216,auto,paste-rtl,240,auto,paste,264,auto,anchor-rtl,288,auto,anchor,312,auto,link,336,auto,unlink,360,auto,redo-rtl,384,auto,redo,408,auto,undo-rtl,432,auto,undo,456,auto,bgcolor,480,auto,textcolor,504,auto,horizontalrule,528,auto,removeformat,552,auto','icons.png');})();CKEDITOR.lang.languages={"af":1,"sq":1,"ar":1,"eu":1,"bn":1,"bs":1,"bg":1,"ca":1,"zh-cn":1,"zh":1,"hr":1,"cs":1,"da":1,"nl":1,"en":1,"en-au":1,"en-ca":1,"en-gb":1,"eo":1,"et":1,"fo":1,"fi":1,"fr":1,"fr-ca":1,"gl":1,"ka":1,"de":1,"el":1,"gu":1,"he":1,"hi":1,"hu":1,"is":1,"id":1,"it":1,"ja":1,"km":1,"ko":1,"ku":1,"lv":1,"lt":1,"mk":1,"ms":1,"mn":1,"no":1,"nb":1,"fa":1,"pl":1,"pt-br":1,"pt":1,"ro":1,"ru":1,"sr":1,"sr-latn":1,"si":1,"sk":1,"sl":1,"es":1,"sv":1,"th":1,"tr":1,"ug":1,"uk":1,"vi":1,"cy":1};}());
+filter:function(a,h){for(var e=a._.removeFormatFilters||[],f=0;f<e.length;f++)if(!1===e[f](h))return!1;return!0}};CKEDITOR.editor.prototype.addRemoveFormatFilter=function(a){this._.removeFormatFilters||(this._.removeFormatFilters=[]);this._.removeFormatFilters.push(a)};CKEDITOR.config.removeFormatTags="b,big,code,del,dfn,em,font,i,ins,kbd,q,s,samp,small,span,strike,strong,sub,sup,tt,u,var";CKEDITOR.config.removeFormatAttributes="class,style,lang,width,height,align,hspace,valign";CKEDITOR.plugins.add("divarea",{afterInit:function(a){a.addMode("wysiwyg",function(c){var b=CKEDITOR.dom.element.createFromHtml('<div class="cke_wysiwyg_div cke_reset" hidefocus="true"></div>');a.ui.space("contents").append(b);b=a.editable(b);b.detach=CKEDITOR.tools.override(b.detach,function(a){return function(){a.apply(this,arguments);this.remove()}});a.setData(a.getData(1),c);a.fire("contentDom")})}});(function(){function i(a){var a=a.document,c=a.getBody(),d=a.getDocumentElement();return"BackCompat"==a.$.compatMode?c:d}var h=function(a,c){if(!a.window)return null;var d=a.getCommand("maximize");if(d&&d.state==CKEDITOR.TRISTATE_ON)return null;var d=i(a),f=a.window.getViewPaneSize().height,b;b=d.getStyle("overflow-y");var g=d.getDocument(),e=CKEDITOR.dom.element.createFromHtml('<span style="margin:0;padding:0;border:0;clear:both;width:1px;height:1px;display:block;">'+(CKEDITOR.env.webkit?" ":
+"")+"</span>",g);g[CKEDITOR.env.ie?"getBody":"getDocumentElement"]().append(e);g=e.getDocumentPosition(g).y+e.$.offsetHeight;e.remove();d.setStyle("overflow-y",b);b=g+(a.config.autoGrow_bottomSpace||0);e=a.config.autoGrow_maxHeight||Infinity;b=Math.max(b,void 0!=a.config.autoGrow_minHeight?a.config.autoGrow_minHeight:200);b=Math.min(b,e);b!=f&&c!=b&&(b=a.fire("autoGrow",{currentHeight:f,newHeight:b}).newHeight,a.resize(a.container.getStyle("width"),b,!0),c=b);d.$.scrollHeight>d.$.clientHeight&&b<
+e?d.setStyle("overflow-y","hidden"):d.removeStyle("overflow-y");return c};CKEDITOR.plugins.add("autogrow",{init:function(a){if(a.elementMode!=CKEDITOR.ELEMENT_MODE_INLINE)a.on("instanceReady",function(){var c;if(a.editable().isInline())a.ui.space("contents").setStyle("height","auto");else{a.addCommand("autogrow",{exec:function(a){c=h(a,c)},modes:{wysiwyg:1},readOnly:1,canUndo:!1,editorFocus:!1});var d={contentDom:1,key:1,selectionChange:1,insertElement:1,mode:1},f;for(f in d)a.on(f,function(a){"wysiwyg"==
+a.editor.mode&&setTimeout(function(){c=h(a.editor,c);c=h(a.editor,c)},100)});a.on("afterCommandExec",function(b){"maximize"==b.data.name&&"wysiwyg"==b.editor.mode&&(b.data.command.state==CKEDITOR.TRISTATE_ON?i(a).removeStyle("overflow"):c=h(a,c))});a.config.autoGrow_onStartup&&a.execCommand("autogrow")}})}})})();CKEDITOR.config.plugins='basicstyles,dialogui,dialog,clipboard,button,toolbar,enterkey,fakeobjects,link,undo,colordialog,panelbutton,panel,floatpanel,colorbutton,listblock,richcombo,font,horizontalrule,removeformat,divarea,autogrow';CKEDITOR.config.skin='pidgin';(function() {var setIcons = function(icons, strip) {var path = CKEDITOR.getUrl( 'plugins/' + strip );icons = icons.split( ',' );for ( var i = 0; i < icons.length; i++ )CKEDITOR.skin.icons[ icons[ i ] ] = { path: path, offset: -icons[ ++i ], bgsize : icons[ ++i ] };};if (CKEDITOR.env.hidpi) setIcons('bold,0,,italic,24,,strike,48,,subscript,72,,superscript,96,,underline,120,,copy-rtl,144,,copy,168,,cut-rtl,192,,cut,216,,paste-rtl,240,,paste,264,,anchor-rtl,288,,anchor,312,,link,336,,unlink,360,,redo-rtl,384,,redo,408,,undo-rtl,432,,undo,456,,bgcolor,480,,textcolor,504,,horizontalrule,528,,removeformat,552,','icons_hidpi.png');else setIcons('bold,0,auto,italic,24,auto,strike,48,auto,subscript,72,auto,superscript,96,auto,underline,120,auto,copy-rtl,144,auto,copy,168,auto,cut-rtl,192,auto,cut,216,auto,paste-rtl,240,auto,paste,264,auto,anchor-rtl,288,auto,anchor,312,auto,link,336,auto,unlink,360,auto,redo-rtl,384,auto,redo,408,auto,undo-rtl,432,auto,undo,456,auto,bgcolor,480,auto,textcolor,504,auto,horizontalrule,528,auto,removeformat,552,auto','icons.png');})();CKEDITOR.lang.languages={"af":1,"sq":1,"ar":1,"eu":1,"bn":1,"bs":1,"bg":1,"ca":1,"zh-cn":1,"zh":1,"hr":1,"cs":1,"da":1,"nl":1,"en":1,"en-au":1,"en-ca":1,"en-gb":1,"eo":1,"et":1,"fo":1,"fi":1,"fr":1,"fr-ca":1,"gl":1,"ka":1,"de":1,"el":1,"gu":1,"he":1,"hi":1,"hu":1,"is":1,"id":1,"it":1,"ja":1,"km":1,"ko":1,"ku":1,"lv":1,"lt":1,"mk":1,"ms":1,"mn":1,"no":1,"nb":1,"fa":1,"pl":1,"pt-br":1,"pt":1,"ro":1,"ru":1,"sr":1,"sr-latn":1,"si":1,"sk":1,"sl":1,"es":1,"sv":1,"th":1,"tr":1,"ug":1,"uk":1,"vi":1,"cy":1};}());
\ No newline at end of file
diff --git a/pidgin/ckeditor/config.js b/pidgin/ckeditor/config.js
--- a/pidgin/ckeditor/config.js
+++ b/pidgin/ckeditor/config.js
@@ -24,6 +24,10 @@ CKEDITOR.editorConfig = function( config
 	// For the complete reference:
 	// http://docs.ckeditor.com/#!/api/CKEDITOR.config
 
+	// Autogrow sizes
+	config.autoGrow_onStartup = true;
+	config.autoGrow_maxHeight = 400;
+
 	// Toolbar configuration
 	config.toolbar = [
 		{ name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline', 'Strike', ] },
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -2308,6 +2308,7 @@ pidgin_conv_switch_active_conversation(P
 	GtkWebView *entry;
 	const char *protocol_name;
 	PurpleConnectionFlags features;
+	int min_lines;
 
 	g_return_if_fail(conv != NULL);
 
@@ -2413,6 +2414,10 @@ pidgin_conv_switch_active_conversation(P
 			(features & PURPLE_CONNECTION_FORMATTING_WBFO));
 	}
 
+	/* Reset minimum height for current font settings. */
+	min_lines = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/minimum_entry_lines");
+	gtk_webview_set_minimum_height(entry, min_lines);
+
 	purple_signal_emit(pidgin_conversations_get_handle(), "conversation-switched", conv);
 
 	gray_stuff_out(gtkconv);
@@ -4852,8 +4857,11 @@ minimum_entry_lines_pref_cb(const char *
 	{
 		conv = (PurpleConversation *)l->data;
 
-		if (PIDGIN_IS_PIDGIN_CONVERSATION(conv))
+		if (PIDGIN_IS_PIDGIN_CONVERSATION(conv)) {
+			gtk_webview_set_minimum_height(GTK_WEBVIEW(PIDGIN_CONVERSATION(conv)->entry),
+			                               GPOINTER_TO_INT(value));
 			resize_webview_cb(PIDGIN_CONVERSATION(conv));
+		}
 
 		l = l->next;
 	}
diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -1858,6 +1858,22 @@ gtk_webview_setup_entry(GtkWebView *webv
 }
 
 void
+gtk_webview_set_minimum_height(GtkWebView *webview, gint lines)
+{
+	char *scr;
+
+	g_return_if_fail(webview != NULL);
+
+	scr = g_strdup_printf("(function() {"
+	                          "var size = CKEDITOR.tools.convertToPx('%dem');"
+	                          "CKEDITOR.config.autoGrow_minHeight = size;"
+	                          ""
+	                      "})();", lines);
+	gtk_webview_safe_execute_script(webview, scr);
+	g_free(scr);
+}
+
+void
 pidgin_webview_set_spellcheck(GtkWebView *webview, gboolean enable)
 {
 	WebKitWebSettings *settings;
diff --git a/pidgin/gtkwebview.h b/pidgin/gtkwebview.h
--- a/pidgin/gtkwebview.h
+++ b/pidgin/gtkwebview.h
@@ -183,6 +183,15 @@ char *gtk_webview_quote_js_string(const 
 void gtk_webview_set_vadjustment(GtkWebView *webview, GtkAdjustment *vadj);
 
 /**
+ * Set the minimum height for the GtkWebView. This setting is only
+ * effective for editable GtkWebViews.
+ *
+ * @param webview  The GtkWebView object
+ * @param lines    The minimum number of lines to show
+ */
+void gtk_webview_set_minimum_height(GtkWebView *webview, gint lines);
+
+/**
  * Scrolls the Webview to the end of its contents.
  *
  * @param webview The GtkWebView object



More information about the Commits mailing list