(function(){
+ // Classes
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
this.Class = function(){};
Class.extend = function(prop) {
Class.extend = arguments.callee;
return Class;
};
+
+ // Templates
+ var cache = {};
+
+ this.render_template = function render_template(str, data){
+ // Figure out if we're getting a template, or if we need to
+ // load the template - and be sure to cache the result.
+ var fn = !/^[\d\s-_]/.test(str) ?
+ cache[str] = cache[str] ||
+ render_template(document.getElementById(str).innerHTML) :
+
+ // Generate a reusable function that will serve as a template
+ // generator (and which will be cached).
+ new Function("obj",
+ "var p=[],print=function(){p.push.apply(p,arguments);};" +
+
+ // Introduce the data as local variables using with(){}
+ "with(obj){p.push('" +
+
+ // Convert the template into pure JavaScript
+ str
+ .replace(/[\r\t\n]/g, " ")
+ .split("<%").join("\t")
+ .replace(/((^|%>)[^\t]*)'/g, "$1\r")
+ .replace(/\t=(.*?)%>/g, "',$1,'")
+ .split("\t").join("');")
+ .split("%>").join("p.push('")
+ .split("\r").join("\\'")
+ + "');}return p.join('');");
+
+ // Provide some basic currying to the user
+ return data ? fn( data ) : fn;
+ };
})();
(function() {
})();
+var panels = [];
+
+var documentsUrl = '/api/documents/';
+
+var DocumentModel = Class.extend({
+ data: null, // name, text_url, latest_rev, latest_shared_rev, parts_url, dc_url, size
+ xml: '',
+ html: '',
+
+ init: function() {},
+
+ getData: function(callback) {
+ console.log('get:', documentsUrl + fileId);
+ $.ajax({
+ cache: false,
+ url: documentsUrl + fileId,
+ dataType: 'json',
+ success: this.successfulGetData.bind(this, callback)
+ });
+ },
+
+ successfulGetData: function(callback, data) {
+ this.data = data;
+ this.modelChanged();
+ if (callback) {
+ (callback.bind(this))(data);
+ }
+ },
+
+ getXML: function(callback) {
+ if (!this.data) {
+ this.getData(this.getXML);
+ } else {
+ console.log('getXML:', this.data.text_url);
+ $.ajax({
+ cache: false,
+ url: this.data.text_url,
+ dataType: 'text',
+ success: this.successfulGetXML.bind(this, callback)
+ });
+ };
+ },
+
+ successfulGetXML: function(callback, data) {
+ if (data != this.xml) {
+ this.xml = data;
+ this.modelChanged();
+ $(this).trigger('modelxmlchanged');
+ }
+ },
+
+ modelChanged: function() {
+ $(this).trigger('modelchanged');
+ }
+});
+
+var leftPanelView, rightPanelContainer, doc;
$(function() {
- var splitView = new SplitView('#panels');
+ doc = new DocumentModel();
+ var splitView = new SplitView('#splitview', doc);
+ leftPanelView = new PanelContainerView('#left-panel-container', doc);
+ rightPanelContainer = new PanelContainerView('#right-panel-container', doc);
});