Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Aug 20, 2009
0 parents commit 138bee4
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 0 deletions.
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Software License Agreement (BSD License)

Copyright (c) 2007, Dav Glass <dav.glass@yahoo.com>.
All rights reserved.

Redistribution and use of this software in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.

* The name of Dav Glass may not be used to endorse or promote products
derived from this software without specific prior
written permission of Dav Glass.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

This is the new home of the YUI RTE Code Editor project

18 changes: 18 additions & 0 deletions blank.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>YUI Editor Blank Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
body { background:white url(line-numbers.png) repeat-y scroll 0pt 3px; font-family:monospace; font-size:13px; height:100%; line-height:16px; margin-left:32px; margin-top:13px; white-space:pre; }
b, i, s, u, a, em, tt, ins, big, cite, strong, var, dfn {text-decoration:none;font-weight:normal;font-style:normal;font-size:13px;}
b, cite {color:#7F0055;font-weight:bold;} /* reserved words */
u {color:darkblue;font-weight:bold;} /* special words */
i, i b, i s, i u {color:green;font-weight:normal;} /* comments */
s, s b, s u {color:#2A00FF;font-weight:normal;} /* strings */
ins, ins b, ins s, ins em {color:green;} /* comments */
a {color:blue; text-decoration: underline; } /* links */
</style>
</head>
<body onload="document.body._rteLoaded = true;"></body>
</html>
126 changes: 126 additions & 0 deletions code-editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
(function() {
var Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event,
Lang = YAHOO.lang,
myConfig = {
height: '700px',
width: '700px',
animate: false,
dompath: false,
focusAtStart: true
},
//Borrowed this from CodePress: http://codepress.sourceforge.net
cc = '\u2009', // carret char
keywords = [
{ code: /(&lt;DOCTYPE.*?--&gt.)/g, tag: '<ins>$1</ins>' }, // comments
{ code: /(&lt;[^!]*?&gt;)/g, tag: '<b>$1</b>' }, // all tags
{ code: /(&lt;!--.*?--&gt.)/g, tag: '<ins>$1</ins>' }, // comments
{ code: /\b(YAHOO|widget|util|Dom|Event|lang)\b/g, tag: '<cite>$1</cite>' }, // reserved words
{ code: /\b(break|continue|do|for|new|this|void|case|default|else|function|return|typeof|while|if|label|switch|var|with|catch|boolean|int|try|false|throws|null|true|goto)\b/g, tag: '<b>$1</b>' }, // reserved words
{ code: /\"(.*?)(\"|<br>|<\/P>)/g, tag: '<s>"$1$2</s>' }, // strings double quote
{ code: /\'(.*?)(\'|<br>|<\/P>)/g, 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)/g, tag: '$1<i>//$2</i>$3' }, // comments //
{ code: /\/\*(.*?)\*\//g, tag: '<i>/*$1* /</i>' } // comments / * */
];
//End Borrowed Content


YAHOO.widget.Editor.prototype._cleanIncomingHTML = function(str) {
return str;
};

YAHOO.widget.Editor.prototype.focusCaret = function() {
if (this.browser.gecko) {
if (this._getWindow().find(cc)) {
this._getSelection().getRangeAt(0).deleteContents();
}
} else if (this.browser.opera) {
var sel = this._getWindow().getSelection();
var range = this._getDoc().createRange();
var span = this._getDoc().getElementsByTagName('span')[0];

range.selectNode(span);
sel.removeAllRanges();
sel.addRange(range);
span.parentNode.removeChild(span);
} else if (this.browser.webkit || this.browser.ie) {
this.focus();
var cur = this._getDoc().getElementById('cur');
cur.id = '';
cur.innerHTML = '';
this._selectNode(cur);
}
};
YAHOO.widget.Editor.prototype.highlight = function(focus) {
if (!focus) {
if (this.browser.gecko) {
this._getSelection().getRangeAt(0).insertNode(this._getDoc().createTextNode(cc));
} else if (this.browser.opera) {
var span = this._getDoc().createElement('span');
this._getWindow().getSelection().getRangeAt(0).insertNode(span);
} else if (this.browser.webkit || this.browser.ie) {
this.execCommand('inserthtml', '<span id="cur"></span>');
}
}
var html = '';
html = this._getDoc().body.innerHTML;
if (this.browser.opera) {
html = html.replace(/<(?!span|\/span|br).*?>/gi,'');
} else if (this.browser.webkit) {
//YAHOO.log('1: ' + html);
html = html.replace(/<span id="cur"><\/span>/ig, '!!CURSOR_HERE!!');
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(/\n/g,'<br>');
//YAHOO.log('2: ' + html);
} else {
if (this.browser.ie) {
html = html.replace(/<SPAN id=cur><\/SPAN>/ig, '!!CURSOR_HERE!!');
html = html.replace(/<SPAN id=""><\/SPAN>/ig, '');
}
YAHOO.log(html);
html = html.replace(/<br>/gi,'\n');
html = html.replace(/<.*?>/g,'');
html = html.replace(/\n/g,'<br>');
YAHOO.log(html);
}
for (var i = 0; i < keywords.length; i++) {
html = html.replace(keywords[i].code, keywords[i].tag);
}

html = html.replace('!!CURSOR_HERE!!', '<span id="cur">&nbsp;|&nbsp;</span>');

this._getDoc().body.innerHTML = html;
if (!focus) {
this.focusCaret();
}
};

myEditor = new YAHOO.widget.Editor('editor', myConfig);
myEditor.on('editorContentLoaded', function() {
var link = this._getDoc().createElement('link');
link.rel = "stylesheet";
link.type = "text/css";
link.href = "code.css";
this._getDoc().getElementsByTagName('head')[0].appendChild(link);
this.highlight(true);
if (this.browser.ie) {
this._getDoc().body.style.marginLeft = '';
}
}, myEditor, true);
myEditor.on('editorKeyDown', function(ev) {
if ((ev.ev.keyCode == 13) || (ev.ev.keyCode == 9)) {
Lang.later(100, this, this.highlight);
}
});
myEditor.on('editorKeyPress', function(ev) {
if ((ev.ev.keyCode == 32) || (ev.ev.charCode == 59) || (ev.ev.charCode == 32) || (ev.ev.keyCode == 13) || (ev.ev.charCode == 40) || (ev.ev.charCode == 123)) {
Lang.later(100, this, this.highlight);
}
}, myEditor, true);
myEditor.render();
})();
9 changes: 9 additions & 0 deletions code.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
body { background:white url(line-numbers.png) repeat-y scroll 0pt 3px; font-family:monospace; font-size:13px; height:100%; line-height:16px; margin-left:32px; margin-top:8px; white-space:pre; }
b, i, s, u, a, em, tt, ins, big, cite, strong, var, dfn {text-decoration:none;font-weight:normal;font-style:normal;font-size:13px;}
b, cite {color:#7F0055;font-weight:bold;} /* reserved words */
u {color:darkblue;font-weight:bold;} /* special words */
i, i b, i s, i u {color:green;font-weight:normal;} /* comments */
s, s b, s u {color:#2A00FF;font-weight:normal;} /* strings */
ins, ins b, ins s, ins em {color:green;} /* comments */
a {color:blue; text-decoration: underline; } /* links */
body.ie { background-position: 0 -3px; margin-top: 0px;}
41 changes: 41 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>YUI: Editor: Code Editor w/Syntax Highlighting</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css">
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/assets/skins/sam/skin.css">
<link rel="stylesheet" href="http://blog.davglass.com/wp-content/themes/davglass/style.css" type="text/css">
<style>
#form1 {
margin: 2em;
}
.yui-toolbar-subcont {
display: none;
}
.yui-skin-sam .yui-toolbar-container .yui-toolbar-titlebar span.collapse {
display: none;
}
</style>
</head>
<body class="yui-skin-sam">
<div id="davdoc" class="yui-t7">
<div id="hd"><h1 id="header"><a href="http://blog.davglass.com/">YUI: Editor: Code Editor w/Syntax Highlighting</a></h1></div>
<div id="bd">
<p>This is a very early prototype of changing the Editor to work as a Syntax Highlighting Code Editor.</p>
<p><a href="code-editor.js">Javascript Souce Code here.</a></p>
<p><a href="line-numbers.png">Line Numbers Image here.</a></p>
<p><a href="blank.htm">Blank HTML file here.</a></p>
<form method="post" action="index.php" id="form1">
<textarea id="editor" name="editor" rows="20" cols="75"></textarea>
</form>
</div>
<div id="ft">&nbsp;</div>
</div>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/utilities/utilities.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/container/container_core-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/menu/menu-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/button/button-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/editor/editor-min.js"></script>
<script src="code-editor.js?bust=<?php echo(mktime()); ?>"></script>
</body>
</html>
Binary file added line-numbers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 138bee4

Please sign in to comment.