[geeklog-hg] geeklog: CKEditor: added showprotected plugin.

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sun Feb 9 07:46:44 EST 2014


changeset 9486:f798368f431c
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/f798368f431c
user: dengen <taharaxp at gmail.com>
date: Sun Feb 09 21:43:30 2014 +0900
description:
CKEditor: added showprotected plugin.
It makes protected source sections visible and editable.
Especially important for [code]..[/code] and [raw]..[/raw] tags.

Public site of the original source code:
https://github.com/IGx89/CKEditor-ShowProtected-Plugin

diffstat:

 public_html/editors/ckeditor/config.js                                  |    5 +
 public_html/editors/ckeditor/plugins/showprotected/dialogs/protected.js |   74 ++++++
 public_html/editors/ckeditor/plugins/showprotected/images/code.gif      |  Bin 
 public_html/editors/ckeditor/plugins/showprotected/plugin.js            |  109 ++++++++++
 4 files changed, 188 insertions(+), 0 deletions(-)

diffs (209 lines):

diff -r be8712880089 -r f798368f431c public_html/editors/ckeditor/config.js
--- a/public_html/editors/ckeditor/config.js	Sun Feb 09 11:19:18 2014 +0900
+++ b/public_html/editors/ckeditor/config.js	Sun Feb 09 21:43:30 2014 +0900
@@ -83,6 +83,11 @@
 	// config.language = 'fr';
 	// config.uiColor = '#AADC6E';
 
+	// Add extra plugins
+	// Makes protected source sections visible and editable.
+	// Especially important for [code]..[/code] and [raw]..[/raw] for Geeklog.
+	config.extraPlugins = 'showprotected';
+
 	// Disable Advanced Content Filter
 	config.allowedContent = true;
 
