Preliminary catalogue.
[redakcja.git] / src / 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             $(document).on('click', '#tabs li', function(event, callback) {
27             event.preventDefault();
28                         $.wiki.switchToTab(this);
29         });
30
31             $(document).on('click', '#tabs li > .tabclose', function(event, callback) {
32                         var $tab = $(this).parent();
33
34                         if($tab.is('.active'))
35                                 $.wiki.switchToTab(DEFAULT_PERSPECTIVE);
36
37                         var p = $.wiki.perspectiveForTab($tab);
38                         p.destroy();
39                         return false;
40         });
41
42         $(window).resize(function(){
43             $('iframe').height($(window).height() - $('#tabs').outerHeight() - $('#source-editor .toolbar').outerHeight());
44         });
45
46                 $(document).bind('wlapi_document_changed', function(event, doc) {
47                         try {
48                                 $('#document-revision').text(doc.revision);
49                         } catch(e) {
50                                 console.log("Failed handler", e);
51                         }
52                 });
53
54                 CurrentDocument.fetch({
55                         success: function(){
56                                 console.log("Fetch success");
57                                 $('#loading-overlay').fadeOut();
58                                 var active_tab = document.location.hash || DEFAULT_PERSPECTIVE;
59
60                                 $(window).resize();
61
62                                 console.log("Initial tab is:", active_tab)
63                                 $.wiki.switchToTab(active_tab);
64                         },
65                         failure: function() {
66                                 $('#loading-overlay').fadeOut();
67                                 alert("FAILURE");
68                         }
69                 });
70     }; /* end of initialize() */
71
72         /* Load configuration */
73         $.wiki.loadConfig();
74
75         var initAll = function(a, f) {
76                 if (a.length == 0) return f();
77
78                 $.wiki.initTab({
79                         tab: a.pop(),
80                         doc: CurrentDocument,
81                         callback: function(){
82                                 initAll(a, f);
83                         }
84                 });
85         };
86
87
88         /*
89          * Initialize all perspectives
90          */
91         initAll( $.makeArray($('#tabs li')), initialize);
92         console.log(location.hash);
93 });