You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1009 lines
34 KiB

  1. /*!
  2. * DokuWiki Bootstrap3 Template: Hacks!
  3. *
  4. * Home http://dokuwiki.org/template:bootstrap3
  5. * Author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
  6. * License GPL 2 (http://www.gnu.org/licenses/gpl.html)
  7. */
  8. /* DOKUWIKI:include assets/bootstrap/js/bootstrap.min.js */
  9. /* DOKUWIKI:include assets/anchorjs/anchor.min.js */
  10. /* DOKUWIKI:include assets/typeahead/bootstrap3-typeahead.min.js */
  11. /* DOKUWIKI:include assets/iconify/iconify.min.js */
  12. /* DOKUWIKI:include assets/iconify/plugins/fa.js */
  13. // Detect Icoonify support with Icon Plugin
  14. if (!Iconify.getConfig('defaultAPI').match('lib/plugins/icons')) {
  15. Iconify.setConfig('defaultAPI', DOKU_TPL + 'iconify.php?prefix={prefix}&icons={icons}');
  16. }
  17. if (typeof JSINFO.bootstrap3 === 'undefined') {
  18. JSINFO.bootstrap3 = {
  19. config: {}
  20. };
  21. }
  22. if (typeof JSINFO.plugin === 'undefined') {
  23. JSINFO.plugin = {};
  24. }
  25. function dw_mode(id) {
  26. return ((JSINFO.bootstrap3.mode === id) ? true : false);
  27. }
  28. function dw_admin(page) {
  29. return ((JSINFO.bootstrap3.admin === page) ? true : false);
  30. }
  31. function mediaSize(media) {
  32. return jQuery(['#screen__mode .visible-', media, '-block'].join('')).is(':visible');
  33. }
  34. var dw_template = {
  35. init: function () {
  36. dw_template.common();
  37. dw_template.mobileLayout();
  38. dw_template.toc();
  39. dw_template.tabs();
  40. dw_template.tocMenu();
  41. dw_template.nav();
  42. dw_template.backToTop();
  43. dw_template.anchorJS();
  44. dw_template.pageTools();
  45. dw_template.pageIcons();
  46. dw_template.dropdownPage();
  47. dw_template.footnotes();
  48. dw_template.mediaManager();
  49. dw_template.collapseSections();
  50. dw_template.pageRestoreConfirm();
  51. dw_template.alerts();
  52. dw_template.detail();
  53. dw_template.menuitem();
  54. dw_template.cookieLaw();
  55. dw_template.plugins();
  56. // Enable Typeahead
  57. if (! JSINFO.bootstrap3.config.disableSearchSuggest) {
  58. dw_template.typeahead();
  59. }
  60. // Preload icons
  61. Iconify.preloadImages(['mdi:folder-open', 'mdi:folder', 'mdi:file-document-outline', 'mdi:chevron-up', 'mdi:chevron-down']);
  62. // Mobile Layout
  63. jQuery(window).resize(function () {
  64. dw_template.mobileLayout();
  65. dw_template.collapseSections();
  66. dw_template.tocResize();
  67. });
  68. // Re-initialize some components in media-manager
  69. if (dw_mode('media') || jQuery('#media__manager').length) {
  70. jQuery(document).ajaxSuccess(function () {
  71. dw_template.common();
  72. dw_template.buttons();
  73. dw_template.tabs();
  74. dw_template.mediaManager();
  75. dw_template.alerts();
  76. });
  77. }
  78. // Index Mode
  79. if (dw_mode('index')) {
  80. jQuery(document).ajaxSuccess(function () {
  81. dw_template.modeIndex();
  82. });
  83. jQuery('#index__tree').click(function (e) {
  84. dw_template.modeIndex();
  85. });
  86. }
  87. // Hash change
  88. if (JSINFO.bootstrap3.config.fixedTopNavbar) {
  89. var scrollOnHashChange = function () {
  90. scrollBy(0, - (parseInt(jQuery('body').css('marginTop')) || 0));
  91. };
  92. if (location.hash) {
  93. setTimeout(function () {
  94. scrollOnHashChange();
  95. }, 1);
  96. }
  97. jQuery(window).on('hashchange', function () {
  98. scrollOnHashChange();
  99. });
  100. }
  101. },
  102. // Normalization & Basic Styling
  103. common: function () {
  104. var $dw_content = jQuery('#dokuwiki__content, #media__manager'); // Page Content node
  105. // Abbr tooltips
  106. jQuery('abbr').tooltip();
  107. // Search Hit
  108. jQuery('.search_hit').removeClass('search_hit').addClass('mark');
  109. // Fix accesskey issue on dropdown menu
  110. if (jQuery('#dw__pagetools').length) {
  111. jQuery('ul.dropdown-menu li a[accesskey]')
  112. .closest('.top, .revs, .show, .edit')
  113. .removeAttr('accesskey');
  114. }
  115. // Form and controls
  116. // TODO ported
  117. $dw_content.find(':submit, :button, :reset').addClass('btn btn-default');
  118. jQuery('input, select, textarea')
  119. .not('[type=submit], [type=reset], [type=button], [type=hidden], [type=image], [type=checkbox], [type=radio]')
  120. .addClass('form-control');
  121. jQuery('input[type=checkbox]').addClass('checkbox-inline');
  122. jQuery('input[type=radio]').addClass('radio-inline');
  123. jQuery('label').addClass('control-label');
  124. jQuery('main form:not(.form-horizontal)').addClass('form-inline');
  125. // Toolbar
  126. jQuery('#tool__bar').addClass('btn-group');
  127. // Add icons
  128. jQuery('[data-dw-icon]').each(function () {
  129. var $self = jQuery(this);
  130. var $icon = jQuery('<span class="iconify mr-1">').attr('data-icon', $self.attr('data-dw-icon'));
  131. if ($self.attr('data-dw-icon-target')) {
  132. $self.find($self.attr('data-dw-icon-target')).prepend($icon);
  133. } else {
  134. $self.prepend($icon);
  135. }
  136. });
  137. // Picker
  138. // if (dw_mode('edit')) {
  139. // jQuery('.picker').addClass('btn-group');
  140. // }
  141. // Footer links
  142. jQuery('footer a').addClass('navbar-link');
  143. // Personal Home-Page icon
  144. if (NS == 'user' && dw_mode('show') && !jQuery('.notFound').length) {
  145. jQuery('.mode_show #dokuwiki__content h1').prepend('<span class="iconify mr-2" data-icon="mdi:account"/> ');
  146. }
  147. // Scrolling animation (on TOC and FootNotes)
  148. jQuery('#dw__toc a, #dw__toc_menu a, a.fn_top, a.fn_bot').on('click', function (e) {
  149. var $link = jQuery(this);
  150. if ($link.attr('href').match(/^#/) && $link.attr('href').length > 1) {
  151. e.preventDefault();
  152. if (mediaSize('xs') && $link.hasClass('fn_top')) {
  153. return false;
  154. }
  155. if (JSINFO.bootstrap3.config.tocCollapseOnScroll && JSINFO.bootstrap3.config.tocAffix) {
  156. dw_template.tocClose();
  157. }
  158. var $target = jQuery('body ' + $link.attr('href'));
  159. if ($target.length) {
  160. var body_offset = (parseInt(jQuery('body').css('marginTop')) || 0),
  161. target_position = Math.round($target.offset().top - body_offset);
  162. jQuery('html, body').animate({
  163. scrollTop: target_position
  164. }, 600);
  165. document.location.hash = $link.attr('href');
  166. }
  167. return false;
  168. }
  169. });
  170. },
  171. /**
  172. * Customize jQuery UI with Bootstrap v3 classes
  173. */
  174. jQueryUI: function () {
  175. if (typeof jQuery.ui === 'undefined') return false;
  176. // accordion
  177. jQuery.ui.accordion.prototype.options.classes["ui-accordion"] = "panel panel-default";
  178. jQuery.ui.accordion.prototype.options.classes["ui-accordion-content"] = "panel-collapse collapse";
  179. jQuery.ui.accordion.prototype.options.classes["ui-accordion-content-active"] = "in";
  180. jQuery.ui.accordion.prototype.options.classes["ui-accordion-header"] = "panel-heading";
  181. // button
  182. jQuery.ui.button.prototype.options.classes["ui-button"] = "btn btn-default";
  183. jQuery.ui.button.prototype.options.classes["ui-button-icon"] = "glyphicon";
  184. // dialog
  185. jQuery.ui.dialog.prototype.options.classes["ui-dialog"] = "modal-content";
  186. jQuery.ui.dialog.prototype.options.classes["ui-dialog-titlebar"] = "modal-header";
  187. jQuery.ui.dialog.prototype.options.classes["ui-dialog-title"] = "modal-title";
  188. jQuery.ui.dialog.prototype.options.classes["ui-dialog-titlebar-close"] = "btn btn-default";
  189. jQuery.ui.dialog.prototype.options.classes["ui-dialog-content"] = "modal-body";
  190. jQuery.ui.dialog.prototype.options.classes["ui-dialog-buttonpane"] = "modal-footer";
  191. // menu
  192. jQuery.ui.menu.prototype.options.classes["ui-menu"] = "list-group";
  193. jQuery.ui.menu.prototype.options.classes["ui-menu-icons"] = "";
  194. jQuery.ui.menu.prototype.options.classes["ui-menu-icon"] = "glyphicon glyphicon-chevron-right";
  195. jQuery.ui.menu.prototype.options.classes["ui-menu-item"] = "list-group-item";
  196. jQuery.ui.menu.prototype.options.classes["ui-menu-divider"] = "";
  197. jQuery.ui.menu.prototype.options.classes["ui-menu-item-wrapper"] = "";
  198. // progressbar
  199. jQuery.ui.progressbar.prototype.options.classes["ui-progressbar"] = "progress";
  200. jQuery.ui.progressbar.prototype.options.classes["ui-progressbar-value"] = "progress-bar";
  201. // selectmenu
  202. jQuery.ui.selectmenu.prototype.options.classes["ui-selectmenu-button"] = "btn btn-default dropdown-toggle";
  203. jQuery.ui.selectmenu.prototype.options.classes["ui-selectmenu-open"] = "open";
  204. jQuery.ui.selectmenu.prototype.options.icons.button = "caret";
  205. jQuery.ui.selectmenu.prototype.options.width = "auto";
  206. // tabs
  207. jQuery.ui.tabs.prototype.options.classes["ui-tabs-nav"] = "nav nav-tabs";
  208. jQuery.ui.tabs.prototype.options.classes["ui-tabs-panel"] = "tab-pane";
  209. jQuery.ui.tabs.prototype.options.classes["ui-tabs-active"] = "active";
  210. // tooltip
  211. jQuery.ui.tooltip.prototype.options.classes["ui-tooltip"] = "tooltip top fade in";
  212. jQuery.ui.tooltip.prototype.options.classes["ui-tooltip-content"] = "tooltip-inner";
  213. },
  214. nav: function () {
  215. // Unwrap unnecessary tags inside list items for Bootstrap nav component
  216. jQuery('.nav div.li').contents().unwrap();
  217. // Move the font-icons inside a link
  218. jQuery('.nav li .dw-icons + a').each(function () {
  219. var $link = jQuery(this),
  220. $icon = $link.prev();
  221. $icon.prependTo($link);
  222. $icon.after(' ');
  223. });
  224. },
  225. tabs: function () {
  226. jQuery('ul.tabs').addClass('nav nav-tabs');
  227. jQuery('.nav-tabs strong').replaceWith(function () {
  228. jQuery(this).parent().addClass('active');
  229. return jQuery('<a href="#"/>').html(jQuery(this).contents());
  230. });
  231. },
  232. buttons: function () {
  233. // TODO ported
  234. jQuery('.button').removeClass('button'); // Not ported
  235. jQuery('.alert button').removeClass('btn btn-default');
  236. jQuery('#dw__login, #dw__register, #subscribe__form, #media__manager').find(':submit').addClass('btn-success');
  237. jQuery('#dw__profiledelete').find(':submit').addClass('btn-danger');
  238. jQuery('#edbtn__save').addClass('btn-success');
  239. // Section Button edit
  240. // TODO ported
  241. jQuery('.btn_secedit .btn').addClass('btn-xs');
  242. },
  243. backToTop: function () {
  244. jQuery('.back-to-top').click(function (e) {
  245. e.preventDefault();
  246. jQuery('html, body').animate({ scrollTop: 0 }, 600);
  247. });
  248. // Display back-to-top during scroll
  249. jQuery(window).scroll(function () {
  250. if (jQuery(this).scrollTop()) {
  251. jQuery('.back-to-top').fadeIn();
  252. } else {
  253. jQuery('.back-to-top').fadeOut();
  254. }
  255. });
  256. },
  257. footnotes: function () {
  258. var orig_insituPopup = dw_page.insituPopup;
  259. dw_page.insituPopup = function (target, popup_id) {
  260. var $fndiv = orig_insituPopup(target, popup_id);
  261. $fndiv.addClass('panel panel-body panel-default');
  262. return $fndiv;
  263. }
  264. },
  265. alerts: function () {
  266. // Info
  267. jQuery('div.info')
  268. .removeClass('info')
  269. .addClass('alert alert-info')
  270. .prepend('<span class="iconify mr-2" data-height="18" data-icon="mdi:information"/>');
  271. // Error
  272. jQuery('div.error')
  273. .removeClass('error')
  274. .addClass('alert alert-danger')
  275. .prepend('<span class="iconify mr-2" data-height="18" data-icon="mdi:alert-octagon"/>');
  276. // Success
  277. jQuery('div.success')
  278. .removeClass('success')
  279. .addClass('alert alert-success')
  280. .prepend('<span class="iconify mr-2" data-height="18" data-icon="mdi:check-circle"/>');
  281. // Notify
  282. jQuery('div.notify')
  283. .removeClass('notify')
  284. .addClass('alert alert-warning')
  285. .prepend('<span class="iconify mr-2" data-height="18" data-icon="mdi:alert"/>');
  286. },
  287. cookieLaw: function () {
  288. jQuery('#cookieDismiss').on('click', function () {
  289. jQuery('#cookieNotice').hide();
  290. DokuCookie.setValue('cookieNoticeAccepted', 1);
  291. });
  292. },
  293. anchorJS: function () {
  294. if (!JSINFO.bootstrap3.config.useAnchorJS) return false;
  295. anchors.add('.mode_show article .dw-content h1, .mode_show article ' +
  296. '.dw-content h2, .mode_show article .dw-content h3, ' +
  297. '.mode_show article .dw-content h4, .mode_show article ' +
  298. '.dw-content h5');
  299. },
  300. dropdownPage: function () {
  301. jQuery('.dw__dropdown_page .dropdown').hover(function () {
  302. if (!jQuery('#screen_mode').find('.visible-xs').is(':visible')) {
  303. jQuery(this).addClass('open');
  304. }
  305. },
  306. function () {
  307. if (!jQuery('#screen_mode').find('.visible-xs').is(':visible')) {
  308. jQuery(this).removeClass('open');
  309. }
  310. });
  311. },
  312. pageIcons: function () {
  313. var $dw_page_icons = jQuery('.dw-page-icons');
  314. if (!$dw_page_icons.length) return false;
  315. var title = encodeURIComponent(document.title),
  316. url = encodeURIComponent(location),
  317. window_options = 'width=800,height=600,menubar=no,location=no,status=no';
  318. var share_to = {
  319. 'twitter': (function () { return ['https://twitter.com/intent/tweet?text=', title, '&url=', url].join(''); })(),
  320. 'linkedin': (function () { return ['https://www.linkedin.com/shareArticle?mini=true&url=', url, '&title=', title].join(''); })(),
  321. 'facebook': (function () { return ['https://www.facebook.com/sharer/sharer.php?u=', url, '&t=', title].join(''); })(),
  322. 'pinterest': (function () { return ['https://pinterest.com/pin/create/button/?url=', url, '&description=', title].join(''); })(),
  323. 'telegram': (function () { return ['https://telegram.me/share/url?url=', url].join(''); })(),
  324. 'whatsapp': (function () { return ['https://wa.me/?text=', title, ': ', url].join(''); })(),
  325. 'yammer': (function () { return ['https://www.yammer.com/messages/new?login=true&trk_event=yammer_share&status=', url, '#/Messages/bookmarklet'].join(''); })(),
  326. 'sendmail': (function () { return ['mailto:?subject=', document.title, '&body=', document.URL].join(''); })(),
  327. 'reddit': (function () { return ['https://www.reddit.com/submit?url=', url, '&title=', title].join(''); })(),
  328. 'msteams': (function () { return ['https://teams.microsoft.com/share?href=', url, '&referrer=', location.host].join(''); })(),
  329. };
  330. $dw_page_icons.find('.share-twitter').on('click', function () {
  331. window.open(share_to.twitter, 'Share to Twitter', window_options);
  332. });
  333. $dw_page_icons.find('.share-linkedin').on('click', function () {
  334. window.open(share_to.linkedin, 'Share to Linkedin', window_options);
  335. });
  336. $dw_page_icons.find('.share-facebook').on('click', function () {
  337. window.open(share_to.facebook, 'Share to Facebook', window_options);
  338. });
  339. $dw_page_icons.find('.share-pinterest').on('click', function () {
  340. window.open(share_to.pinterest, 'Share to Pinterest', window_options);
  341. });
  342. $dw_page_icons.find('.share-telegram').on('click', function () {
  343. window.open(share_to.telegram, 'Share to Telegram', window_options);
  344. });
  345. $dw_page_icons.find('.share-yammer').on('click', function () {
  346. window.open(share_to.yammer, 'Share to Yammer', window_options);
  347. });
  348. $dw_page_icons.find('.share-reddit').on('click', function () {
  349. window.open(share_to.reddit, 'Share to Reddit', window_options);
  350. });
  351. $dw_page_icons.find('.sendmail').on('click', function (e) {
  352. e.preventDefault();
  353. window.location = share_to['sendmail'];
  354. });
  355. $dw_page_icons.find('.share-whatsapp').on('click', function () {
  356. window.open(share_to.whatsapp, 'Share to WhatsApp', window_options);
  357. });
  358. $dw_page_icons.find('.share-microsoft-teams').on('click', function () {
  359. window.open(share_to.msteams, 'Share to Microsoft Teams', window_options);
  360. });
  361. },
  362. pageTools: function () {
  363. if (!jQuery('#dw__pagetools').length) return false;
  364. // Page Tools Affix
  365. jQuery('#dw__pagetools .tools').affix({
  366. offset: {
  367. top: (jQuery('main').position().top),
  368. bottom: (jQuery(document).height()
  369. - jQuery('#dokuwiki__content').height()
  370. - jQuery('#dokuwiki__pageheader').height()
  371. - jQuery('#dokuwiki__header').height())
  372. }
  373. });
  374. var $pagetools = jQuery('#dw__pagetools');
  375. $pagetools.find('svg').hover(
  376. function () {
  377. var $node = jQuery(this);
  378. $node.closest('li.active').removeClass('active');
  379. $node.closest('li').addClass('active');
  380. },
  381. function () {
  382. var $node = jQuery(this);
  383. $node.closest('li.active').removeClass('active');
  384. }
  385. );
  386. },
  387. collapseSections: function () {
  388. if (!JSINFO.bootstrap3.config.collapsibleSections) return false;
  389. var $sections = jQuery('article div.level2'),
  390. $headings = $sections.prev();
  391. if (mediaSize('xs')) {
  392. $sections.addClass('hide');
  393. if (!$headings.find('svg').length) {
  394. $headings
  395. .css('cursor', 'pointer')
  396. .prepend(Iconify.getSVG('mdi:chevron-down'));
  397. $headings.on('click', function () {
  398. var $heading = jQuery(this),
  399. $icon = $heading.find('svg'),
  400. $section = $heading.nextUntil('h2');
  401. $section.toggleClass('hide');
  402. $heading.css('cursor', 'pointer');
  403. $section.hasClass('hide')
  404. ? $icon.replaceWith(Iconify.getSVG('mdi:chevron-down'))
  405. : $icon.replaceWith(Iconify.getSVG('mdi:chevron-up'));
  406. });
  407. if (mediaSize('xs')) {
  408. $headings.trigger('click');
  409. }
  410. }
  411. } else {
  412. if ($sections.hasClass('hide')) {
  413. $sections.removeClass('hide');
  414. }
  415. }
  416. },
  417. mobileLayout: function () {
  418. var $dw_aside = jQuery('.dw__sidebar');
  419. if (!$dw_aside.length) return false;
  420. if (mediaSize('xs')) {
  421. if (JSINFO.bootstrap3.config.sidebarOnNavbar) {
  422. if (!jQuery('header aside').length) {
  423. jQuery('<aside/>').prependTo('header nav div .navbar-collapse');
  424. $dw_aside.find('.dw-sidebar-content').clone().appendTo('header aside');
  425. jQuery('header aside .dw-sidebar-title').addClass('navbar-text');
  426. }
  427. jQuery('header aside').show();
  428. $dw_aside.hide();
  429. } else {
  430. if (!$dw_aside.find('.dw-sidebar-content').hasClass('panel')) {
  431. $dw_aside.find('.dw-sidebar-content').addClass('panel panel-default');
  432. $dw_aside.find('.dw-sidebar-title').addClass('panel-heading');
  433. $dw_aside.find('.dw-sidebar-body').addClass('panel-body').removeClass('in');
  434. }
  435. }
  436. } else {
  437. jQuery('header aside').hide();
  438. $dw_aside.find('.dw-sidebar-content').removeClass('panel panel-default');
  439. $dw_aside.find('.dw-sidebar-title').removeClass('panel-heading');
  440. $dw_aside.find('.dw-sidebar-body').removeClass('panel-body').addClass('in');
  441. $dw_aside.show();
  442. }
  443. },
  444. modeIndex: function () {
  445. if (!dw_mode('index')) return false;
  446. var $directories = jQuery('ul.idx a.idx_dir'),
  447. $pages = jQuery('ul.idx a.wikilink1');
  448. jQuery.each($directories, function () {
  449. var $directory = jQuery(this),
  450. $closed = $directory.parents('.closed'),
  451. $open = $directory.parents('.open');
  452. if (!$directory.find('svg').length) {
  453. $directory.prepend(Iconify.getSVG('mdi:folder'));
  454. }
  455. if ($open.length) {
  456. $directory.find('svg').replaceWith(Iconify.getSVG('mdi:folder-open'));
  457. }
  458. if ($closed.length) {
  459. $directory.find('svg').replaceWith(Iconify.getSVG('mdi:folder'));
  460. }
  461. $directory.find('svg').addClass('iconify text-primary mr-2');
  462. });
  463. jQuery.each($pages, function () {
  464. var $page = jQuery(this);
  465. if (!$page.find('svg').length) {
  466. $page.prepend(Iconify.getSVG('mdi:file-document-outline'));
  467. }
  468. $page.find('svg').addClass('text-muted mr-2');
  469. });
  470. },
  471. mediaManager: function () {
  472. var $media_popup = jQuery('#media__content'), // Media Manager (pop-up)
  473. $media_manager = jQuery('#mediamanager__page'); // Media Manager (page)
  474. // Media Manager (pop-up)
  475. if ($media_popup.length || $media_manager.length) {
  476. jQuery('.qq-upload-button').addClass('btn btn-default');
  477. jQuery('.qq-upload-action').addClass('btn btn-success');
  478. var $btn_delete = jQuery('#mediamanager__btn_delete [type=submit]');
  479. var $btn_update = jQuery('#mediamanager__btn_update [type=submit]');
  480. if (!$btn_delete.find('span').length) {
  481. $btn_delete.addClass('btn btn-danger');
  482. $btn_delete.prepend(jQuery('<span class="iconify mr-2" data-icon="mdi:delete"/>'));
  483. $btn_update.prepend(jQuery('<span class="iconify mr-2" data-icon="mdi:image-plus"/>'));
  484. }
  485. jQuery('#page__revisions .sizechange').addClass('label label-primary');
  486. jQuery('#page__revisions .sizechange.positive').addClass('label-success');
  487. jQuery('#page__revisions .sizechange.negative').addClass('label-danger');
  488. }
  489. // Media Manager (page)
  490. if ($media_manager.length) {
  491. var $sort_buttons = jQuery('.ui-buttonset');
  492. //$media_manager.find('.file dl').addClass('dl-horizontal');
  493. $media_manager.find('.file dd').addClass('pl-4');
  494. $media_manager.find('.panel').removeClass('panel').addClass('pull-left');
  495. $sort_buttons.addClass('btn-group');
  496. $sort_buttons.find('label').addClass('btn btn-xs btn-default');
  497. $sort_buttons.find('input').hide();
  498. function buttonHandler() {
  499. var $button = jQuery(this),
  500. option_for = $button.attr('for'),
  501. option_set = option_for.replace('sortBy__', '').replace('listType__', '');
  502. $sort_buttons.find('.active').removeClass('active');
  503. $button.addClass('active');
  504. $sort_buttons.find('#' + option_for).prop('checked', true);
  505. switch (option_set) {
  506. case 'thumbs':
  507. case 'rows':
  508. dw_mediamanager.set_fileview_list(option_set);
  509. $sort_buttons.find('[name=list_dwmedia]').val(option_set);
  510. break;
  511. case 'name':
  512. case 'date':
  513. dw_mediamanager.set_fileview_sort(option_set);
  514. $sort_buttons.find('[name=sort_dwmedia]').val(option_set);
  515. dw_mediamanager.list.call(jQuery('#dw__mediasearch')[0] || this, event);
  516. break;
  517. }
  518. }
  519. $sort_buttons.find('label').on('click', buttonHandler);
  520. }
  521. },
  522. detail: function () {
  523. var $detail_page = jQuery('#dokuwiki__detail'); // Detail Page node
  524. if (!$detail_page.length) return false;
  525. $detail_page.find('img.img_detail')
  526. .addClass('img-responsive');
  527. $detail_page.find('dl')
  528. .addClass('dl-horizontal');
  529. },
  530. tocResize: function () {
  531. var $dw_toc = jQuery('#dw__toc');
  532. if (!$dw_toc.length) return false;
  533. if (JSINFO.bootstrap3.config.tocAffix) {
  534. $dw_toc.affix('checkPosition');
  535. }
  536. jQuery('#dw__toc .toc-body > ul').css({
  537. 'max-height': (jQuery(window).height() - 50 - jQuery('#dokuwiki__content').position().top) + 'px',
  538. 'overflow-y': 'scroll'
  539. });
  540. jQuery('.toc-body').width(jQuery('.dw-toc').width());
  541. },
  542. tocClose: function () {
  543. var $dw_toc = jQuery('#dw__toc');
  544. if (!$dw_toc.length) return false;
  545. if (!$dw_toc.hasClass('affix-bottom')) {
  546. jQuery('.dw-content-page').addClass('dw-toc-closed');
  547. $dw_toc.find('.toc-body').collapse('hide');
  548. }
  549. },
  550. tocOpen: function () {
  551. var $dw_toc = jQuery('#dw__toc');
  552. if (!$dw_toc.length) return false;
  553. jQuery('.dw-content-page').removeClass('dw-toc-closed');
  554. $dw_toc.find('.toc-body').collapse('show');
  555. },
  556. // Table of Contents (Navbar)
  557. tocMenu: function () {
  558. if (!jQuery("#dw__toc_menu").length) return false;
  559. if (jQuery(JSINFO.bootstrap3.toc).length) {
  560. jQuery("#dw__toc_menu").removeClass("hide");
  561. }
  562. jQuery.each(JSINFO.bootstrap3.toc, function (idx, item) {
  563. var indent = "";
  564. if (item.level > 1) {
  565. for (var i = 0; i <= item.level; i++) {
  566. indent += "&nbsp;&nbsp;"
  567. }
  568. }
  569. jQuery("#dw__toc_menu ul").append(['<li><a class="small" href="', item.link, '">', indent, item.title, '</a></li>'].join(''));
  570. });
  571. },
  572. toc: function () {
  573. var $dw_toc = jQuery('#dw__toc');
  574. if (!$dw_toc.length) return false;
  575. // Set TOC Affix
  576. if (JSINFO.bootstrap3.config.tocAffix) {
  577. $dw_toc.affix({
  578. offset: {
  579. top: (jQuery("#dokuwiki__content").position().top),
  580. bottom: (jQuery(document).height() - jQuery("#dokuwiki__content").height()),
  581. }
  582. });
  583. }
  584. // ScrollSpy
  585. var scrollspy_target = '#dw__toc';
  586. if (JSINFO.bootstrap3.config.tocLayout == 'navbar') {
  587. scrollspy_target = '#dw__navbar_items';
  588. }
  589. jQuery('body').scrollspy({
  590. target: scrollspy_target,
  591. offset: ((parseInt(jQuery('body').css('marginTop')) || 0) + 10),
  592. });
  593. dw_template.tocResize();
  594. if (mediaSize('xs')) {
  595. dw_template.tocClose();
  596. }
  597. $dw_toc.css('backgroundColor', jQuery('article > .panel').css('backgroundColor'));
  598. $dw_toc.find('a').css('color', jQuery('body').css('color'));
  599. if (JSINFO.bootstrap3.config.tocCollapseOnScroll && JSINFO.bootstrap3.config.tocAffix) {
  600. $dw_toc.on('affix.bs.affix', function () {
  601. dw_template.tocClose();
  602. });
  603. if (!JSINFO.bootstrap3.config.tocCollapsed) {
  604. $dw_toc.on('affix-top.bs.affix', function () {
  605. dw_template.tocOpen();
  606. });
  607. }
  608. }
  609. $dw_toc.find('.toc-title').on('click', function () {
  610. jQuery('.dw-content-page').toggleClass('dw-toc-closed');
  611. if (jQuery('.dw-toc').hasClass('dw-toc-bootstrap')) {
  612. if (jQuery('.dw-content-page').hasClass('dw-toc-closed')) {
  613. jQuery('.dw-toc').removeClass('col-md-3');
  614. jQuery('.dw-content-page').removeClass('col-md-9').addClass('col-md-12');
  615. } else {
  616. jQuery('.dw-toc').addClass('col-md-3');
  617. jQuery('.dw-content-page').removeClass('col-md-12').addClass('col-md-9');
  618. dw_template.tocResize();
  619. }
  620. }
  621. if (!jQuery('.dw-toc-closed').length) {
  622. dw_template.tocResize();
  623. }
  624. });
  625. if ((jQuery(window).height() < $dw_toc.height())) {
  626. dw_template.tocResize();
  627. }
  628. },
  629. // Add typeahead support for quick seach
  630. typeahead: function () {
  631. jQuery("#qsearch").typeahead({
  632. source: function (query, process) {
  633. return jQuery.post(DOKU_BASE + 'lib/exe/ajax.php',
  634. {
  635. call: 'qsearch',
  636. q: encodeURI(query)
  637. },
  638. function (data) {
  639. var results = [];
  640. jQuery(data).find('a').each(function () {
  641. var page = jQuery(this);
  642. results.push({
  643. name: page.text(),
  644. href: page.attr('href'),
  645. title: page.attr('title'),
  646. category: page.attr('title').replace(/:/g, ' » '),
  647. });
  648. });
  649. return process(results);
  650. });
  651. },
  652. itemLink: function (item) {
  653. return item.href;
  654. },
  655. itemTitle: function (item) {
  656. return item.title;
  657. },
  658. followLinkOnSelect: true,
  659. autoSelect: false,
  660. items: 50,
  661. fitToElement: true,
  662. delay: 500,
  663. });
  664. },
  665. // Replace all OOTB DokuWiki toolbar icon with Material Design Icons
  666. toolbarIcons: function () {
  667. if (typeof window.toolbar === 'undefined') return false;
  668. if (!JSINFO.bootstrap3.config.useAlternativeToolbarIcons) return false;
  669. var icons = {
  670. 'bold.png': 'format-bold.svg',
  671. 'chars.png': 'omega.svg',
  672. 'h.png': 'format-header-pound.svg',
  673. 'h1.png': 'format-header-1.svg',
  674. 'hequal.png': 'format-header-equal.svg',
  675. 'hminus.png': 'format-header-decrease.svg',
  676. 'hplus.png': 'format-header-increase.svg',
  677. 'hr.png': 'minus.svg', // ??
  678. 'image.png': 'image.svg',
  679. 'italic.png': 'format-italic.svg',
  680. 'link.png': 'link.svg',
  681. 'linkextern.png': 'link-variant.svg', // ??
  682. 'mono.png': 'format-title.svg',
  683. 'ol.png': 'format-list-numbered.svg',
  684. 'sig.png': 'signature.svg',
  685. 'smiley.png': 'emoticon-outline.svg',
  686. 'strike.png': 'format-strikethrough.svg',
  687. 'ul.png': 'format-list-bulleted.svg',
  688. 'underline.png': 'format-underline.svg',
  689. };
  690. for (var i in window.toolbar) {
  691. // Replace all icons in "H(eaders)" picker
  692. if (window.toolbar[i].icon == 'h.png') {
  693. for (var x in window.toolbar[i].list) {
  694. var hn = parseInt(x) + 1;
  695. window.toolbar[i].list[x].icon = '../../tpl/bootstrap3/iconify.php?icon=mdi-format-header-' + hn + '.svg';
  696. }
  697. }
  698. for (var icon in icons) {
  699. if (window.toolbar[i].icon == icon) {
  700. window.toolbar[i].icon = '../../tpl/bootstrap3/iconify.php?icon=mdi-' + icons[icon];
  701. }
  702. }
  703. }
  704. },
  705. // Display confirm dialog on page restore action
  706. pageRestoreConfirm: function () {
  707. jQuery('li.action a.revert').on('click',
  708. function () {
  709. return confirm(LANG.restore_confirm);
  710. }
  711. );
  712. },
  713. menuitem: function () {
  714. jQuery('.menuitem.help').on('click', function () {
  715. var $self = jQuery(this);
  716. jQuery('.modal.help .modal-title').html($self.attr('title'));
  717. jQuery('.modal.help .modal-body').load($self.data('link'));
  718. });
  719. jQuery('.menuitem.printpage').on('click', function () {
  720. window.print();
  721. });
  722. },
  723. plugins: function () {
  724. /* DOKUWIKI:include js/plugins/csv.js */
  725. /* DOKUWIKI:include js/plugins/data.js */
  726. /* DOKUWIKI:include js/plugins/database2.js */
  727. /* DOKUWIKI:include js/plugins/datatables.js */
  728. /* DOKUWIKI:include js/plugins/davcal.js */
  729. /* DOKUWIKI:include js/plugins/discussion.js */
  730. /* DOKUWIKI:include js/plugins/explain.js */
  731. /* DOKUWIKI:include js/plugins/folded.js */
  732. /* DOKUWIKI:include js/plugins/gallery.js */
  733. /* DOKUWIKI:include js/plugins/include.js */
  734. /* DOKUWIKI:include js/plugins/inlinetoc.js */
  735. /* DOKUWIKI:include js/plugins/monthcal.js */
  736. /* DOKUWIKI:include js/plugins/move.js */
  737. /* DOKUWIKI:include js/plugins/overlay.js */
  738. /* DOKUWIKI:include js/plugins/plantuml.js */
  739. /* DOKUWIKI:include js/plugins/publish.js */
  740. /* DOKUWIKI:include js/plugins/semantic.js */
  741. /* DOKUWIKI:include js/plugins/simplenavi.js */
  742. /* DOKUWIKI:include js/plugins/struct.js */
  743. /* DOKUWIKI:include js/plugins/tabbox.js */
  744. /* DOKUWIKI:include js/plugins/tagalerts.js */
  745. /* DOKUWIKI:include js/plugins/tagging.js */
  746. /* DOKUWIKI:include js/plugins/translation.js */
  747. /* DOKUWIKI:include js/plugins/wrap.js */
  748. /* DOKUWIKI:include js/plugins/watchcycle.js */
  749. },
  750. };
  751. dw_template.toolbarIcons();
  752. dw_template.jQueryUI();
  753. jQuery(dw_template.init);