Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add collapseable blocks. closes #2678 #2760

Merged
merged 1 commit into from
Feb 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CHANGELOG - ZIKULA 1.4.x
- Add theme information to Symfony developer toolbar.
- Add functional login block to Bootstrap theme (#2730)
- Add support for 'account' type links in the LinkContainerCollector (#2758)
- Add collapseable blocks. This feature had disappeared since Core-1.3x (#2678)
- Core-2.0 Features:
- Add `currentUser` global variable to twig templates.
- Add (move) `Zikula\CategoriesModule\Entity\AbstractCategoryAssignment` and related documentation.
Expand Down
14 changes: 14 additions & 0 deletions src/docs/Core-2.0/CollapseableBlocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Collapseable Blocks
===================

In the BlocksModule settings, an admin may **enable block collapse icons**. This feature adds a small icon next to each
block title that when clicked will 'minimize' (collapse) the block. The icon can be clicked again to maximize or restore
the block.

The state of the collapse is maintained through javascript local storage and is only available on "modern" browsers.

Block developers should enclose **all** the block content in a block-level element (`<div>`, `<ul>` or similar) in order
to take full advantage of the feature.

Block developers can disable the "collapsibility" of a block by adding the `nonCollapsible` class to the Html element
that immediately follows the title element (likely the block-level element referenced above).
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<argument type="service" id="zikula_core.common.theme.assets_css" />
</service>

<service id="zikula_core.common.theme.asset_helper" scope="request" class="%zikula_core.common.theme.asset_helper.class%">
<service id="zikula_core.common.theme.asset_helper" class="%zikula_core.common.theme.asset_helper.class%">
<argument type="service" id="kernel" strict="false" />
<argument type="service" id="assets.packages" />
</service>
Expand Down
2 changes: 1 addition & 1 deletion src/system/BlocksModule/Block/HtmlBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function display(array $properties)
return '';
}

return $properties['content'];
return "<div>" . $properties['content'] . "</div>";
}

public function getFormClassName()
Expand Down
2 changes: 1 addition & 1 deletion src/system/BlocksModule/Block/TextBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function display(array $properties)
return '';
}

return nl2br($properties['content']);
return "<div>" . nl2br($properties['content']) . "</div>";
}

public function getFormClassName()
Expand Down
3 changes: 2 additions & 1 deletion src/system/BlocksModule/BlocksModuleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class BlocksModuleInstaller extends AbstractExtensionInstaller
'Zikula\BlocksModule\Entity\BlockEntity',
'Zikula\BlocksModule\Entity\BlockPositionEntity',
'Zikula\BlocksModule\Entity\BlockPlacementEntity',
'Zikula\BlocksModule\Entity\UserBlockEntity'
];

/**
Expand Down Expand Up @@ -141,6 +140,8 @@ public function upgrade($oldversion)
}
$this->entityManager->flush();
case '3.9.3':
$this->schemaTool->drop('Zikula\BlocksModule\Entity\UserBlockEntity');
case '3.9.4':
// future upgrade routines
}

Expand Down
2 changes: 1 addition & 1 deletion src/system/BlocksModule/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function configAction(Request $request)
}

$form = $this->createFormBuilder($this->getVars())
->add('collapseable', 'checkbox', ['label' => __('Enable menu collapse icons'),
->add('collapseable', 'checkbox', ['label' => __('Enable block collapse icons'),
'required' => false
])
->add('save', 'submit', ['label' => 'Save'])
Expand Down
49 changes: 0 additions & 49 deletions src/system/BlocksModule/Controller/UserController.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/system/BlocksModule/Entity/UserBlockEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/**
* UserBlock entity class.
*
* @deprecated remove at Core-2.0 (unused)
* @ORM\Entity
* @ORM\Table(name="userblocks",indexes={@ORM\Index(name="uid_bid_idx",columns={"uid","bid"})})
*/
Expand Down
61 changes: 61 additions & 0 deletions src/system/BlocksModule/Listener/CollapseableBlockListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright Zikula Foundation 2015 - Zikula Application Framework
*
* This work is contributed to the Zikula Foundation under one or more
* Contributor Agreements and licensed to You under the following license:
*
* @license GNU/LGPLv3 (or at your option, any later version).
*
* Please see the NOTICE file distributed with this source code for further
* information regarding copyright and licensing.
*/

namespace Zikula\BlocksModule\Listener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Zikula\Core\Theme\Asset;
use Zikula\Core\Theme\AssetBag;
use Zikula\ExtensionsModule\Api\VariableApi;

