xml format change + fixes
[redakcja.git] / 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         $('#tabs li').live('click', function(event, callback) {
28                         $.wiki.switchToTab(this);
29         });
30
31                 $('#tabs li > .tabclose').live('click', 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
47                 $(document).bind('wlapi_document_changed', function(event, doc) {
48                         try {
49                                 $('#document-revision').text(doc.revision);
50                         } catch(e) {
51                                 console.log("Failed handler", e);
52                         }
53                 });
54
55                 CurrentDocument.fetch({
56                         success: function(){
57                                 console.log("Fetch success");
58                                 $('#loading-overlay').fadeOut();
59                                 var active_tab = document.location.hash || DEFAULT_PERSPECTIVE;
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 });