Skip to content

Commit

Permalink
Support svg pagetool icon, state depends on page selection via js/css
Browse files Browse the repository at this point in the history
svg has to path elements, selectable via a class
via javascript class is toggled
Fixes #104
  • Loading branch information
Klap-in committed Nov 1, 2017
1 parent e318c84 commit 7ab0b34
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 6 deletions.
41 changes: 41 additions & 0 deletions MenuItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace dokuwiki\plugin\bookcreator;

use dokuwiki\Menu\Item\AbstractItem;

/**
* Class MenuItem
*
* Implements the PDF export button for DokuWiki's menu system
*
* @package dokuwiki\plugin\bookcreator
*/
class MenuItem extends AbstractItem {

/** @var string do action for this plugin */
protected $type = 'plugin_bookcreator__addtobook';

/** @var string icon file */
protected $svg = __DIR__ . '/images/book-plusmin.svg';

/**
* MenuItem constructor.
*/
public function __construct() {
parent::__construct();
// global $REV;
// if($REV) $this->params['rev'] = $REV;
}

/**
* Get label from plugin language file
*
* @return string
*/
public function getLabel() {
$hlp = plugin_load('action', 'bookcreator_pagetools');
$jslocal = $hlp->getLang('js');
return $jslocal['btn_addtobook'];
}
}
11 changes: 11 additions & 0 deletions action/pagetools.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function register(Doku_Event_Handler $controller) {
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, '_extendJSINFO');
$controller->register_hook('TPL_ACTION_GET', 'BEFORE', $this, 'allowaddbutton');
$controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'addbutton');
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addsvgbutton', array());
}

/**
Expand Down Expand Up @@ -131,6 +132,16 @@ public function addbutton(Doku_Event $event, $param) {
}
}

/**
* Add 'export pdf' button to page tools, new SVG based mechanism
*
* @param Doku_Event $event
*/
public function addsvgbutton(Doku_Event $event) {
if($event->data['view'] != 'page') return;
array_splice($event->data['items'], -1, 0, [new \dokuwiki\plugin\bookcreator\MenuItem()]);
}

/**
* Check if user should see the tools at a page
*
Expand Down
1 change: 1 addition & 0 deletions images/book-plusmin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 19 additions & 6 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,32 @@ var Bookcreator = {
*/
updatePage: function() {

var $addtobookBtn = jQuery('.plugin_bookcreator_addtobook'),
var $addtobookBtn2 = jQuery('.plugin_bookcreator_addtobook'),
$addtobookBtn = jQuery('.plugin_bookcreator__addtobook'),
$bookbar = jQuery('.bookcreator__bookbar');

//pagetool add/remove button
$addtobookBtn.css( "display", "block");
if ($addtobookBtn.length) { //exists the addtobook link
/* TODO DEPRECATED 2017 */
$addtobookBtn2.css( "display", "block");
if ($addtobookBtn2.length) { //exists the addtobook link
var text = LANG.plugins.bookcreator['btn_' + (this.isCurrentPageSelected ? 'remove' : 'add') + 'tobook'];

$addtobookBtn
$addtobookBtn2
.toggleClass('remove', this.isCurrentPageSelected)
.attr('title', text)
.children('span').html(text);
}

//pagetool add/remove button
if ($addtobookBtn.length) { //exists the addtobook link
var text = LANG.plugins.bookcreator['btn_' + (this.isCurrentPageSelected ? 'remove' : 'add') + 'tobook'];

$addtobookBtn.find('a')
.toggleClass('remove', this.isCurrentPageSelected)
.attr('title', text).blur()
.children('span').html(text);
}

//bookbar with add/remove button
if(this.isBookbarVisible()) {
jQuery("#bookcreator__add").toggle(!this.isCurrentPageSelected);
Expand Down Expand Up @@ -718,9 +730,10 @@ jQuery(function () {

//bookbar buttons
jQuery('a.bookcreator__tglPgSelection').click(Bookcreator.clickAddRemoveButton);
//pagetool button
//pagetool button TODO DEPRECATED 2017
jQuery('.plugin_bookcreator_addtobook').click(Bookcreator.clickAddRemoveButton);

//pagetool button
jQuery('.plugin_bookcreator__addtobook').click(Bookcreator.clickAddRemoveButton);
//gui
Bookcreator.updatePage();
}
Expand Down
19 changes: 19 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ div.bookcreator__panel {
* Page tools
* show add/remove icon
*/

/* OLD BUTTONS DEPRECATED since 2017 */



#dokuwiki__pagetools ul li a.plugin_bookcreator_addtobook {
background-position: right -90px;
}
Expand Down Expand Up @@ -163,6 +168,20 @@ div.bookcreator__panel {
[dir=rtl] #dokuwiki__pagetools ul li a.plugin_bookcreator_addtobook.remove {
background-position: left -180px;
}

/* NEW SVG BUTTONS since 2017 */
/* svg has two paths, toggling depending on selection state of page */
#dokuwiki__pagetools div.tools ul li.plugin_bookcreator__addtobook a .bookmin {
display: none;
}

#dokuwiki__pagetools div.tools ul li.plugin_bookcreator__addtobook a.remove .bookplus {
display: none;
}
#dokuwiki__pagetools div.tools ul li.plugin_bookcreator__addtobook a.remove .bookmin {
display: block;
}

/**
* page add/remove button
*/
Expand Down

0 comments on commit 7ab0b34

Please sign in to comment.