Alien-CodePress
view release on metacpan or search on metacpan
cp/codepress/engines/msie.js view on Meta::CPAN
/*
* CodePress - Real Time Syntax Highlighting Editor written in JavaScript - http://codepress.org/
*
* Copyright (C) 2007 Fernando M.A.d.S. <fermads@gmail.com>
*
* Developers:
* Fernando M.A.d.S. <fermads@gmail.com>
* Michael Hurni <michael.hurni@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;
( run in 1.081 second using v1.01-cache-2.11-cpan-2398b32b56e )