Legimi update.
[redakcja.git] / src / redakcja / static / js / wiki_img / loader.js
1 if (!window.console) {
2     window.console = {
3         log: function(){
4         }
5     }
6 }
7
8 DEFAULT_PERSPECTIVE = "#MotifsPerspective";
9
10 $(function()
11 {
12         var tabs = $('ol#tabs li');
13         var gallery = null;
14         CurrentDocument = new $.wikiapi.WikiDocument("document-meta");
15
16         $.blockUI.defaults.baseZ = 10000;
17
18     function initialize()
19         {
20                 $(document).keydown(function(event) {
21                         console.log("Received key:", event);
22                 });
23
24                 /* The save button */
25         $('#save-button').click(function(event){
26             event.preventDefault();
27                         $.wiki.showDialog('#save_dialog');
28         });
29
30                 $('.editor').hide();
31
32                 /*
33                  * TABS
34                  */
35             $(document).on('click', '.tabs li', function(event, callback) {
36             event.preventDefault();
37                         $.wiki.switchToTab(this);
38         });
39
40             $(document).on('click', '#tabs li .tabclose', function(event, callback) {
41                 var $tab = $(this).parent().parent();
42
43                 if($('a', $tab).is('.active'))
44                                 $.wiki.switchToTab(DEFAULT_PERSPECTIVE);
45
46                         var p = $.wiki.perspectiveForTab($tab);
47                         p.destroy();
48
49                         return false;
50         });
51
52
53         window.onbeforeunload = function(e) {
54             if($.wiki.isDirty()) {
55                                 e.returnValue = "Na stronie mogą być nie zapisane zmiany.";
56                                 return "Na stronie mogą być nie zapisane zmiany.";
57                         };
58         };
59
60                 console.log("Fetching document's text");
61
62                 $(document).bind('wlapi_document_changed', function(event, doc) {
63                         try {
64                                 $('#document-revision').text(doc.revision);
65                         } catch(e) {
66                                 console.log("Failed handler", e);
67                         }
68                 });
69
70                 CurrentDocument.fetch({
71                         success: function(){
72                                 console.log("Fetch success");
73                                 $('#loading-overlay').fadeOut();
74                                 var active_tab = document.location.hash || DEFAULT_PERSPECTIVE;
75
76                                 console.log("Initial tab is:", active_tab)
77                                 $.wiki.switchToTab(active_tab);
78                         },
79                         failure: function() {
80                                 $('#loading-overlay').fadeOut();
81                                 alert("FAILURE");
82                         }
83                 });
84     }; /* end of initialize() */
85
86
87         /* Load configuration */
88         $.wiki.loadConfig();
89
90         var initAll = function(a, f) {
91                 if (a.length == 0) return f();
92
93                 $.wiki.initTab({
94                         tab: a.pop(),
95                         doc: CurrentDocument,
96                         callback: function(){
97                                 initAll(a, f);
98                         }
99                 });
100         };
101
102
103         /*
104          * Initialize all perspectives
105          */
106         initAll( $.makeArray($('.tabs li')), initialize);
107         console.log(location.hash);
108 });
109
110