1/**
2* If the template doesn't natively support this plugin, go through some hard-coded cases to create reasonable coverage.
3*/
4if (!window.tpl_fastwiki_support) {
5	(function($) {
6		var m_showRow, m_editRow;
7
8		var m_utils = {
9			makeShowLink: function(url) {
10				url = url.replace(/\?do=.*$/, '');
11				return '<a href="' + url + '" class="action show" accesskey="v" rel="nofollow" title="' + JSINFO.fastwiki.text_btn_show + ' [V]"><span>' + JSINFO.fastwiki.text_btn_show + '</span></a>';
12			},
13
14			// Add a "show" link for templates which have a <ul> list of action links.
15			makeShowRowLI: function(pagetools, mode) {
16				var showLink = $("a[href $= 'do=']", pagetools);
17				if (showLink.length > 0)
18					m_showRow = $(showLink.parents('li')[0]);
19				else {
20					var link = $("a[href *= 'do=']", pagetools)[0];
21					if (link) {
22						m_showRow = $('<li>' + m_utils.makeShowLink(link.href) + '</li>').toggle(mode != 'show');
23						pagetools.prepend(m_showRow);
24					}
25				}
26			},
27
28			// Update button bars
29			fixButtons: function(showParent, allButtons, mode) {
30				var showBtn = $('.button.btn_show', showParent);
31				if (showBtn.length == 0) {
32					var url = $('form.button', allButtons)[0].action;
33					showBtnHtml = '<form class="button btn_show" method="get" action="' + url + '"><div class="no"><input type="hidden" name="do" value=""><input type="submit" value="' + JSINFO.fastwiki.text_btn_show + '" class="button" accesskey="v" title="' + JSINFO.fastwiki.text_btn_show + ' [V]"></div></form>';
34					showParent.each(function(idx, elt) {
35						var newBtn = $(showBtnHtml);
36						showBtn = showBtn.add(newBtn);
37						$(elt).prepend(newBtn.toggle(mode!='show'));
38					});
39				}
40				var editBtn = $('.button.btn_edit', allButtons);
41				if (editBtn.length > 0)
42					m_editRow = m_editRow ? m_editRow.add(editBtn) : editBtn;
43				m_showRow = m_showRow ? m_showRow.add(showBtn) : showBtn;
44			}
45		};
46
47		// dokuwiki, starter, greensteel
48		if ($('#dokuwiki__pagetools').length > 0) {
49			var hasSidebar = $('.showSidebar.hasSidebar').length > 0;
50			// Only show is supported as a start mode, because otherwise, we'd have to add pagetools for each action and check for actions being allowed.
51			window.tpl_fastwiki_startmode_support = {show:1};
52			$(window).on({
53				'fastwiki:init': function(e, mode) {
54					m_utils.makeShowRowLI($("#dokuwiki__pagetools ul"), mode);
55				},
56				'fastwiki:afterSwitch': function(e, mode, isSectionEdit, prevMode) {
57					// The dokuwiki template hides the sidebar in non-show modes
58					if (hasSidebar) {
59						$("#dokuwiki__top").toggleClass("showSidebar hasSidebar", mode == 'show');
60						$("#dokuwiki__aside").css('display', mode == 'show' ? '' : 'none');
61					}
62					m_showRow.toggle(mode != 'show');
63				}
64			});
65		}
66		// arctic
67		else if (JSINFO.fastwiki.templatename == 'arctic') {
68			window.tpl_fastwiki_startmode_support = {show:1};
69			$(window).on({
70				'fastwiki:init': function(e, mode) {
71					var buttonBars = $('#bar__bottom, #bar__top');
72					if ($('.button', buttonBars).length > 0)
73						m_utils.fixButtons($('.bar-left'), buttonBars, mode);
74					else {
75						var pagetools = $('.bar-left');
76						m_editRow = $("a[href *= 'do=edit']", pagetools);
77						m_showRow = $("a[href $= 'do=']", pagetools[0]);
78						if (m_showRow.length == 0) {
79							var url = $("a[href *= 'do=']")[0].href;
80							m_showRow = $();
81							pagetools.each(function(idx, elt) {
82								var show = $(m_utils.makeShowLink(url)).toggle(mode != 'show');
83								m_showRow = m_showRow.add(show);
84								$(elt).prepend(show);
85							});
86						}
87					}
88				},
89				'fastwiki:afterSwitch': function(e, mode, isSectionEdit, prevMode) {
90					m_showRow.toggle(mode != 'show');
91					m_editRow.toggle(mode != 'edit' && mode != 'draft');
92					$(".left_sidebar, .right_sidebar").css('display', mode=='show' ? '' : 'none');
93				}
94			});
95		}
96		// starterbootstrap
97		else if ($('ul.nav.navbar-nav').length > 0) {
98			window.tpl_fastwiki_startmode_support = {show:1};
99			$(window).on({
100				'fastwiki:init': function(e, mode) {
101					var pagetools = $("ul.nav.navbar-nav");
102					m_utils.makeShowRowLI(pagetools, mode);
103					m_editRow = $($('li', pagetools)[0]);
104				},
105				'fastwiki:afterSwitch': function(e, mode, isSectionEdit, prevMode) {
106					m_showRow.toggle(mode != 'show');
107					m_editRow.toggle(mode != 'edit' && mode != 'draft');
108				},
109				'fastwiki:updateToc': function(e, tocObj) {
110					$('#dw_toc').remove();
111
112					if (tocObj.length > 0)
113						$('.content_initial').prepend($('<div id="dw_toc"></div>').append(tocObj.html()));
114					tocObj.remove();
115				}
116			});
117		}
118		// scanlines
119		else if ($('.stylehead .bar_top .bar_top_content').length > 0) {
120			$(window).on({
121				'fastwiki:init': function(e, mode) {
122					// If the toolbox is enabled.
123					var toolbox = $(".sidebar_content .li_toolbox ul");
124					m_utils.makeShowRowLI(toolbox, mode);
125					m_editRow = $('.action.edit', toolbox).parent();
126
127					// Button bar
128					m_utils.fixButtons($('.bar_bottom_content .bar-right'), $('.bar_bottom_content .bar-right'), mode);
129				},
130				'fastwiki:afterSwitch': function(e, mode, isSectionEdit, prevMode) {
131					$(".right_sidebar, .left_sidebar").css('display', mode=='edit' ? 'none' : '');
132					m_showRow.toggle(mode != 'show');
133					m_editRow.toggle(mode != 'edit' && mode != 'draft');
134
135					// In this template, two levels of DOM structure are missing in edit mode. Clear out their styles.
136					if (mode == 'edit' || mode == 'draft') {
137						$('.page_720').css({border: 0, textAlign: 'inherit'});
138						$('.left_page, .right_page').css({float:'none', width:'auto'});
139					}
140					else {
141						$('.page_720').css({border: '', textAlign: ''});
142						$('.left_page, .right_page').css({float:'', width:''});
143					}
144				}
145			});
146		}
147	})(jQuery);
148}
149