no audience in master file
[redakcja.git] / redakcja / static / js / wiki / loader_readonly.js
1 if (!window.console) {
2     window.console = {
3         log: function(){
4         }
5     }
6 }
7
8
9 DEFAULT_PERSPECTIVE = "#VisualPerspective";
10
11 $(function()
12 {
13         var tabs = $('ol#tabs li');
14         var gallery = null;
15
16         CurrentDocument = new $.wikiapi.WikiDocument("document-meta");
17         $.blockUI.defaults.baseZ = 10000;
18
19         function initialize()
20         {
21                 $('.editor').hide();
22
23                 /*
24                  * TABS
25                  */
26         $('#tabs li').live('click', function(event, callback) {
27                         $.wiki.switchToTab(this);
28         });
29
30                 $('#tabs li > .tabclose').live('click', function(event, callback) {
31                         var $tab = $(this).parent();
32
33                         if($tab.is('.active'))
34                                 $.wiki.switchToTab(DEFAULT_PERSPECTIVE);
35
36                         var p = $.wiki.perspectiveForTab($tab);
37                         p.destroy();
38                         return false;
39         });
40
41         $(window).resize(function(){
42             $('iframe').height($(window).height() - $('#tabs').outerHeight() - $('#source-editor .toolbar').outerHeight());
43         });
44
45                 $(document).bind('wlapi_document_changed', function(event, doc) {
46                         try {
47                                 $('#document-revision').text(doc.revision);
48                         } catch(e) {
49                                 console.log("Failed handler", e);
50                         }
51                 });
52
53                 CurrentDocument.fetch({
54                         success: function(){
55                                 console.log("Fetch success");
56                                 $('#loading-overlay').fadeOut();
57                                 var active_tab = document.location.hash || DEFAULT_PERSPECTIVE;
58
59                                 $(window).resize();
60
61                                 console.log("Initial tab is:", active_tab)
62                                 $.wiki.switchToTab(active_tab);
63                         },
64                         failure: function() {
65                                 $('#loading-overlay').fadeOut();
66                                 alert("FAILURE");
67                         }
68                 });
69     }; /* end of initialize() */
70
71         /* Load configuration */
72         $.wiki.loadConfig();
73
74         var initAll = function(a, f) {
75                 if (a.length == 0) return f();
76
77                 $.wiki.initTab({
78                         tab: a.pop(),
79                         doc: CurrentDocument,
80                         callback: function(){
81                                 initAll(a, f);
82                         }
83                 });
84         };
85
86
87         /*
88          * Initialize all perspectives
89          */
90         initAll( $.makeArray($('ol#tabs li')), initialize);
91         console.log(location.hash);
92 });