improve SyntaxHighlighterPanel

This commit is contained in:
Sebastian Sdorra
2011-06-14 22:01:52 +02:00
parent 99a0b86716
commit 3f89ee98fd
2 changed files with 13 additions and 14 deletions

View File

@@ -131,6 +131,7 @@ Sonia.panel.SyntaxHighlighterPanel = Ext.extend(Ext.Panel, {
}], }],
syntax: 'plain', syntax: 'plain',
brush: 'plain',
brushUrl: 'shBrushPlain.js', brushUrl: 'shBrushPlain.js',
theme: 'Default', theme: 'Default',
shPath: 'resources/syntaxhighlighter', shPath: 'resources/syntaxhighlighter',
@@ -153,7 +154,6 @@ Sonia.panel.SyntaxHighlighterPanel = Ext.extend(Ext.Panel, {
for ( var j=0;j<s.aliases.length; j++ ){ for ( var j=0;j<s.aliases.length; j++ ){
if ( this.syntax == s.aliases[j] ){ if ( this.syntax == s.aliases[j] ){
found = true; found = true;
this.syntax = s.name;
this.brushUrl = s.fileName; this.brushUrl = s.fileName;
if (debug){ if (debug){
console.debug( "found brush " + this.syntax + " at " + this.brushUrl ); console.debug( "found brush " + this.syntax + " at " + this.brushUrl );
@@ -174,6 +174,8 @@ Sonia.panel.SyntaxHighlighterPanel = Ext.extend(Ext.Panel, {
} }
} }
this.brush = this.syntax;
// load core stylesheet // load core stylesheet
main.loadStylesheet( this.shPath + '/styles/shCore.css'); main.loadStylesheet( this.shPath + '/styles/shCore.css');
// load theme stylesheet // load theme stylesheet
@@ -186,31 +188,26 @@ Sonia.panel.SyntaxHighlighterPanel = Ext.extend(Ext.Panel, {
autoScroll: true, autoScroll: true,
listeners: { listeners: {
afterrender: { afterrender: {
fn: this.loadContent, fn: this.loadBodyContent,
scope: this scope: this
} }
} }
}; };
this.loadContent();
Ext.apply(this, Ext.apply(this.initialConfig, config)); Ext.apply(this, Ext.apply(this.initialConfig, config));
if (debug){
console.debug(config);
}
Sonia.panel.SyntaxHighlighterPanel.superclass.initComponent.apply(this, arguments); Sonia.panel.SyntaxHighlighterPanel.superclass.initComponent.apply(this, arguments);
}, },
loadContent: function(){ loadBodyContent: function(){
main.loadScript(this.shPath + '/scripts/shCore.js', this.loadBrush, this); main.loadScript(this.shPath + '/scripts/shCore.js', this.loadBrush, this);
Ext.Ajax.request({ Ext.Ajax.request({
url: this.contentUrl, url: this.contentUrl,
scope: this, scope: this,
success: function(response){ success: function(response){
console.debug( this.syntax ); if (debug){
this.update('<pre class="brush: ' + this.syntax + '">' + Ext.util.Format.htmlEncode(response.responseText) + '</pre>'); console.debug( 'load content for brush: ' + this.brush );
}
this.update('<pre class="brush: ' + this.brush + '; class-name: ' + this.brush + '">' + Ext.util.Format.htmlEncode(response.responseText) + '</pre>');
this.contentLoaded = true; this.contentLoaded = true;
this.highlight(); this.highlight();
}, },

View File

@@ -390,6 +390,7 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
if ( this.scripts.indexOf(url) < 0 ){ if ( this.scripts.indexOf(url) < 0 ){
var js = document.createElement('script'); var js = document.createElement('script');
js.type = "text/javascript"; js.type = "text/javascript";
js.language = 'javascript';
js.src = url; js.src = url;
if ( Ext.isIE ){ if ( Ext.isIE ){
@@ -408,8 +409,9 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
console.debug('load script ' + url); console.debug('load script ' + url);
} }
var head = document.getElementsByTagName('head')[0]; document.body.appendChild(js);
head.appendChild(js); // var head = document.getElementsByTagName('head')[0];
// head.appendChild(js);
this.scripts.push(url); this.scripts.push(url);
} else { } else {
if (debug){ if (debug){