+ $.wiki.activePerspective = function() {
+ return this.perspectives[$("#tabs li.active").attr('id')];
+ };
+
+ $.wiki.exitContext = function() {
+ var ap = this.activePerspective();
+ if(ap) ap.onExit();
+ return ap;
+ };
+
+ $.wiki.enterContext = function(ap) {
+ if(ap) ap.onEnter();
+ };
+
+ $.wiki.isDirty = function() {
+ var ap = this.activePerspective();
+ return (!!CurrentDocument && CurrentDocument.has_local_changes) || ap.dirty();
+ };
+
+ $.wiki.newTab = function(doc, title, klass) {
+ var base_id = 'id' + Math.floor(Math.random()* 5000000000);
+ var id = (''+klass)+'_' + base_id;
+ var $tab = $('<li id="'+id+'" data-ui-related="'+base_id+'" data-ui-jsclass="'+klass+'" >'
+ + title + '<img src="/static/icons/close.png" class="tabclose"></li>');
+ var $view = $('<div class="editor '+klass+'" id="'+base_id+'"> </div>');
+
+ this.perspectives[id] = new $.wiki[klass]({
+ doc: doc,
+ id: id,
+ base_id: base_id,
+ });
+
+ $('#tabs').append($tab);
+ $view.hide().appendTo('#editor');
+ return {
+ tab: $tab[0],
+ view: $view[0],
+ };
+ };
+
+ $.wiki.initTab = function(options) {
+ var klass = $(options.tab).attr('data-ui-jsclass');
+
+ return new $.wiki[klass]({
+ doc: options.doc,
+ id: $(options.tab).attr('id'),
+ callback: function() {
+ $.wiki.perspectives[this.perspective_id] = this;
+ if(options.callback)
+ options.callback.call(this);
+ }
+ });
+ };
+
+ $.wiki.perspectiveForTab = function(tab) { // element or id
+ return this.perspectives[ $(tab).attr('id')];