/**
* Class CollapseableBlockListener
* @package Zikula\BlocksModule\Listener
*/
class CollapseableBlockListener implements EventSubscriberInterface
{
private $jsAssetBag;
private $variableApi;
private $assetHelper;

public function __construct(AssetBag $jsAssetBag, VariableApi $variableApi, Asset $assetHelper)
{
$this->jsAssetBag = $jsAssetBag;
$this->variableApi = $variableApi;
$this->assetHelper = $assetHelper;
}

/**
* @param GetResponseEvent $event
*/
public function addCollapseableBehavior(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
if ($this->variableApi->get('ZikulaBlocksModule', 'collapseable')) {
$this->jsAssetBag->add($this->assetHelper->resolve('@ZikulaBlocksModule:js/Zikula.Blocks.Common.Minimizer.js'));
}
}

public static function getSubscribedEvents()
{
return array(
KernelEvents::REQUEST => array(
array('addCollapseableBehavior', 202),
),
);
}
}
8 changes: 8 additions & 0 deletions src/system/BlocksModule/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<parameter key="zikula_blocks_module.form.block_filter_type.class">Zikula\BlocksModule\Form\Type\BlockFilterType</parameter>
<parameter key="zikula_blocks_module.form.block_type.class">Zikula\BlocksModule\Form\Type\BlockType</parameter>
<parameter key="twig.extension.zikula_blocks_module.class">Zikula\BlocksModule\Twig\Extension\BlocksExtension</parameter>
<parameter key="zikula_blocks_module.listener.collapseable_block_listener.class">Zikula\BlocksModule\Listener\CollapseableBlockListener</parameter>
</parameters>

<services>
Expand Down Expand Up @@ -69,6 +70,13 @@
<tag name="twig.extension" />
</service>

<service id="zikula_blocks_module.listener.collapseable_block_listener" class="%zikula_blocks_module.listener.collapseable_block_listener.class%">
<argument type="service" id="zikula_core.common.theme.assets_js" />
<argument type="service" id="zikula_extensions_module.api.variable" />
<argument type="service" id="zikula_core.common.theme.asset_helper" />
<tag name="kernel.event_subscriber"/>
</service>

</services>

</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Javascript functions to minimize/hide and maximize/show a block when clicking on a small adjacent icon.
// Copyright Zikula Foundation 2016 - license GNU/LGPLv3 (or at your option, any later version).

(function($) {
$(document).ready(function() {
$('.z-block').children(':header').each(function() {
var nextElement = $(this).next();
if (!nextElement.hasClass('nonCollapsible') && nextElement.length > 0) {
var titleText = $(this).text();
var nextId, classes, icon;
if (typeof nextElement.attr('id') === "undefined") {
// create an id
nextId = titleText.replace(/([|!&;$%@"<>()+,])|(^\s*)|(\s*$)|( )/g, '').toLowerCase(); // strip all bad chars, spaces, make lowercase
nextElement.attr('id', nextId); // set the new id
} else {
nextId = nextElement.attr('id');
}
if (nextId && localStorage.getItem(nextId) === 'true' ) {
classes = "collapse";
icon = "expand";
} else {
classes = "collapse in";
icon = "compress";
}
nextElement.addClass(classes);
$(this).html(titleText + ' <a role="button" data-toggle="collapse" href="#' + nextId + '"><i class="fa fa-'+icon+' small block-expander"></i></a>');
}
});
$('.collapse').on('hide.bs.collapse', function() {
if (this.id) {
localStorage.setItem(this.id, 'true');
}
}).on('show.bs.collapse', function() {
if (this.id) {
localStorage.removeItem(this.id);
}
});
$('.block-expander').on('click', function() {
$(this).toggleClass("fa-compress fa-expand");
});
});
})(jQuery);
2 changes: 1 addition & 1 deletion src/system/BlocksModule/composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zikula/blocks-module",
"description": "Blocks Administration Module",
"version": "3.9.3",
"version": "3.9.4",
"type": "zikula-module",
"license": "LGPL-3.0+",
"authors": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>{{ pagevars.title }}</title>
<meta name="description" content="{{ pagevars.meta.description }}" />
<meta name="keywords" content="{{ pagevars.meta.keywords }}" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{{ pageAddAsset('stylesheet', zasset('@ZikulaBootstrapTheme:css/style.css')) }}
</head>
<body>