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.";
123 $('body').mousemove(function(e) {
124 CurrentDocument.active = true;
126 $('body').keydown(function(e) {
127 CurrentDocument.active = true;
131 console.log("Fetching document's text");
133 $(document).bind('wlapi_document_changed', function(event, doc) {
135 $('#document-revision').text(doc.revision);
137 console.log("Failed handler", e);
141 CurrentDocument.fetch({
143 console.log("Fetch success");
144 $('#loading-overlay').fadeOut();
145 var active_tab = document.location.hash || DEFAULT_PERSPECTIVE;
147 if(active_tab == "#ScanGalleryPerspective")
148 active_tab = DEFAULT_PERSPECTIVE;
150 console.log("Initial tab is:", active_tab)
151 $.wiki.switchToTab(active_tab);
153 /* every 5 minutes check for a newer version */
154 var revTimer = setInterval(function() {
155 CurrentDocument.checkRevision({outdated: function(){
156 $('#header').addClass('out-of-date');
157 clearInterval(revTimer);
161 failure: function() {
162 $('#loading-overlay').fadeOut();
166 }; /* end of initialize() */
169 /* Load configuration */
172 var initAll = function(a, f) {
173 if (a.length == 0) return f();
177 doc: CurrentDocument,
178 callback: function(){
186 * Initialize all perspectives
188 initAll( $.makeArray($('.tabs li')), initialize);
189 console.log(location.hash);