diff -r be8712880089 -r f798368f431c public_html/editors/ckeditor/plugins/showprotected/dialogs/protected.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/public_html/editors/ckeditor/plugins/showprotected/dialogs/protected.js	Sun Feb 09 21:43:30 2014 +0900
@@ -0,0 +1,74 @@
+
+CKEDITOR.dialog.add( 'showProtectedDialog', function( editor ) {
+
+	var size = CKEDITOR.document.getWindow().getViewPaneSize();
+
+	// Make it maximum 700px wide, but still fully visible in the viewport.
+	var width = Math.min(size.width - 30, 700);
+
+	// Make it maximum 300px high, but still fully visible in the viewport.
+	var height = Math.min(size.height - 130, 300);
+
+	return {
+		title: 'Edit Protected Source',
+		minWidth: width,
+		minHeight: height,
+
+		onOk: function() {
+			var newSourceValue = this.getContentElement( 'main', 'protectedSource' ).getValue();
+			
+			var encodedSourceValue = CKEDITOR.plugins.showprotected.encodeProtectedSource( newSourceValue );
+			
+			this._.selectedElement.setAttribute('data-cke-realelement', encodedSourceValue);
+			this._.selectedElement.setAttribute('title', newSourceValue);
+			this._.selectedElement.setAttribute('alt', newSourceValue);
+		},
+
+		onHide: function() {
+			delete this._.selectedElement;
+		},
+
+		onShow: function() {
+			this._.selectedElement = editor.getSelection().getSelectedElement();
+			
+			var decodedSourceValue = CKEDITOR.plugins.showprotected.decodeProtectedSource( this._.selectedElement.getAttribute('data-cke-realelement') );
+
+			this.setValueOf( 'main', 'protectedSource', decodedSourceValue );
+
+			if (typeof jQuery !== undefined) {
+				var jqobj = jQuery('.cke_dialog_contents_body');
+				// Fine-tune padding.
+				jqobj.css('padding','10px');
+				// Make textarea height resizable.
+				jqobj.find('div').css('height','100%');
+				jqobj.find('table').css('height','100%');
+				jqobj.find('td').css('height','100%');
+				jqobj.find('textarea').css('height','100%');
+			}
+		},
+		contents: [ {
+			id: 'main',
+			label: 'Edit Protected Source',
+			accessKey: 'I',
+			elements: [ {
+				type: 'textarea',
+				id: 'protectedSource',
+				dir: 'ltr',
+				inputStyle: 'cursor:auto;' +
+					'width:100%;' +
+					'height:' + height + 'px;' +
+					'tab-size:4;' +
+					'text-align:left;',
+				'class': 'cke_source',
+				required: true,
+				validate: function() {
+					if ( !this.getValue() ) {
+						alert( 'The value cannot be empty' );
+						return false;
+					}
+					return true;
+				}
+			} ]
+		} ]
+	};
+} );
diff -r be8712880089 -r f798368f431c public_html/editors/ckeditor/plugins/showprotected/images/code.gif
Binary file public_html/editors/ckeditor/plugins/showprotected/images/code.gif has changed
diff -r be8712880089 -r f798368f431c public_html/editors/ckeditor/plugins/showprotected/plugin.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/public_html/editors/ckeditor/plugins/showprotected/plugin.js	Sun Feb 09 21:43:30 2014 +0900
@@ -0,0 +1,109 @@
+/*
+ *  "showprotected" CKEditor plugin
+ *  http://ckeditor.com/addon/showprotected
+ *  https://github.com/IGx89/CKEditor-ShowProtected-Plugin
+ *  
+ *  Created by Matthew Lieder (https://github.com/IGx89)
+ *  
+ *  Modified by Yoshinori Tahara (taharaxp AT gmail DOT com)
+ *  
+ *  Licensed under the MIT, GPL, LGPL and MPL licenses
+ *  
+ *  Icon courtesy of famfamfam: http://www.famfamfam.com/lab/icons/mini/
+ */
+
+// TODO: configuration settings
+// TODO: show the actual text inline, not just an icon?
+// TODO: improve copy/paste behavior (tooltip is wrong after paste)
+
+CKEDITOR.plugins.add( 'showprotected', {
+	requires: 'dialog,fakeobjects',
+	onLoad: function() {
+		// Add the CSS styles for protected source placeholders.
+		var iconPath = CKEDITOR.getUrl( this.path + 'images' + '/code.gif' ),
+			baseStyle = 'background:url(' + iconPath + ') no-repeat %1 center;border:1px dotted #00f;background-size:16px;';
+
+		var template = '.%2 img.cke_protected' +
+			'{' +
+				baseStyle +
+				'width:16px;' +
+				'min-height:15px;' +
+				// The default line-height on IE.
+				'height:1.15em;' +
+				// Opera works better with "middle" (even if not perfect)
+				'vertical-align:' + ( CKEDITOR.env.opera ? 'middle' : 'text-bottom' ) + ';' +
+			'}';
+
+		// Styles with contents direction awareness.
+		function cssWithDir( dir ) {
+			return template.replace( /%1/g, dir == 'rtl' ? 'right' : 'left' ).replace( /%2/g, 'cke_contents_' + dir );
+		}
+
+		CKEDITOR.addCss( cssWithDir( 'ltr' ) + cssWithDir( 'rtl' ) );
+	},
+
+	init: function( editor ) {
+		CKEDITOR.dialog.add( 'showProtectedDialog', this.path + 'dialogs/protected.js' );
+		
+		editor.on( 'doubleclick', function( evt ) {
+			var element = evt.data.element;
+
+			if ( element.is( 'img' ) && element.hasClass( 'cke_protected' ) ) {
+				evt.data.dialog = 'showProtectedDialog';
+			}
+		} );
+	},
+
+	afterInit: function( editor ) {
+		// Register a filter to displaying placeholders after mode change.
+
+		var dataProcessor = editor.dataProcessor,
+			dataFilter = dataProcessor && dataProcessor.dataFilter;
+
+		if ( dataFilter ) {
+			dataFilter.addRules( {
+				comment: function( commentText, commentElement ) {
+					if(commentText.indexOf(CKEDITOR.plugins.showprotected.protectedSourceMarker) == 0) {
+						commentElement.attributes = [];
+						var fakeElement = editor.createFakeParserElement( commentElement, 'cke_protected', 'protected' );
+						
+						var cleanedCommentText = CKEDITOR.plugins.showprotected.decodeProtectedSource( commentText );
+						fakeElement.attributes.title = fakeElement.attributes.alt = cleanedCommentText;
+						
+						return fakeElement;
+					}
+					
+					return null;
+				}
+			} );
+		}
+	}
+} );
+
+/**
+ * Set of showprotected plugin's helpers.
+ *
+ * @class
+ * @singleton
+ */
+CKEDITOR.plugins.showprotected = {
+		
+	protectedSourceMarker: '{cke_protected}',
+		
+	decodeProtectedSource: function( protectedSource ) {
+		if(protectedSource.indexOf('%3C!--') == 0) {
+			return decodeURIComponent(protectedSource).replace( /<!--\{cke_protected\}([\s\S]+?)-->/g, function( match, data ) {
+                return decodeURIComponent( data );
+			} );
+		} else {
+			return decodeURIComponent(protectedSource.substr(CKEDITOR.plugins.showprotected.protectedSourceMarker.length));
+		}
+	},
+	
+	encodeProtectedSource: function( protectedSource ) {
+		return '<!--' + CKEDITOR.plugins.showprotected.protectedSourceMarker +
+        	encodeURIComponent( protectedSource ).replace( /--/g, '%2D%2D' ) +
+        	'-->';
+	}
+	
+};
\ No newline at end of file



More information about the geeklog-cvs mailing list