8 var DEFAULT_PERSPECTIVE = "#VisualPerspective";
11 var tabs = $('ol#tabs li');
13 var MIN_SIDEBAR_WIDTH = 50,
14 DEFAULT_SIDEBAR_WIDTH = 480;
16 CurrentDocument = new $.wikiapi.WikiDocument("document-meta");
18 $.blockUI.defaults.baseZ = 10000;
20 function initialize() {
21 var splitter = $('#splitter'),
22 vsplitbar = $('#vsplitbar'),
23 sidebar = $('#sidebar'),
24 dragLayer = $('#drag-layer'),
25 vsplitbarWidth = vsplitbar.outerWidth(),
28 function setSidebarWidth(x) {
29 if (x < MIN_SIDEBAR_WIDTH) {
31 vsplitbar.removeClass('active');
33 vsplitbar.addClass('active');
35 $.wiki.state.perspectives.ScanGalleryPerspective.width = x;
36 sidebar[0].style.width = x + 'px';
40 $('#save-button').click(function(event){
41 event.preventDefault();
42 $.wiki.showDialog('#save_dialog');
50 $(document).on('click', '.tabs li', function(event, callback) {
51 event.preventDefault();
52 $.wiki.switchToTab(this);
55 $(document).on('click', '#tabs li .tabclose', function(event, callback) {
56 var $tab = $(this).parent().parent();
58 if($('a', $tab).is('.active'))
59 $.wiki.switchToTab(DEFAULT_PERSPECTIVE);
61 var p = $.wiki.perspectiveForTab($tab);
67 $(window).resize(function(){
68 splitterWidth = splitter.width();
72 $.wiki.perspectiveForTab($('#tabs-right .active').parent()).onEnter();
74 vsplitbar.on('click', function() {
76 if ($this.hasClass('active')) {
77 $.wiki.state.perspectives.ScanGalleryPerspective.lastWidth = sidebar.width();
80 setSidebarWidth($.wiki.state.perspectives.ScanGalleryPerspective.lastWidth);
84 /* Splitbar dragging support */
86 .mousedown(function(e) {
89 if (sidebar.width() > MIN_SIDEBAR_WIDTH) {
90 $.wiki.state.perspectives.ScanGalleryPerspective.lastWidth = sidebar.width();
93 .mousemove(function(e) {
95 dragLayer.show(); // We don't show it up until now so that we don't lose single click events on vsplitbar
98 dragLayer.mousemove(function(e) {
99 setSidebarWidth(splitterWidth - e.clientX - vsplitbarWidth / 2);
101 $('body').mouseup(function(e) {
106 setSidebarWidth($.wiki.state.perspectives.ScanGalleryPerspective.width);
108 window.onbeforeunload = function(e) {
109 if($.wiki.isDirty()) {
110 e.returnValue = "Na stronie mogą być nie zapisane zmiany.";
111 return "Na stronie mogą być nie zapisane zmiany.";
115 $('body').mousemove(function(e) {
116 CurrentDocument.active = new Date();
118 $('body').keydown(function(e) {
119 CurrentDocument.active = new Date();
122 console.log("Fetching document's text");
124 $(document).bind('wlapi_document_changed', function(event, doc) {
126 $('#document-revision').text(doc.revision);
128 console.log("Failed handler", e);
132 CurrentDocument.fetch({
134 console.log("Fetch success");
135 $('#loading-overlay').fadeOut();
136 var active_tab = document.location.hash || DEFAULT_PERSPECTIVE;
138 if(active_tab == "#ScanGalleryPerspective")
139 active_tab = DEFAULT_PERSPECTIVE;
141 console.log("Initial tab is:", active_tab)
142 $.wiki.switchToTab(active_tab);
144 /* check for a newer version */
145 CurrentDocument.checkRevision({outdated: function(){
146 $('#header').addClass('out-of-date');
148 var revTimer = setInterval(function() {
149 CurrentDocument.checkRevision({outdated: function(){
150 $('#header').addClass('out-of-date');
154 failure: function() {
155 $('#loading-overlay').fadeOut();
159 }; /* end of initialize() */
162 /* Load configuration */
166 * Initialize all perspectives
168 $('.tabs li').each((i, e) => {
169 $.wiki.initTab({tab: e, doc: CurrentDocument});