Revision: 1081
Author:
tbc...@gmail.com
Date: Sun Jun 23 07:08:10 2013
Log: Kleio edit and sintaxe highlight v1 @mhk_families
http://code.google.com/p/mhk/source/detail?r=1081
Added:
/branches/mhk_families/idb/web/scripts/codepress
/branches/mhk_families/idb/web/scripts/codepress/codepress.css
/branches/mhk_families/idb/web/scripts/codepress/codepress.html
/branches/mhk_families/idb/web/scripts/codepress/codepress.js
/branches/mhk_families/idb/web/scripts/codepress/engines
/branches/mhk_families/idb/web/scripts/codepress/engines/gecko.js
/branches/mhk_families/idb/web/scripts/codepress/engines/khtml.js
/branches/mhk_families/idb/web/scripts/codepress/engines/msie.js
/branches/mhk_families/idb/web/scripts/codepress/engines/older.js
/branches/mhk_families/idb/web/scripts/codepress/engines/opera.js
/branches/mhk_families/idb/web/scripts/codepress/images
/branches/mhk_families/idb/web/scripts/codepress/images/line-numbers.png
/branches/mhk_families/idb/web/scripts/codepress/languages
/branches/mhk_families/idb/web/scripts/codepress/languages/kleio.css
/branches/mhk_families/idb/web/scripts/codepress/languages/kleio.js
Modified:
/branches/mhk_families/idb/etc/template/new/edit_files.vm
=======================================
--- /dev/null
+++ /branches/mhk_families/idb/web/scripts/codepress/codepress.css Sun Jun
23 07:08:10 2013
@@ -0,0 +1,21 @@
+body {
+ margin-top:13px;
+ _margin-top:14px;
+ background:white;
+ margin-left:32px;
+ font-family:monospace;
+ font-size:13px;
+ white-space:pre;
+ background-image:url("images/line-numbers.png");
+ background-repeat:repeat-y;
+ background-position:0 3px;
+ line-height:16px;
+ height:100%;
+}
+pre {margin:0;}
+html>body{background-position:0 2px;}
+P {margin:0;padding:0;border:0;outline:0;display:block;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;}
+
+body.hide-line-numbers {background:white;margin-left:16px;}
+body.show-line-numbers
{background-image:url("images/line-numbers.png");margin-left:32px;}
=======================================
--- /dev/null
+++ /branches/mhk_families/idb/web/scripts/codepress/codepress.html Sun Jun
23 07:08:10 2013
@@ -0,0 +1,35 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+ <title>CodePress - Real Time Syntax Highlighting Editor written in
JavaScript</title>
+ <meta name="description" content="CodePress - source code editor window"
/>
+
+ <script type="text/javascript">
+ var language = 'generic';
+ var engine = 'older';
+ var ua = navigator.userAgent;
+ var ts = (new Date).getTime(); // timestamp to avoid cache
+ var lh = location.href;
+
+ if(ua.match('MSIE')) engine = 'msie';
+ else if(ua.match('KHTML')) engine = 'khtml';
+ else if(ua.match('Opera')) engine = 'opera';
+ else if(ua.match('Gecko')) engine = 'gecko';
+
+ if(lh.match('language=')) language =
lh.replace(/.*language=(.*?)(&.*)?$/,'$1');
+
+ document.write('<link type="text/css" href="codepress.css?ts='+ts+'"
rel="stylesheet" />');
+ document.write('<link type="text/css"
href="languages/'+language+'.css?ts='+ts+'" rel="stylesheet"
id="cp-lang-style" />');
+ document.write('<scr'+'ipt type="text/javascript"
src="engines/'+engine+'.js?ts='+ts+'"></scr'+'ipt>');
+ document.write('<scr'+'ipt type="text/javascript"
src="languages/'+language+'.js?ts='+ts+'"></scr'+'ipt>');
+ </script>
+
+</head>
+
+<script type="text/javascript">
+if(engine == "msie" || engine == "gecko") document.write('<body><pre>
</pre></body>');
+else if(engine == "opera") document.write('<body></body>');
+// else if(engine == "khtml") document.write('<body> </body>');
+</script>
+
+</html>
=======================================
--- /dev/null
+++ /branches/mhk_families/idb/web/scripts/codepress/codepress.js Sun Jun
23 07:08:10 2013
@@ -0,0 +1,127 @@
+/*
+ * CodePress - Real Time Syntax Highlighting Editor written in JavaScript
-
http://codepress.org/
+ *
+ * Copyright (C) 2006 Fernando M.A.d.S. <
fer...@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
under the terms of the
+ * GNU Lesser General Public License as published by the Free Software
Foundation.
+ *
+ * Read the full licence:
http://www.opensource.org/licenses/lgpl-license.php
+ */
+
+CodePress = function(obj) {
+ var self = document.createElement('iframe');
+ self.textarea = obj;
+ self.textarea.disabled = true;
+ self.textarea.style.overflow = 'hidden';
+ self.style.height = self.textarea.clientHeight +'px';
+ self.style.width = self.textarea.clientWidth +'px';
+ self.textarea.style.overflow = 'auto';
+ self.style.border = '1px solid gray';
+ self.frameBorder = 0; // remove IE internal iframe border
+ self.style.visibility = 'hidden';
+ self.style.position = 'absolute';
+ self.options = self.textarea.className;
+
+ self.initialize = function() {
+ self.editor = self.contentWindow.CodePress;
+ self.editor.body =
self.contentWindow.document.getElementsByTagName('body')[0];
+ self.editor.setCode(self.textarea.value);
+ self.setOptions();
+ self.editor.syntaxHighlight('init');
+ self.textarea.style.display = 'none';
+ self.style.position = 'static';
+ self.style.visibility = 'visible';
+ self.style.display = 'inline';
+ }
+
+ // obj can by a textarea id or a string (code)
+ self.edit = function(obj,language) {
+ if(obj) self.textarea.value = document.getElementById(obj) ?
document.getElementById(obj).value : obj;
+ if(!self.textarea.disabled) return;
+ self.language = language ? language : self.getLanguage();
+ self.src =
CodePress.path+'codepress.html?language='+self.language+'&ts='+(new
Date).getTime();
+ if(self.attachEvent) self.attachEvent('onload',self.initialize);
+ else self.addEventListener('load',self.initialize,false);
+ }
+
+ self.getLanguage = function() {
+ for (language in CodePress.languages)
+ if(self.options.match('\\b'+language+'\\b'))
+ return CodePress.languages[language] ? language : 'generic';
+ }
+
+ self.setOptions = function() {
+ if(self.options.match('autocomplete-off')) self.toggleAutoComplete();
+ if(self.options.match('readonly-on')) self.toggleReadOnly();
+ if(self.options.match('linenumbers-off')) self.toggleLineNumbers();
+ }
+
+ self.getCode = function() {
+ return self.textarea.disabled ? self.editor.getCode() :
self.textarea.value;
+ }
+
+ self.setCode = function(code) {
+ self.textarea.disabled ? self.editor.setCode(code) : self.textarea.value
= code;
+ }
+
+ self.toggleAutoComplete = function() {
+ self.editor.autocomplete = (self.editor.autocomplete) ? false : true;
+ }
+
+ self.toggleReadOnly = function() {
+ self.textarea.readOnly = (self.textarea.readOnly) ? false : true;
+ if(self.style.display != 'none') // prevent exception on FF + iframe
with display:none
+ self.editor.readOnly(self.textarea.readOnly ? true : false);
+ }
+
+ self.toggleLineNumbers = function() {
+ var cn = self.editor.body.className;
+ self.editor.body.className = (cn==''||
cn=='show-line-numbers') ? 'hide-line-numbers' : 'show-line-numbers';
+ }
+
+ self.toggleEditor = function() {
+ if(self.textarea.disabled) {
+ self.textarea.value = self.getCode();
+ self.textarea.disabled = false;
+ self.style.display = 'none';
+ self.textarea.style.display = 'inline';
+ }
+ else {
+ self.textarea.disabled = true;
+ self.setCode(self.textarea.value);
+ self.editor.syntaxHighlight('init');
+ self.style.display = 'inline';
+ self.textarea.style.display = 'none';
+ }
+ }
+
+ self.edit();
+ return self;
+}
+
+CodePress.languages = {
+ kleio : 'Kleio'
+}
+
+
+CodePress.run = function() {
+ s = document.getElementsByTagName('script');
+ for(var i=0,n=s.length;i<n;i++) {
+ if(s[i].src.match('codepress.js')) {
+ CodePress.path = s[i].src.replace('codepress.js','');
+ }
+ }
+ t = document.getElementsByTagName('textarea');
+ for(var i=0,n=t.length;i<n;i++) {
+ if(t[i].className.match('codepress')) {
+ id = t[i].id;
+ t[i].id = id+'_cp';
+ eval(id+' = new CodePress(t[i])');
+ t[i].parentNode.insertBefore(eval(id), t[i]);
+ }
+ }
+}
+
+if(window.attachEvent) window.attachEvent('onload',CodePress.run);
+else window.addEventListener('DOMContentLoaded',CodePress.run,false);
=======================================
--- /dev/null
+++ /branches/mhk_families/idb/web/scripts/codepress/engines/gecko.js Sun
Jun 23 07:08:10 2013
@@ -0,0 +1,293 @@
+/*
+ * CodePress - Real Time Syntax Highlighting Editor written in JavaScript
-
http://codepress.org/
+ *
+ * Copyright (C) 2007 Fernando M.A.d.S. <
fer...@gmail.com>
+ *
+ * Developers:
+ * Fernando M.A.d.S. <
fer...@gmail.com>
+ * Michael Hurni <
michae...@gmail.com>
+ * Contributors:
+ * Martin D. Kirk
+ *
+ * This program is free software; you can redistribute it and/or modify it
under the terms of the
+ * GNU Lesser General Public License as published by the Free Software
Foundation.
+ *
+ * Read the full licence:
http://www.opensource.org/licenses/lgpl-license.php
+ */
+
+CodePress = {
+ scrolling : false,
+ autocomplete : true,
+
+ // set initial vars and start sh
+ initialize : function() {
+ if(typeof(editor)=='undefined' && !arguments[0]) return;
+ body = document.getElementsByTagName('body')[0];
+ body.innerHTML = body.innerHTML.replace(/\n/g,"");
+ chars = '|32|46|62|8|'; // charcodes that trigger syntax highlighting
+ cc = '\u2009'; // carret char
+ editor = document.getElementsByTagName('pre')[0];
+ document.designMode = 'on';
+ document.addEventListener('keypress', this.keyHandler, true);
+ window.addEventListener('scroll', function() { if(!CodePress.scrolling)
CodePress.syntaxHighlight('scroll') }, false);
+ completeChars = this.getCompleteChars();
+ completeEndingChars = this.getCompleteEndingChars();
+ },
+
+ // treat key bindings
+ keyHandler : function(evt) {
+ keyCode = evt.keyCode;
+ charCode = evt.charCode;
+ fromChar = String.fromCharCode(charCode);
+
+ if((evt.ctrlKey || evt.metaKey) && evt.shiftKey && charCode!=90) { //
shortcuts = ctrl||appleKey+shift+key!=z(undo)
+ CodePress.shortcuts(charCode?charCode:keyCode);
+ }
+ else if( (completeEndingChars.indexOf('|'+fromChar+'|')!= -1 ||
completeChars.indexOf('|'+fromChar+'|')!=-1) && CodePress.autocomplete) {
// auto complete
+ if(!CodePress.completeEnding(fromChar))
+ CodePress.complete(fromChar);
+ }
+ else if(chars.indexOf('|'+charCode+'|')!=-1||keyCode==13) { // syntax
highlighting
+ top.setTimeout(function(){CodePress.syntaxHighlight('generic');},100);
+ }
+ else if(keyCode==9 || evt.tabKey) { // snippets activation (tab)
+ CodePress.snippets(evt);
+ }
+ else if(keyCode==46||keyCode==8) { // save to history when delete or
backspace pressed
+ CodePress.actions.history[CodePress.actions.next()] = editor.innerHTML;
+ }
+ else if((charCode==122||charCode==121||charCode==90) && evt.ctrlKey) {
// undo and redo
+ (charCode==121||evt.shiftKey) ? CodePress.actions.redo() :
CodePress.actions.undo();
+ evt.preventDefault();
+ }
+ else if(charCode==118 && evt.ctrlKey) { // handle paste
+ top.setTimeout(function(){CodePress.syntaxHighlight('generic');},100);
+ }
+ else if(charCode==99 && evt.ctrlKey) { // handle cut
+
//alert(window.getSelection().getRangeAt(0).toString().replace(/\t/g,'FFF'));
+ }
+
+ },
+
+ // put cursor back to its original position after every parsing
+ findString : function() {
+ if(self.find(cc))
+ window.getSelection().getRangeAt(0).deleteContents();
+ },
+
+ // split big files, highlighting parts of it
+ split : function(code,flag) {
+ if(flag=='scroll') {
+ this.scrolling = true;
+ return code;
+ }
+ else {
+ this.scrolling = false;
+ mid = code.indexOf(cc);
+ if(mid-2000<0) {ini=0;end=4000;}
+ else if(mid+2000>code.length) {ini=code.length-4000;end=code.length;}
+ else {ini=mid-2000;end=mid+2000;}
+ code = code.substring(ini,end);
+ return code;
+ }
+ },
+
+ getEditor : function() {
+ if(!document.getElementsByTagName('pre')[0]) {
+ body = document.getElementsByTagName('body')[0];
+ if(!body.innerHTML) return body;
+ if(body.innerHTML=="<br>") body.innerHTML = "<pre> </pre>";
+ else body.innerHTML = "<pre>"+body.innerHTML+"</pre>";
+ }
+ return document.getElementsByTagName('pre')[0];
+ },
+
+ // syntax highlighting parser
+ syntaxHighlight : function(flag) {
+ //if(document.designMode=='off') document.designMode='on'
+ if(flag != 'init') {
window.getSelection().getRangeAt(0).insertNode(document.createTextNode(cc));}
+ editor = CodePress.getEditor();
+ o = editor.innerHTML;
+ o = o.replace(/<br>/g,'\n');
+ o = o.replace(/<.*?>/g,'');
+ x = z = this.split(o,flag);
+ x = x.replace(/\n/g,'<br>');
+
+ if(arguments[1]&&arguments[2]) x = x.replace(arguments[1],arguments[2]);
+
+ for(i=0;i<Language.syntax.length;i++)
+ x = x.replace(Language.syntax[i].input,Language.syntax[i].output);
+
+ editor.innerHTML = this.actions.history[this.actions.next()] =
(flag=='scroll') ? x : o.split(z).join(x);
+ if(flag!='init') this.findString();
+ },
+
+ getLastWord : function() {
+ var rangeAndCaret = CodePress.getRangeAndCaret();
+ words = rangeAndCaret[0].substring(rangeAndCaret[1]-40,rangeAndCaret[1]);
+ words = words.replace(/[\s\n\r\);\W]/g,'\n').split('\n');
+ return words[words.length-1].replace(/[\W]/gi,'').toLowerCase();
+ },
+
+ snippets : function(evt) {
+ var snippets = Language.snippets;
+ var trigger = this.getLastWord();
+ for (var i=0; i<snippets.length; i++) {
+ if(snippets[i].input == trigger) {
+ var content = snippets[i].output.replace(/</g,'<');
+ content = content.replace(/>/g,'>');
+ if(content.indexOf('$0')<0) content += cc;
+ else content = content.replace(/\$0/,cc);
+ content = content.replace(/\n/g,'<br>');
+ var pattern = new RegExp(trigger+cc,'gi');
+ evt.preventDefault(); // prevent the tab key from being added
+ this.syntaxHighlight('snippets',pattern,content);
+ }
+ }
+ },
+
+ readOnly : function() {
+ document.designMode = (arguments[0]) ? 'off' : 'on';
+ },
+
+ complete : function(trigger) {
+ window.getSelection().getRangeAt(0).deleteContents();
+ var complete = Language.complete;
+ for (var i=0; i<complete.length; i++) {
+ if(complete[i].input == trigger) {
+ var pattern = new RegExp('\\'+trigger+cc);
+ var content = complete[i].output.replace(/\$0/g,cc);
+ parent.setTimeout(function () {
CodePress.syntaxHighlight('complete',pattern,content)},0); // wait for char
to appear on screen
+ }
+ }
+ },
+
+ getCompleteChars : function() {
+ var cChars = '';
+ for(var i=0;i<Language.complete.length;i++)
+ cChars += '|'+Language.complete[i].input;
+ return cChars+'|';
+ },
+
+ getCompleteEndingChars : function() {
+ var cChars = '';
+ for(var i=0;i<Language.complete.length;i++)
+ cChars
+= '|'+Language.complete[i].output.charAt(Language.complete[i].output.length-1);
+ return cChars+'|';
+ },
+
+ completeEnding : function(trigger) {
+ var range = window.getSelection().getRangeAt(0);
+ try {
+ range.setEnd(range.endContainer, range.endOffset+1)
+ }
+ catch(e) {
+ return false;
+ }
+ var next_character = range.toString()
+ range.setEnd(range.endContainer, range.endOffset-1)
+ if(next_character != trigger) return false;
+ else {
+ range.setEnd(range.endContainer, range.endOffset+1)
+ range.deleteContents();
+ return true;
+ }
+ },
+
+ shortcuts : function() {
+ var cCode = arguments[0];
+ if(cCode==13) cCode = '[enter]';
+ else if(cCode==32) cCode = '[space]';
+ else cCode = '['+String.fromCharCode(charCode).toLowerCase()+']';
+ for(var i=0;i<Language.shortcuts.length;i++)
+ if(Language.shortcuts[i].input == cCode)
+ this.insertCode(Language.shortcuts[i].output,false);
+ },
+
+ getRangeAndCaret : function() {
+ var range = window.getSelection().getRangeAt(0);
+ var range2 = range.cloneRange();
+ var node = range.endContainer;
+ var caret = range.endOffset;
+ range2.selectNode(node);
+ return [range2.toString(),caret];
+ },
+
+ insertCode : function(code,replaceCursorBefore) {
+ var range = window.getSelection().getRangeAt(0);
+ var node = window.document.createTextNode(code);
+ var selct = window.getSelection();
+ var range2 = range.cloneRange();
+ // Insert text at cursor position
+ selct.removeAllRanges();
+ range.deleteContents();
+ range.insertNode(node);
+ // Move the cursor to the end of text
+ range2.selectNode(node);
+ range2.collapse(replaceCursorBefore);
+ selct.removeAllRanges();
+ selct.addRange(range2);
+ },
+
+ // get code from editor
+ getCode : function() {
+ if(!document.getElementsByTagName('pre')[0] || editor.innerHTML == '')
+ editor = CodePress.getEditor();
+ var code = editor.innerHTML;
+ code = code.replace(/<br>/g,'\n');
+ code = code.replace(/\u2009/g,'');
+ code = code.replace(/<.*?>/g,'');
+ code = code.replace(/</g,'<');
+ code = code.replace(/>/g,'>');
+ code = code.replace(/&/gi,'&');
+ return code;
+ },
+
+ // put code inside editor
+ setCode : function() {
+ var code = arguments[0];
+ code = code.replace(/\u2009/gi,'');
+ code = code.replace(/&/gi,'&');
+ code = code.replace(/</g,'<');
+ code = code.replace(/>/g,'>');
+ editor.innerHTML = code;
+ if (code == '')
+ document.getElementsByTagName('body')[0].innerHTML = '';
+ },
+
+ // undo and redo methods
+ actions : {
+ pos : -1, // actual history position
+ history : [], // history vector
+
+ undo : function() {
+ editor = CodePress.getEditor();
+ if(editor.innerHTML.indexOf(cc)==-1){
+ if(editor.innerHTML != " ")
+
window.getSelection().getRangeAt(0).insertNode(document.createTextNode(cc));
+ this.history[this.pos] = editor.innerHTML;
+ }
+ this.pos --;
+ if(typeof(this.history[this.pos])=='undefined') this.pos ++;
+ editor.innerHTML = this.history[this.pos];
+ if(editor.innerHTML.indexOf(cc)>-1) editor.innerHTML+=cc;
+ CodePress.findString();
+ },
+
+ redo : function() {
+ // editor = CodePress.getEditor();
+ this.pos++;
+ if(typeof(this.history[this.pos])=='undefined') this.pos--;
+ editor.innerHTML = this.history[this.pos];
+ CodePress.findString();
+ },
+
+ next : function() { // get next vector position and clean old ones
+ if(this.pos>20) this.history[this.pos-21] = undefined;
+ return ++this.pos;
+ }
+ }
+}
+
+Language={};
+window.addEventListener('load', function() { CodePress.initialize('new');
}, true);
=======================================
--- /dev/null
+++ /branches/mhk_families/idb/web/scripts/codepress/engines/msie.js Sun
Jun 23 07:08:10 2013
@@ -0,0 +1,304 @@
+/*
+ * CodePress - Real Time Syntax Highlighting Editor written in JavaScript
-
http://codepress.org/
+ *
+ * Copyright (C) 2007 Fernando M.A.d.S. <
fer...@gmail.com>
+ *
+ * Developers:
+ * Fernando M.A.d.S. <
fer...@gmail.com>
+ * Michael Hurni <
michae...@gmail.com>
+ * Contributors:
+ * Martin D. Kirk
+ *
+ * This program is free software; you can redistribute it and/or modify it
under the terms of the
+ * GNU Lesser General Public License as published by the Free Software
Foundation.
+ *
+ * Read the full licence:
http://www.opensource.org/licenses/lgpl-license.php
+ */
+
+CodePress = {
+ scrolling : false,
+ autocomplete : true,
+
+ // set initial vars and start sh
+ initialize : function() {
+ if(typeof(editor)=='undefined' && !arguments[0]) return;
+ chars = '|32|46|62|'; // charcodes that trigger syntax highlighting
+ cc = '\u2009'; // carret char
+ editor = document.getElementsByTagName('pre')[0];
+ editor.contentEditable = 'true';
+ document.getElementsByTagName('body')[0].onfocus = function()
{editor.focus();}
+ document.attachEvent('onkeydown', this.metaHandler);
+ document.attachEvent('onkeypress', this.keyHandler);
+ window.attachEvent('onscroll', function() { if(!CodePress.scrolling)
setTimeout(function(){CodePress.syntaxHighlight('scroll')},1)});
+ completeChars = this.getCompleteChars();
+ completeEndingChars = this.getCompleteEndingChars();
+ setTimeout(function() { window.scroll(0,0) },50); // scroll IE to top
+ },
+
+ // treat key bindings
+ keyHandler : function(evt) {
+ charCode = evt.keyCode;
+ fromChar = String.fromCharCode(charCode);
+
+ if( (completeEndingChars.indexOf('|'+fromChar+'|')!= -1 ||
completeChars.indexOf('|'+fromChar+'|')!=-1 )&& CodePress.autocomplete) {
// auto complete
+ if(!CodePress.completeEnding(fromChar))
+ CodePress.complete(fromChar);
+ }
+ else if(chars.indexOf('|'+charCode+'|')!=-1||charCode==13) { //
syntax highlighting
+ CodePress.syntaxHighlight('generic');
+ }
+ },
+
+ metaHandler : function(evt) {
+ keyCode = evt.keyCode;
+
+ if(keyCode==9 || evt.tabKey) {
+ CodePress.snippets();
+ }
+ else if((keyCode==122||keyCode==121||keyCode==90) && evt.ctrlKey) { //
undo and redo
+ (keyCode==121||evt.shiftKey) ? CodePress.actions.redo() :
CodePress.actions.undo();
+ evt.returnValue = false;
+ }
+ else if(keyCode==34||keyCode==33) { // handle page up/down for IE
+ self.scrollBy(0, (keyCode==34) ? 200 : -200);
+ evt.returnValue = false;
+ }
+ else if(keyCode==46||keyCode==8) { // save to history when delete or
backspace pressed
+ CodePress.actions.history[CodePress.actions.next()] = editor.innerHTML;
+ }
+ else if((evt.ctrlKey || evt.metaKey) && evt.shiftKey && keyCode!=90) {
// shortcuts = ctrl||appleKey+shift+key!=z(undo)
+ CodePress.shortcuts(keyCode);
+ evt.returnValue = false;
+ }
+ else if(keyCode==86 && evt.ctrlKey) { // handle paste
+
window.clipboardData.setData('Text',window.clipboardData.getData('Text').replace(/\t/g,'\u2008'));
+ top.setTimeout(function(){CodePress.syntaxHighlight('paste');},10);
+ }
+ else if(keyCode==67 && evt.ctrlKey) { // handle cut
+ // window.clipboardData.setData('Text',x[0]);
+ // code = window.clipboardData.getData('Text');
+ }
+ },
+
+ // put cursor back to its original position after every parsing
+
+
+ findString : function() {
+ range = self.document.body.createTextRange();
+ if(range.findText(cc)){
+ range.select();
+ range.text = '';
+ }
+ },
+
+ // split big files, highlighting parts of it
+ split : function(code,flag) {
+ if(flag=='scroll') {
+ this.scrolling = true;
+ return code;
+ }
+ else {
+ this.scrolling = false;
+ mid = code.indexOf(cc);
+ if(mid-2000<0) {ini=0;end=4000;}
+ else if(mid+2000>code.length) {ini=code.length-4000;end=code.length;}
+ else {ini=mid-2000;end=mid+2000;}
+ code = code.substring(ini,end);
+ return code.substring(code.indexOf('<P>'),code.lastIndexOf('</P>')+4);
+ }
+ },
+
+ // syntax highlighting parser
+ syntaxHighlight : function(flag) {
+ if(flag!='init') document.selection.createRange().text = cc;
+ o = editor.innerHTML;
+ if(flag=='paste') { // fix pasted text
+ o = o.replace(/<BR>/g,'\r\n');
+ o = o.replace(/\u2008/g,'\t');
+ }
+ o = o.replace(/<P>/g,'\n');
+ o = o.replace(/<\/P>/g,'\r');
+ o = o.replace(/<.*?>/g,'');
+ o = o.replace(/ /g,'');
+ o = '<PRE><P>'+o+'</P></PRE>';
+ o = o.replace(/\n\r/g,'<P></P>');
+ o = o.replace(/\n/g,'<P>');
+ o = o.replace(/\r/g,'<\/P>');
+ o = o.replace(/<P>(<P>)+/,'<P>');
+ o = o.replace(/<\/P>(<\/P>)+/,'</P>');
+ o = o.replace(/<P><\/P>/g,'<P><BR/></P>');
+ x = z = this.split(o,flag);
+
+ if(arguments[1]&&arguments[2]) x = x.replace(arguments[1],arguments[2]);
+
+ for(i=0;i<Language.syntax.length;i++)
+ x = x.replace(Language.syntax[i].input,Language.syntax[i].output);
+
+ editor.innerHTML = this.actions.history[this.actions.next()] =
(flag=='scroll') ? x : o.replace(z,x);
+ if(flag!='init') this.findString();
+ },
+
+ snippets : function(evt) {
+ var snippets = Language.snippets;
+ var trigger = this.getLastWord();
+ for (var i=0; i<snippets.length; i++) {
+ if(snippets[i].input == trigger) {
+ var content = snippets[i].output.replace(/</g,'<');
+ content = content.replace(/>/g,'>');
+ if(content.indexOf('$0')<0) content += cc;
+ else content = content.replace(/\$0/,cc);
+ content = content.replace(/\n/g,'</P><P>');
+ var pattern = new RegExp(trigger+cc,"gi");
+ this.syntaxHighlight('snippets',pattern,content);
+ }
+ }
+ },
+
+ readOnly : function() {
+ editor.contentEditable = (arguments[0]) ? 'false' : 'true';
+ },
+
+ complete : function(trigger) {
+ var complete = Language.complete;
+ for (var i=0; i<complete.length; i++) {
+ if(complete[i].input == trigger) {
+ var pattern = new RegExp('\\'+trigger+cc);
+ var content = complete[i].output.replace(/\$0/g,cc);
+ setTimeout(function () {
CodePress.syntaxHighlight('complete',pattern,content)},0); // wait for char
to appear on screen
+ }
+ }
+ },
+
+ getCompleteChars : function() {
+ var cChars = '';
+ for(var i=0;i<Language.complete.length;i++)
+ cChars += '|'+Language.complete[i].input;
+ return cChars+'|';
+ },
+
+ getCompleteEndingChars : function() {
+ var cChars = '';
+ for(var i=0;i<Language.complete.length;i++)
+ cChars
+= '|'+Language.complete[i].output.charAt(Language.complete[i].output.length-1);
+ return cChars+'|';
+ },
+
+ completeEnding : function(trigger) {
+ var range = document.selection.createRange();
+ try {
+ range.moveEnd('character', 1)
+ }
+ catch(e) {
+ return false;
+ }
+ var next_character = range.text
+ range.moveEnd('character', -1)
+ if(next_character != trigger ) return false;
+ else {
+ range.moveEnd('character', 1)
+ range.text=''
+ return true;
+ }
+ },
+
+ shortcuts : function() {
+ var cCode = arguments[0];
+ if(cCode==13) cCode = '[enter]';
+ else if(cCode==32) cCode = '[space]';
+ else cCode = '['+String.fromCharCode(keyCode).toLowerCase()+']';
+ for(var i=0;i<Language.shortcuts.length;i++)
+ if(Language.shortcuts[i].input == cCode)
+ this.insertCode(Language.shortcuts[i].output,false);
+ },
+
+ getLastWord : function() {
+ var rangeAndCaret = CodePress.getRangeAndCaret();
+ words = rangeAndCaret[0].substring(rangeAndCaret[1]-40,rangeAndCaret[1]);
+ words = words.replace(/[\s\n\r\);\W]/g,'\n').split('\n');
+ return words[words.length-1].replace(/[\W]/gi,'').toLowerCase();
+ },
+
+ getRangeAndCaret : function() {
+ var range = document.selection.createRange();
+ var caret = Math.abs(range.moveStart('character', -1000000)+1);
+ range = this.getCode();
+ range = range.replace(/\n\r/gi,' ');
+ range = range.replace(/\n/gi,'');
+ return [range.toString(),caret];
+ },
+
+ insertCode : function(code,replaceCursorBefore) {
+ var repdeb = '';
+ var repfin = '';
+
+ if(replaceCursorBefore) { repfin = code; }
+ else { repdeb = code; }
+
+ if(typeof document.selection != 'undefined') {
+ var range = document.selection.createRange();
+ range.text = repdeb + repfin;
+ range = document.selection.createRange();
+ range.move('character', -repfin.length);
+ range.select();
+ }
+ },
+
+ // get code from editor
+ getCode : function() {
+ var code = editor.innerHTML;
+ code = code.replace(/<br>/g,'\n');
+ code = code.replace(/<\/p>/gi,'\r');
+ code = code.replace(/<p>/i,''); // IE first line fix
+ code = code.replace(/<p>/gi,'\n');
+ code = code.replace(/ /gi,'');
+ code = code.replace(/\u2009/g,'');
+ code = code.replace(/<.*?>/g,'');
+ code = code.replace(/</g,'<');
+ code = code.replace(/>/g,'>');
+ code = code.replace(/&/gi,'&');
+ return code;
+ },
+
+ // put code inside editor
+ setCode : function() {
+ var code = arguments[0];
+ code = code.replace(/\u2009/gi,'');
+ code = code.replace(/&/gi,'&');
+ code = code.replace(/</g,'<');
+ code = code.replace(/>/g,'>');
+ editor.innerHTML = '<pre>'+code+'</pre>';
+ },
+
+
+ // undo and redo methods
+ actions : {
+ pos : -1, // actual history position
+ history : [], // history vector
+
+ undo : function() {
+ if(editor.innerHTML.indexOf(cc)==-1){
+ document.selection.createRange().text = cc;
+ this.history[this.pos] = editor.innerHTML;
+ }
+ this.pos--;
+ if(typeof(this.history[this.pos])=='undefined') this.pos++;
+ editor.innerHTML = this.history[this.pos];
+ CodePress.findString();
+ },
+
+ redo : function() {
+ this.pos++;
+ if(typeof(this.history[this.pos])=='undefined') this.pos--;
+ editor.innerHTML = this.history[this.pos];
+ CodePress.findString();
+ },
+
+ next : function() { // get next vector position and clean old ones
+ if(this.pos>20) this.history[this.pos-21] = undefined;
+ return ++this.pos;
+ }
+ }
+}
+
+Language={};
+window.attachEvent('onload', function() { CodePress.initialize('new');});
=======================================
--- /dev/null
+++ /branches/mhk_families/idb/web/scripts/codepress/engines/opera.js Sun
Jun 23 07:08:10 2013
@@ -0,0 +1,260 @@
+/*
+ * CodePress - Real Time Syntax Highlighting Editor written in JavaScript
-
http://codepress.org/
+ *
+ * Copyright (C) 2007 Fernando M.A.d.S. <
fer...@gmail.com>
+ *
+ * Contributors :
+ *
+ * Michael Hurni <
michae...@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
under the terms of the
+ * GNU Lesser General Public License as published by the Free Software
Foundation.
+ *
+ * Read the full licence:
http://www.opensource.org/licenses/lgpl-license.php
+ */
+
+
+CodePress = {
+ scrolling : false,
+ autocomplete : true,
+
+ // set initial vars and start sh
+ initialize : function() {
+ if(typeof(editor)=='undefined' && !arguments[0]) return;
+ chars = '|32|46|62|'; // charcodes that trigger syntax highlighting
+ cc = '\u2009'; // control char
+ editor = document.getElementsByTagName('body')[0];
+ document.designMode = 'on';
+ document.addEventListener('keyup', this.keyHandler, true);
+ window.addEventListener('scroll', function() { if(!CodePress.scrolling)
CodePress.syntaxHighlight('scroll') }, false);
+ completeChars = this.getCompleteChars();
+// CodePress.syntaxHighlight('init');
+ },
+
+ // treat key bindings
+ keyHandler : function(evt) {
+ keyCode = evt.keyCode;
+ charCode = evt.charCode;
+
+ if((evt.ctrlKey || evt.metaKey) && evt.shiftKey && charCode!=90) { //
shortcuts = ctrl||appleKey+shift+key!=z(undo)
+ CodePress.shortcuts(charCode?charCode:keyCode);
+ }
+ else if(completeChars.indexOf('|'+String.fromCharCode(charCode)+'|')!=-1
&& CodePress.autocomplete) { // auto complete
+ CodePress.complete(String.fromCharCode(charCode));
+ }
+ else if(chars.indexOf('|'+charCode+'|')!=-1||keyCode==13) { // syntax
highlighting
+ CodePress.syntaxHighlight('generic');
+ }
+ else if(keyCode==9 || evt.tabKey) { // snippets activation (tab)
+ CodePress.snippets(evt);
+ }
+ else if(keyCode==46||keyCode==8) { // save to history when delete or
backspace pressed
+ CodePress.actions.history[CodePress.actions.next()] = editor.innerHTML;
+ }
+ else if((charCode==122||charCode==121||charCode==90) && evt.ctrlKey) {
// undo and redo
+ (charCode==121||evt.shiftKey) ? CodePress.actions.redo() :
CodePress.actions.undo();
+ evt.preventDefault();
+ }
+ else if(keyCode==86 && evt.ctrlKey) { // paste
+ // TODO: pasted text should be parsed and highlighted
+ }
+ },
+
+ // put cursor back to its original position after every parsing
+ findString : function() {
+ var sel = window.getSelection();
+ var range = window.document.createRange();
+ var span = window.document.getElementsByTagName('span')[0];
+
+ range.selectNode(span);
+ sel.removeAllRanges();
+ sel.addRange(range);
+ span.parentNode.removeChild(span);
+ //if(self.find(cc))
+ //window.getSelection().getRangeAt(0).deleteContents();
+ },
+
+ // split big files, highlighting parts of it
+ split : function(code,flag) {
+ if(flag=='scroll') {
+ this.scrolling = true;
+ return code;
+ }
+ else {
+ this.scrolling = false;
+ mid = code.indexOf('<SPAN>');
+ if(mid-2000<0) {ini=0;end=4000;}
+ else if(mid+2000>code.length) {ini=code.length-4000;end=code.length;}
+ else {ini=mid-2000;end=mid+2000;}
+ code = code.substring(ini,end);
+ return code;
+ }
+ },
+
+ // syntax highlighting parser
+ syntaxHighlight : function(flag) {
+ //if(document.designMode=='off') document.designMode='on'
+ if(flag!='init') {
+ var span = document.createElement('span');
+ window.getSelection().getRangeAt(0).insertNode(span);
+ }
+
+ o = editor.innerHTML;
+// o = o.replace(/<br>/g,'\r\n');
+// o = o.replace(/<(b|i|s|u|a|em|tt|ins|big|cite|strong)?>/g,'');
+ //alert(o)
+ o = o.replace(/<(?!span|\/span|br).*?>/gi,'');
+// alert(o)
+// x = o;
+ x = z = this.split(o,flag);
+ //alert(z)
+// x = x.replace(/\r\n/g,'<br>');
+ x = x.replace(/\t/g, ' ');
+
+
+ if(arguments[1]&&arguments[2]) x = x.replace(arguments[1],arguments[2]);
+
+ for(i=0;i<Language.syntax.length;i++)
+ x = x.replace(Language.syntax[i].input,Language.syntax[i].output);
+
+ editor.innerHTML = this.actions.history[this.actions.next()] =
(flag=='scroll') ? x : o.split(z).join(x);
+
+ if(flag!='init') this.findString();
+ },
+
+ getLastWord : function() {
+ var rangeAndCaret = CodePress.getRangeAndCaret();
+ words = rangeAndCaret[0].substring(rangeAndCaret[1]-40,rangeAndCaret[1]);
+ words = words.replace(/[\s\n\r\);\W]/g,'\n').split('\n');
+ return words[words.length-1].replace(/[\W]/gi,'').toLowerCase();
+ },
+
+ snippets : function(evt) {
+ var snippets = Language.snippets;
+ var trigger = this.getLastWord();
+ for (var i=0; i<snippets.length; i++) {
+ if(snippets[i].input == trigger) {
+ var content = snippets[i].output.replace(/</g,'<');
+ content = content.replace(/>/g,'>');
+ if(content.indexOf('$0')<0) content += cc;
+ else content = content.replace(/\$0/,cc);
+ content = content.replace(/\n/g,'<br>');
+ var pattern = new RegExp(trigger+cc,'gi');
+ evt.preventDefault(); // prevent the tab key from being added
+ this.syntaxHighlight('snippets',pattern,content);
+ }
+ }
+ },
+
+ readOnly : function() {
+ document.designMode = (arguments[0]) ? 'off' : 'on';
+ },
+
+ complete : function(trigger) {
+ window.getSelection().getRangeAt(0).deleteContents();
+ var complete = Language.complete;
+ for (var i=0; i<complete.length; i++) {
+ if(complete[i].input == trigger) {
+ var pattern = new RegExp('\\'+trigger+cc);
+ var content = complete[i].output.replace(/\$0/g,cc);
+ parent.setTimeout(function () {
CodePress.syntaxHighlight('complete',pattern,content)},0); // wait for char
to appear on screen
+ }
+ }
+ },
+
+ getCompleteChars : function() {
+ var cChars = '';
+ for(var i=0;i<Language.complete.length;i++)
+ cChars += '|'+Language.complete[i].input;
+ return cChars+'|';
+ },
+
+ shortcuts : function() {
+ var cCode = arguments[0];
+ if(cCode==13) cCode = '[enter]';
+ else if(cCode==32) cCode = '[space]';
+ else cCode = '['+String.fromCharCode(charCode).toLowerCase()+']';
+ for(var i=0;i<Language.shortcuts.length;i++)
+ if(Language.shortcuts[i].input == cCode)
+ this.insertCode(Language.shortcuts[i].output,false);
+ },
+
+ getRangeAndCaret : function() {
+ var range = window.getSelection().getRangeAt(0);
+ var range2 = range.cloneRange();
+ var node = range.endContainer;
+ var caret = range.endOffset;
+ range2.selectNode(node);
+ return [range2.toString(),caret];
+ },
+
+ insertCode : function(code,replaceCursorBefore) {
+ var range = window.getSelection().getRangeAt(0);
+ var node = window.document.createTextNode(code);
+ var selct = window.getSelection();
+ var range2 = range.cloneRange();
+ // Insert text at cursor position
+ selct.removeAllRanges();
+ range.deleteContents();
+ range.insertNode(node);
+ // Move the cursor to the end of text
+ range2.selectNode(node);
+ range2.collapse(replaceCursorBefore);
+ selct.removeAllRanges();
+ selct.addRange(range2);
+ },
+
+ // get code from editor
+ getCode : function() {
+ var code = editor.innerHTML;
+ code = code.replace(/<br>/g,'\n');
+ code = code.replace(/\u2009/g,'');
+ code = code.replace(/<.*?>/g,'');
+ code = code.replace(/</g,'<');
+ code = code.replace(/>/g,'>');
+ code = code.replace(/&/gi,'&');
+ return code;
+ },
+
+ // put code inside editor
+ setCode : function() {
+ var code = arguments[0];
+ code = code.replace(/\u2009/gi,'');
+ code = code.replace(/&/gi,'&');
+ code = code.replace(/</g,'<');
+ code = code.replace(/>/g,'>');
+ editor.innerHTML = code;
+ },
+
+ // undo and redo methods
+ actions : {
+ pos : -1, // actual history position
+ history : [], // history vector
+
+ undo : function() {
+ if(editor.innerHTML.indexOf(cc)==-1){
+
window.getSelection().getRangeAt(0).insertNode(document.createTextNode(cc));
+ this.history[this.pos] = editor.innerHTML;
+ }
+ this.pos--;
+ if(typeof(this.history[this.pos])=='undefined') this.pos++;
+ editor.innerHTML = this.history[this.pos];
+ CodePress.findString();
+ },
+
+ redo : function() {
+ this.pos++;
+ if(typeof(this.history[this.pos])=='undefined') this.pos--;
+ editor.innerHTML = this.history[this.pos];
+ CodePress.findString();
+ },
+
+ next : function() { // get next vector position and clean old ones
+ if(this.pos>20) this.history[this.pos-21] = undefined;
+ return ++this.pos;
+ }
+ }
+}
+
+Language={};
+window.addEventListener('load', function() { CodePress.initialize('new');
}, true);
=======================================
--- /dev/null
+++
/branches/mhk_families/idb/web/scripts/codepress/images/line-numbers.png
Sun Jun 23 07:08:10 2013
Binary file, no diff available.
=======================================
--- /dev/null
+++ /branches/mhk_families/idb/web/scripts/codepress/languages/kleio.css
Sun Jun 23 07:08:10 2013
@@ -0,0 +1,9 @@
+/*
+ * CodePress color styles for Java syntax highlighting
+ */
+
+b {color:#7F0055;font-weight:bold;} /* ls$ and rel$ regexp color=pink*/
+i {color:#89C62E;font-weight:bold;} /* /id= color=green */
+l {color:#207A0E;font-weight:bold;} /* /<regexp>= color=green */
+s {color:#2A00FF;font-weight:bold;} /* kleio$ regexp type color=blue */
+r {color:#F71212;font-weight:bold;} /* id regexp color=red */
=======================================
--- /dev/null
+++ /branches/mhk_families/idb/web/scripts/codepress/languages/kleio.js Sun
Jun 23 07:08:10 2013
@@ -0,0 +1,30 @@
+/*
+ * CodePress regular expressions for Kleio syntax highlighting
+ */
+
+// Kleio
+Language.syntax = [
+
+ //{ input : /\B([a-zA-Z0-9]?|[^l][a-zA-Z0-9]+|l[^s][a-zA-Z0-9]+)\$/g,
output : '<i>$1\$</i>'},
+ { input : /(ls\$(ec|enjeitada|enjeitado|pobre|morta|morto|ilegitima|
ilegitimo|assina|cartadeguia)\/[a-zA-Z0-9\s+]*)/g, output : '<b>$1</b>'},
// ls$ with controled value, color=pink
+ { input : /(rel\$(parentesco|sociabilidade|profissional|vizinhanca))/g,
output : '<b>$1</b>'}, // rel$ without controled value, color=pink
+ { input : /(rel\$parentesco\/[a-zA-Z0-9\s]*)/g, output : '<b>$1</b>'}, //
rel$ with controled value, color=pink
+ { input : /((ls\$|rel\$)[a-zA-Z0-9_]*\/)/g, output : '<b>$1</b>'}, // ls$
and rel$ generic type, color=pink
+ { input : /(?!(ls\$|rel\$|s\$|\$|el\$|l\$))([a-zA-Z0-9\-]*\$)/g,
output : '<s>$2</s>'}, // kleio$ generic type regex, color=blue
+ { input : /(\/id=)([a-zA-Z0-9\-]*)/g, output : '<i>$1</i><r>$2</r>'}, //
id specific keyword and value, id_color=green1 value_color=red
+ { input : /(\/same_as=|\/mesmo_que=)([a-zA-Z0-9\-]*)/g,
output : '<i>$1</i><r>$2</r>'}, // same_as and mesmo_que specific keyword
and value, id_color=green1 value_color=red
+ { input : /(?!(\/id=|id=|d=|=))(\/[a-zA-Z0-9_]+=)/g,
output : '<l>$2</l>'}, // /<type>= generic regex, color=green2
+ //{ input : /.*=([a-zA-Z0-9\-]+)/g, output : '=<r>$1</r>'}, // =<digits |
ID> regexp, color=red
+ //{ input : /=([a-zA-Z0-9\-])/g, output : '<r>$1</r>'}, // =<digits | ID>
regexp, color=red
+ //VER TAG ls$xxx/xxx DEVE TER QUE SE SEPARAR REL E LS SENAO NAO APANHA
TUDO NO REL (OU FICA AMBIGUO COM O LS)
+ //MESMO_QUE TA DE COR DIFERENTE
+]
+
+Language.snippets = []
+
+Language.complete = [
+ //{ input : '{', output : '{\n\t$0\n}' },
+ //{ input : '/', output : '' }
+]
+
+Language.shortcuts = []
=======================================
--- /branches/mhk_families/idb/etc/template/new/edit_files.vm Thu Jun 6
14:02:11 2013
+++ /branches/mhk_families/idb/etc/template/new/edit_files.vm Sun Jun 23
07:08:10 2013
@@ -2,44 +2,48 @@
#parse("new/head.vm")
+
</head>
+<script type="text/javascript"
src="/mhk/scripts/codepress/codepress.js"></script>
+##<link type="text/css" href="/mhk/stylesheets/kleio.css" rel="stylesheet"
/>
+##<script type="text/javascript"
src="/mhk/scripts/engines/gecko.js"></script>
+##<script type="text/javascript"
src="/mhk/scripts/engines/khtml.js"></script>
+##<script type="text/javascript"
src="/mhk/scripts/engines/msie.js"></script>
+##<script type="text/javascript"
src="/mhk/scripts/engines/older.js"></script>
+##<script type="text/javascript"
src="/mhk/scripts/engines/opera.js"></script>
+##<script type="text/javascript"
src="/mhk/scripts/engines/webkit.js"></script>
+##<script type="text/javascript"
src="/mhk/scripts/languages/kleio.js"></script>
<body>
-
-#parse("new/header.vm")
-
+#parse("new/header.vm")
#parse("new/setup.vm")
-
- <table>
- <tr><td>File: $filename</td></tr>
- <tr>
- <td colspan="3">
- <textarea id="file_content"
style="width:512px;height:256px"></textarea>
- </td>
- </tr>
- <tr>
- <td>Filename to Save As:</td>
- <td><input id="file_name"></input></td>
- <td><button onclick="saveFile()">Save File</a></td>
- </tr>
+<table>
+ <tr>
+ <td colspan="3">
+ <textarea id="file_content" class="codepress kleio linenumbers-on"
style="width:800px;height:500px;"></textarea>
+ </td>
+ </tr>
+ <tr>
+ <td>Filename to Save As:</td><td><input id="file_name"></input></td>
+ <td><button onclick="saveFile()">Save File</a></td>
+ </tr>
## <tr>
## <td>Select a File to Load:</td>
## <td><input type="file" id="fileToLoad">
## <td><button onclick="loadFileAsText()">Load Selected
File</a><td>
## </tr>
- </table>
+</table>
#parse("new/footer.vm")
</body>
+
+
<script type='text/javascript'>
##alert("${file_content}");
var java_text="${file_content}";
##var final_text = java_text.replace(/\n/g , "<br>");
##alert(final_text)
-
- ##var text="W3Schools----\"-----<br>---\"";
-
document.getElementById("file_content").value=java_text;
##alert(fileToLoad);
##var fileReader = new FileReader();
@@ -68,7 +72,7 @@
{
##alert("${currentdir}");
var filename=document.getElementById("file_name").value;
- var file_content=document.getElementById("file_content").value;
+ var file_content=document.getElementById("file_content_cp").value;
##alert(file_content);
var final_content=file_content.replace(/\n/g , "<br>");
var xmlhttp;
@@ -84,4 +88,5 @@
xmlhttp.send();
}
</script>
+
</html>