Skip to content

Instantly share code, notes, and snippets.

@preaction
Created February 11, 2010 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save preaction/301110 to your computer and use it in GitHub Desktop.
Save preaction/301110 to your computer and use it in GitHub Desktop.
diff --git a/www/extras/yui-webgui/build/code-editor/code-editor.js b/www/extras/yui-webgui/build/code-editor/code-editor.js
index 371de75..ac139c0 100755
--- a/www/extras/yui-webgui/build/code-editor/code-editor.js
+++ b/www/extras/yui-webgui/build/code-editor/code-editor.js
@@ -8,6 +8,7 @@
// Disable Editor configs that don't apply
cfg["animate"] = false;
cfg["dompath"] = false;
+ cfg["focusAtStart"] = false;
// Default toolbar is different
cfg["toolbar"] = cfg["toolbar"] || {
@@ -57,6 +58,8 @@
this.on('editorKeyUp', function(ev) {
// Highlight only if content has changed
+ YAHOO.log( "HTML: " + this.getEditorHTML() );
+ YAHOO.log( "TEXT: " + this.getEditorText() );
if ( this.getEditorText() != this.old_text ) {
Lang.later(10, this, this.highlight);
if ( this.status ) {
@@ -66,6 +69,7 @@
}
}, this, true);
+
//Borrowed this from CodePress: http://codepress.sourceforge.net
this.cc = '\u2009'; // carret char
this.keywords = [
@@ -77,13 +81,13 @@
{ code: /\"(.*?)(\"|<br>|<\/P>)/gi, tag: '<s>"$1$2</s>' }, // strings double quote
{ code: /\'(.*?)(\'|<br>|<\/P>)/gi, tag: '<s>\'$1$2</s>' }, // strings single quote
{ code: /\b(alert|isNaN|parent|Array|parseFloat|parseInt|blur|clearTimeout|prompt|prototype|close|confirm|length|Date|location|Math|document|element|name|self|elements|setTimeout|navigator|status|String|escape|Number|submit|eval|Object|event|onblur|focus|onerror|onfocus|onclick|top|onload|toString|onunload|unescape|open|valueOf|window|onmouseover|innerHTML)\b/g, tag: '<u>$1</u>' }, // special words
- { code: /([^:]|^)\/\/(.*?)(<br|<\/P)/gi, tag: '$1<i>//$2</i>$3' }, // comments //
+ //{ code: /([^:]|^)\/\/(.*?)(<br|<\/P)/gi, tag: '$1<i>//$2</i>$3' }, // comments //
{ code: /\/\*(.*?)\*\//g, tag: '<i>/*$1*/</i>' } // comments / * */
];
//End Borrowed Content
};
- Lang.extend( YAHOO.widget.CodeEditor, YAHOO.widget.Editor, {
+ Lang.extend( YAHOO.widget.CodeEditor, YAHOO.widget.SimpleEditor, {
/**
* @property _defaultCSS
* @description The default CSS used in the config for 'css'. This way you can add to the config like this: { css: YAHOO.widget.SimpleEditor.prototype._defaultCSS + 'ADD MYY CSS HERE' }
@@ -126,7 +130,9 @@
;
}
};
-
+ YAHOO.widget.CodeEditor.prototype._nodeChange = function () {
+ YAHOO.widget.CodeEditor.superclass._nodeChange.call(this);
+ };
/**
* @private
* @method _setupResize
@@ -164,7 +170,7 @@
html = html.replace(/(&nbsp;){4}/g,"\t"); // TODO: make softtabs configurable
html = html.replace(/&nbsp;/g," ");
// Remove spaces at end of lines
- html = html.replace(/\s ?<br>/gi,'\n');
+ html = html.replace(/ ?<br>/gi,'\n');
html = html.replace(/<[^>]+>/g,'');
// If, after all this, we are left with only a \n, user didn't add anything
@@ -193,6 +199,7 @@
YAHOO.widget.CodeEditor.prototype.getEditorText
= function () {
+ //alert( this.getEditorHTML() );
return this.cleanHTML( this.getEditorHTML() );
};
@@ -207,6 +214,7 @@
return;
}
+ // Keep track of where the cursor is right now
if (!focus) {
if (this.browser.gecko) {
this._getSelection().getRangeAt(0).insertNode(this._getDoc().createTextNode(this.cc));
@@ -217,41 +225,47 @@
catch (e) {}
}
}
+
var html = '';
html = this._getDoc().body.innerHTML;
+
+ // Remove existing highlighting
//if (this.browser.opera) {
// html = html.replace(/<(?!span|\/span|br).*?>/gi,'');
//} else
if (this.browser.webkit) {
- //YAHOO.log('1: ' + html);
html = html.replace(/<\/div>/ig, '');
html = html.replace(/<br><div>/ig, '<br>');
html = html.replace(/<div>/ig, '<br>');
html = html.replace(/<br>/ig,'\n');
html = html.replace(/<[^>]*>/g,'');
html = html.replace(/\r?\n/g,'<br>');
- //YAHOO.log('2: ' + html);
} else {
if (this.browser.ie) {
html = html.replace(/<SPAN><\/SPAN>/ig, '');
+ // Special case for <A ... /A>, IE adds these automatically
+ html = html.replace(/<A[^>]*>(.*?)<\/A>/ig,'$1');
}
- YAHOO.log(html);
// &nbsp; before <br> for IE7
- html = html.replace(/(&nbsp;)?<br[^>]*>/gi,'$1\n');
+ html = html.replace(/(&nbsp;)?<br[^>]*>/gi, "$1\n");
html = html.replace(/<\/div>/ig, '');
html = html.replace(/<br><div>/ig, '<br>');
html = html.replace(/<div>/ig, '<br>');
html = html.replace(/<br>/ig,'\n');
+
+
html = html.replace(/<[^>]*>/g,'');
html = html.replace(/\r?\n/g,'<br>');
// &nbsp; between <br> for IE6
- html = html.replace(/<br[^>]*><br[^>]*>/gi, '<br>$1&nbsp;<br>');
- YAHOO.log(html);
+ html = html.replace(/<br[^>]*><br[^>]*>/gi, '<br>&nbsp;<br>');
}
+
+ // Apply new highlighting
for (var i = 0; i < this.keywords.length; i++) {
html = html.replace(this.keywords[i].code, this.keywords[i].tag);
}
- YAHOO.log("AFTER HIGHLIGHT:" + html);
+
+ // Replace cursor
if ( !this.browser.gecko ) {
html = html.replace(this.cc, '<span id="cur">|</span>');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment