8 var DEFAULT_PERSPECTIVE = "#VisualPerspective";
12 var tabs = $('ol#tabs li');
14 CurrentDocument = new $.wikiapi.WikiDocument("document-meta");
16 $.blockUI.defaults.baseZ = 10000;
20 var splitter = $('#splitter'),
21 editors = $('#editor .editor'),
22 vsplitbar = $('.vsplitbar'),
23 sidebar = $('#sidebar'),
24 dragLayer = $('#drag-layer'),
25 vsplitbarWidth = vsplitbar.outerWidth(),
28 // Moves panes so that left border of the vsplitbar lands x pixels from the left border of the splitter
29 function setSplitbarAt(x) {
30 var right = splitterWidth - x;
31 editors.each(function() {
32 this.style.right = right + 'px';
34 vsplitbar[0].style.right = sidebar[0].style.width = (right - vsplitbarWidth) + 'px';
37 $(document).keydown(function(event) {
38 console.log("Received key:", event);
42 $('#save-button').click(function(event){
43 event.preventDefault();
44 $.wiki.showDialog('#save_dialog');
52 $('.tabs li').live('click', function(event, callback) {
53 event.preventDefault();
54 $.wiki.switchToTab(this);
57 $('#tabs li > .tabclose').live('click', function(event, callback) {
58 var $tab = $(this).parent();
60 if($tab.is('.active'))
61 $.wiki.switchToTab(DEFAULT_PERSPECTIVE);
63 var p = $.wiki.perspectiveForTab($tab);
70 $(window).resize(function(){
71 $('iframe').height($(window).height() - $('#tabs').outerHeight() - $('#source-editor .toolbar').outerHeight());
72 splitterWidth = splitter.width();
79 $.wiki.state.perspectives.ScanGalleryPerspective.show = true;
80 setSplitbarAt(splitterWidth - (480 + vsplitbarWidth));
81 $('.vsplitbar').addClass('active');
83 $.wiki.perspectiveForTab('#tabs-right .active').onEnter();
86 var active_right = $.wiki.perspectiveForTab('#tabs-right .active');
87 $.wiki.state.perspectives.ScanGalleryPerspective.show = false;
88 $(".vsplitbar-title").html("↑ " + active_right.vsplitbar + " ↑");
89 setSplitbarAt(splitterWidth - vsplitbarWidth);
90 $('.vsplitbar').removeClass('active');
92 active_right.onExit();
97 /* Splitbar dragging support */
99 .mousedown(function(e) {
103 .mousemove(function(e) {
105 dragLayer.show(); // We don't show it up until now so that we don't lose single click events on vsplitbar
108 dragLayer.mousemove(function(e) {
109 setSplitbarAt(e.clientX - vsplitbarWidth/2);
111 $('body').mouseup(function(e) {
117 if($.wiki.state.perspectives.ScanGalleryPerspective.show){
118 $('.vsplitbar').trigger('click');
119 $(".vsplitbar-title").html("↓ GALERIA ↓");
121 $(".vsplitbar-title").html("↑ GALERIA ↑");
123 window.onbeforeunload = function(e) {
124 if($.wiki.isDirty()) {
125 e.returnValue = "Na stronie mogą być nie zapisane zmiany.";
126 return "Na stronie mogą być nie zapisane zmiany.";
130 console.log("Fetching document's text");
132 $(document).bind('wlapi_document_changed', function(event, doc) {
134 $('#document-revision').text(doc.revision);
136 console.log("Failed handler", e);
140 CurrentDocument.fetch({
142 console.log("Fetch success");
143 $('#loading-overlay').fadeOut();
144 var active_tab = document.location.hash || DEFAULT_PERSPECTIVE;
146 if(active_tab == "#ScanGalleryPerspective")
147 active_tab = DEFAULT_PERSPECTIVE;
149 console.log("Initial tab is:", active_tab)
150 $.wiki.switchToTab(active_tab);
152 /* every 5 minutes check for a newer version */
153 var revTimer = setInterval(function() {
154 CurrentDocument.checkRevision({outdated: function(){
155 $('#header').addClass('out-of-date');
156 clearInterval(revTimer);
160 failure: function() {
161 $('#loading-overlay').fadeOut();
165 }; /* end of initialize() */
168 /* Load configuration */
171 var initAll = function(a, f) {
172 if (a.length == 0) return f();
176 doc: CurrentDocument,
177 callback: function(){
185 * Initialize all perspectives
187 initAll( $.makeArray($('.tabs li')), initialize);
188 console.log(location.hash);