Fix theme box.
[redakcja.git] / src / redakcja / static / js / wiki_img / loader_readonly.js
1 if (!window.console) {
2     window.console = {
3         log: function(){
4         }
5     }
6 }
7
8
9 DEFAULT_PERSPECTIVE = "#MotifsPerspective";
10
11
12 $(function()
13 {
14         var tabs = $('ol#tabs li');
15         var gallery = null;
16
17         CurrentDocument = new $.wikiapi.WikiDocument("document-meta");
18         $.blockUI.defaults.baseZ = 10000;
19
20         function initialize()
21         {
22                 $('.editor').hide();
23
24                 /*
25                  * TABS
26                  */
27             $(document).on('click', '#tabs li', function(event, callback) {
28             event.preventDefault();
29                         $.wiki.switchToTab(this);
30         });
31
32             $(document).on('click', '#tabs li > .tabclose', function(event, callback) {
33                         var $tab = $(this).parent();
34
35                         if($tab.is('.active'))
36                                 $.wiki.switchToTab(DEFAULT_PERSPECTIVE);
37
38                         var p = $.wiki.perspectiveForTab($tab);
39                         p.destroy();
40                         return false;
41         });
42 /*
43         $(window).resize(function(){
44             $('iframe').height($(window).height() - $('#tabs').outerHeight() - $('#source-editor .toolbar').outerHeight());
45         });
46         */
47
48                 $(document).bind('wlapi_document_changed', function(event, doc) {
49                         try {
50                                 $('#document-revision').text(doc.revision);
51                         } catch(e) {
52                                 console.log("Failed handler", e);
53                         }
54                 });
55
56                 CurrentDocument.fetch({
57                         success: function(){
58                                 console.log("Fetch success");
59                                 $('#loading-overlay').fadeOut();
60                                 var active_tab = document.location.hash || DEFAULT_PERSPECTIVE;
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 });