8 var DEFAULT_PERSPECTIVE = "#VisualPerspective";
12 var tabs = $('ol#tabs li');
14 var MIN_SIDEBAR_WIDTH = 50,
15 DEFAULT_SIDEBAR_WIDTH = 480;
17 CurrentDocument = new $.wikiapi.WikiDocument("document-meta");
19 $.blockUI.defaults.baseZ = 10000;
23 var splitter = $('#splitter'),
24 vsplitbar = $('#vsplitbar'),
25 sidebar = $('#sidebar'),
26 dragLayer = $('#drag-layer'),
27 vsplitbarWidth = vsplitbar.outerWidth(),
30 function setSidebarWidth(x) {
31 if (x < MIN_SIDEBAR_WIDTH) {
33 vsplitbar.removeClass('active');
35 vsplitbar.addClass('active');
37 $.wiki.state.perspectives.ScanGalleryPerspective.width = x;
38 sidebar[0].style.width = x + 'px';
43 $('#save-button').click(function(event){
44 event.preventDefault();
45 $.wiki.showDialog('#save_dialog');
53 $(document).on('click', '.tabs li', function(event, callback) {
54 event.preventDefault();
55 $.wiki.switchToTab(this);
58 $(document).on('click', '#tabs li .tabclose', function(event, callback) {
59 var $tab = $(this).parent().parent();
61 if($('a', $tab).is('.active'))
62 $.wiki.switchToTab(DEFAULT_PERSPECTIVE);
64 var p = $.wiki.perspectiveForTab($tab);
71 $(window).resize(function(){
72 splitterWidth = splitter.width();
76 $.wiki.perspectiveForTab($('#tabs-right .active').parent()).onEnter();
78 vsplitbar.on('click', function() {
80 if ($this.hasClass('active')) {
81 $.wiki.state.perspectives.ScanGalleryPerspective.lastWidth = sidebar.width();
84 setSidebarWidth($.wiki.state.perspectives.ScanGalleryPerspective.lastWidth);
89 /* Splitbar dragging support */
91 .mousedown(function(e) {
94 if (sidebar.width() > MIN_SIDEBAR_WIDTH) {
95 $.wiki.state.perspectives.ScanGalleryPerspective.lastWidth = sidebar.width();
98 .mousemove(function(e) {
100 dragLayer.show(); // We don't show it up until now so that we don't lose single click events on vsplitbar
103 dragLayer.mousemove(function(e) {
104 setSidebarWidth(splitterWidth - e.clientX - vsplitbarWidth / 2);
106 $('body').mouseup(function(e) {
111 setSidebarWidth($.wiki.state.perspectives.ScanGalleryPerspective.width);
113 window.onbeforeunload = function(e) {
114 if($.wiki.isDirty()) {
115 e.returnValue = "Na stronie mogą być nie zapisane zmiany.";
116 return "Na stronie mogą być nie zapisane zmiany.";
120 console.log("Fetching document's text");
122 $(document).bind('wlapi_document_changed', function(event, doc) {
124 $('#document-revision').text(doc.revision);
126 console.log("Failed handler", e);
130 CurrentDocument.fetch({
132 console.log("Fetch success");
133 $('#loading-overlay').fadeOut();
134 var active_tab = document.location.hash || DEFAULT_PERSPECTIVE;
136 if(active_tab == "#ScanGalleryPerspective")
137 active_tab = DEFAULT_PERSPECTIVE;
139 console.log("Initial tab is:", active_tab)
140 $.wiki.switchToTab(active_tab);
142 /* every 5 minutes check for a newer version */
143 var revTimer = setInterval(function() {
144 CurrentDocument.checkRevision({outdated: function(){
145 $('#header').addClass('out-of-date');
146 clearInterval(revTimer);
150 failure: function() {
151 $('#loading-overlay').fadeOut();
155 }; /* end of initialize() */
158 /* Load configuration */
161 var initAll = function(a, f) {
162 if (a.length == 0) return f();
166 doc: CurrentDocument,
167 callback: function(){
175 * Initialize all perspectives
177 initAll( $.makeArray($('.tabs li')), initialize);
178 console.log(location.hash);