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 $.wiki.switchToTab(this);
56 $('#tabs li > .tabclose').live('click', function(event, callback) {
57 var $tab = $(this).parent();
59 if($tab.is('.active'))
60 $.wiki.switchToTab(DEFAULT_PERSPECTIVE);
62 var p = $.wiki.perspectiveForTab($tab);
69 $(window).resize(function(){
70 $('iframe').height($(window).height() - $('#tabs').outerHeight() - $('#source-editor .toolbar').outerHeight());
71 splitterWidth = splitter.width();
78 $.wiki.state.perspectives.ScanGalleryPerspective.show = true;
79 setSplitbarAt(splitterWidth - (480 + vsplitbarWidth));
80 $('.vsplitbar').addClass('active');
82 $.wiki.perspectiveForTab('#tabs-right .active').onEnter();
85 var active_right = $.wiki.perspectiveForTab('#tabs-right .active');
86 $.wiki.state.perspectives.ScanGalleryPerspective.show = false;
87 $(".vsplitbar-title").html("↑ " + active_right.vsplitbar + " ↑");
88 setSplitbarAt(splitterWidth - vsplitbarWidth);
89 $('.vsplitbar').removeClass('active');
91 active_right.onExit();
96 /* Splitbar dragging support */
98 .mousedown(function(e) {
102 .mousemove(function(e) {
104 dragLayer.show(); // We don't show it up until now so that we don't lose single click events on vsplitbar
107 dragLayer.mousemove(function(e) {
108 setSplitbarAt(e.clientX - vsplitbarWidth/2);
110 $('body').mouseup(function(e) {
116 if($.wiki.state.perspectives.ScanGalleryPerspective.show){
117 $('.vsplitbar').trigger('click');
118 $(".vsplitbar-title").html("↓ GALERIA ↓");
120 $(".vsplitbar-title").html("↑ GALERIA ↑");
122 window.onbeforeunload = function(e) {
123 if($.wiki.isDirty()) {
124 e.returnValue = "Na stronie mogą być nie zapisane zmiany.";
125 return "Na stronie mogą być nie zapisane zmiany.";
129 console.log("Fetching document's text");
131 $(document).bind('wlapi_document_changed', function(event, doc) {
133 $('#document-revision').text(doc.revision);
135 console.log("Failed handler", e);
139 CurrentDocument.fetch({
141 console.log("Fetch success");
142 $('#loading-overlay').fadeOut();
143 var active_tab = document.location.hash || DEFAULT_PERSPECTIVE;
145 if(active_tab == "#ScanGalleryPerspective")
146 active_tab = DEFAULT_PERSPECTIVE;
148 console.log("Initial tab is:", active_tab)
149 $.wiki.switchToTab(active_tab);
151 /* every 5 minutes check for a newer version */
152 var revTimer = setInterval(function() {
153 CurrentDocument.checkRevision({outdated: function(){
154 $('#header').addClass('out-of-date');
155 clearInterval(revTimer);
159 failure: function() {
160 $('#loading-overlay').fadeOut();
164 }; /* end of initialize() */
167 /* Load configuration */
170 var initAll = function(a, f) {
171 if (a.length == 0) return f();
175 doc: CurrentDocument,
176 callback: function(){
184 * Initialize all perspectives
186 initAll( $.makeArray($('.tabs li')), initialize);
187 console.log(location.hash);