' + Ext.util.Format.htmlEncode(response.responseText) + '');
+ this.contentLoaded = true;
+ this.highlight();
+ },
+ failure: function(){
+ // TODO
+ }
+ });
+ },
+
+ loadBrush: function(){
+ main.loadScript(this.shPath + '/scripts/' + this.brushUrl, function(){
+ this.scriptsLoaded = true;
+ this.highlight();
+ }, this);
+ },
+
+ highlight: function(){
+ if (debug){
+ console.debug('loaded, script: ' + this.scriptsLoaded + ", content: " + this.contentLoaded );
+ }
+ if ( this.scriptsLoaded && this.contentLoaded ){
+ if (debug){
+ console.debug('call SyntaxHighlighter.highlight()');
+ }
+ SyntaxHighlighter.highlight({}, this.body.el);
+ }
+ }
+
+});
+
+Ext.reg('syntaxHighlighterPanel', Sonia.panel.SyntaxHighlighterPanel);
\ No newline at end of file
diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js
index 50004c86fd..2db1adf536 100644
--- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js
+++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js
@@ -44,11 +44,6 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, {
initComponent: function(){
- this.syntaxes = new Array();
- this.syntaxes['java'] = 'resources/syntaxhighlighter/scripts/shBrushJava.js';
- this.syntaxes['xml'] = 'resources/syntaxhighlighter/scripts/shBrushXml.js';
- this.syntaxes['txt'] = 'resources/syntaxhighlighter/scripts/shBrushPlain.js';
-
var browserStore = new Sonia.rest.JsonStore({
proxy: new Ext.data.HttpProxy({
url: restUrl + 'repositories/' + this.repository.id + '/browse.json',
@@ -113,8 +108,7 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, {
click: {
fn: this.onClick,
scope: this
- },
- afterRender: this.afterRender
+ }
}
};
@@ -122,14 +116,6 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, {
Sonia.repository.RepositoryBrowser.superclass.initComponent.apply(this, arguments);
},
- afterRender: function(){
- // preload syntaxhighlighter
- main.loadScript('resources/syntaxhighlighter/scripts/shCore.js');
- main.loadStylesheet('resources/syntaxhighlighter/styles/shCore.css');
- // theme onfigureable ??
- main.loadStylesheet('resources/syntaxhighlighter/styles/shCoreDefault.css');
- },
-
loadStore: function(store, records, extra){
var path = extra.params.path;
if ( path != null && path.length > 0 ){
@@ -201,39 +187,16 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, {
console.debug( 'open file: ' + path );
}
- var ext = this.getExtension( path );
- var url = this.syntaxes[ext];
- if ( url == null ){
- // load plain on default
- ext = "plain";
- url = this.syntaxes['txt'];
- }
-
- main.loadScript(url);
+ var ext = this.getExtension( path );
main.addTab({
id: this.repository.id + "-b-" + path,
- xtype: 'panel',
+ contentUrl: restUrl + 'repositories/' + this.repository.id + '/content?path=' + path,
+ xtype: 'syntaxHighlighterPanel',
title: this.getName(path),
closable: true,
autoScroll: true,
- listeners: {
- afterrender: {
- fn: function(panel){
- Ext.Ajax.request({
- url: restUrl + 'repositories/' + this.repository.id + '/content?path=' + path,
- success: function(response){
- panel.update('' + Ext.util.Format.htmlEncode(response.responseText) + '
');
- SyntaxHighlighter.highlight({}, panel.body.el);
- },
- failure: function(){
- // TODO
- }
- });
- },
- scope: this
- }
- }
+ syntax: ext
});
},
diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.scm.js b/scm-webapp/src/main/webapp/resources/js/sonia.scm.js
index ae55d966d5..80d8fa0ed4 100644
--- a/scm-webapp/src/main/webapp/resources/js/sonia.scm.js
+++ b/scm-webapp/src/main/webapp/resources/js/sonia.scm.js
@@ -376,13 +376,46 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
}
},
- loadScript: function(url){
+ loadScript: function(url, callback, scope){
+ var doCallback = function(){
+ if (debug){
+ console.debug('call callback for script ' + url);
+ }
+ if ( scope ){
+ callback.call(scope);
+ } else {
+ callback();
+ }
+ }
if ( this.scripts.indexOf(url) < 0 ){
var js = document.createElement('script');
js.type = "text/javascript";
js.src = url;
- document.head.appendChild(js);
+
+ if ( Ext.isIE ){
+ js.onreadystatechange = function (){
+ if (this.readyState === 'loaded' ||
+ this.readyState === 'complete'){
+ doCallback();
+ }
+ }
+ } else {
+ js.onload = doCallback;
+ js.onerror = doCallback;
+ }
+
+ if (debug){
+ console.debug('load script ' + url);
+ }
+
+ var head = document.getElementsByTagName('head')[0];
+ head.appendChild(js);
this.scripts.push(url);
+ } else {
+ if (debug){
+ console.debug( 'script ' + url + ' allready loaded' );
+ }
+ doCallback();
}
},