Skip to content

Commit

Permalink
Merge pull request vufind-org#8 from samuli/navibar-with-css
Browse files Browse the repository at this point in the history
[ALLI-2174] Navibar (includes various CSS changes).
  • Loading branch information
EreMaijala committed Feb 16, 2015
2 parents 15b4e93 + 303d5a5 commit 762957a
Show file tree
Hide file tree
Showing 39 changed files with 9,785 additions and 315 deletions.
13 changes: 13 additions & 0 deletions local/config/finna/navibar.ini.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[search]
advanced_search = 'search-advanced'
browse = 'browse-home'
history = 'search-history'

[organisations]
organisations = 'content-organisations'

[about]
about = 'content-about'

[help]
help = 'content-help'
4 changes: 4 additions & 0 deletions local/config/vufind/navibar.ini.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
; Inherit main configuration
[Parent_Config]
relative_path = ../finna/navibar.ini

12 changes: 5 additions & 7 deletions module/Finna/src/Finna/View/Helper/Root/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,18 @@ public static function getRecord(ServiceManager $sm)
}

/**
* Construct the Header view helper.
* Construct the Navibar view helper.
*
* @param ServiceManager $sm Service manager.
*
* @return Header
* @return \Finna\View\Helper\Root\Navibar
*/
public static function getHeader(ServiceManager $sm)
public static function getNavibar(ServiceManager $sm)
{
$locator = $sm->getServiceLocator();
$translator = $locator->get('VuFind\Translator');
$menuConfig = $locator->get('VuFind\Config')->get('header-navigation');
$urlHelper = $sm->get('url');
$menuConfig = $locator->get('VuFind\Config')->get('navibar');

return new Header($menuConfig, $translator, $urlHelper);
return new Navibar($menuConfig);
}

/**
Expand Down
236 changes: 236 additions & 0 deletions module/Finna/src/Finna/View/Helper/Root/Navibar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
<?php
/**
* Navibar view helper
*
* PHP version 5
*
* Copyright (C) The National Library of Finland 2014.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package View_Helpers
* @author Samuli Sillanpää <samuli.sillanpaa@helsinki.fi>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org Main Site
*/
namespace Finna\View\Helper\Root;

/**
* Navibar view helper
*
* @category VuFind2
* @package View_Helpers
* @author Samuli Sillanpää <samuli.sillanpaa@helsinki.fi>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org Main Site
*/
class Navibar extends \Zend\View\Helper\AbstractHelper
{
/**
* Url view helper
*
* @var Zend\View\Helper\Url
*/
protected $urlHelper;

/**
* Menu configuration
*
* @var \Zend\Config\Config
*/
protected $config;

/**
* Menu items
*
* @var Array
*/
protected $menuItems;

/**
* Constructor
*
* @param Zend\Config\Config $config Menu configuration
* custom variables
*/
public function __construct(\Zend\Config\Config $config)
{
$this->config = $config;
}

/**
* Returns Navibar view helper.
*
* @return FInna\View\Helper\Root\Navibar
*/
public function __invoke()
{
if (!$this->menuItems) {
$this->urlHelper = $this->getView()->plugin('url');
$this->parseMenuConfig();
}
return $this;
}

/**
* Returns rendered navibar layout.
*
* @return string
*/
public function render()
{
return $this->getView()->render('navibar.phtml');
}

/**
* Returns menu items as an associative array where each item consists of:
* string $label Label (untranslated)
* string $url Url
* boolean $route True if url is a route name.
* False if url is a literal link.
* array $routeParams Route parameters as a key-value pairs.
*
* @return Array
*/
public function getMenuItems()
{
return $this->menuItems;
}

/**
* Constructs an url for a menu item that may be used in the template.
*
* @param array $data menu item configuration
*
* @return string
*/
public function getMenuItemUrl(Array $data)
{
if (!$data['route']) {
return $data['url'];
}

if (isset($data['routeParams'])) {
return $this->urlHelper->__invoke($data['url'], $data['routeParams']);
} else {
return $this->urlHelper->__invoke($data['url']);
}
}

/**
* Returns a url for changing the site language.
*
* The url is constructed by appending 'lng' query parameter
* to the current page url.
* Note: the returned url does not include possible hash (anchor),
* which is inserted on the client-side.
* /themes/finna/js/finna.js::initAnchorNavigationLinks
*
* @param string $lng Language code
*
* @return string
*/
public function getLanguageUrl($lng)
{
$url = $this->view->serverUrl(true);
$parts = parse_url($url);

$params = array();
if (isset($parts['query'])) {
parse_str($parts['query'], $params);
$url = substr($url, 0, strpos($url, '?'));
}
$params['lng'] = $lng;
$url .= '?' . http_build_query($params);
if (isset($parts['fragment'])) {
$url .= '#' . $parts['fragment'];
}
return $url;
}

/**
* Internal function for parsing menu configuration.
*
* @return void
*/
protected function parseMenuConfig()
{
$translator = $this->getView()->plugin('translate');

$parseUrl = function ($url) {
if (preg_match('/^(http|https):\/\//', $url)) {
// external url
return array('url' => $url, 'route' => false);
}

$data = array('route' => true);

$needle = 'content-';
if (($pos = strpos($url, $needle)) === 0) {
// Content pages do not have static routes, so we
// need to add required route parameters for url view helper.
$page = substr($url, $pos+strlen($needle));
$data['routeParams'] = array();
$data['routeParams']['page'] = $page;
$url = 'content-page';
}

$data['url'] = $url;
return $data;
};

$this->menuItems = array();
foreach ($this->config as $menuKey => $items) {
if ($menuKey === 'Parent_Config') {
continue;
}

if (!count($items)) {
continue;
}
$item = array(
'label' => "menu_$menuKey",
);

$desc = 'menu_' . $menuKey . '_desc';
if ($translator->translate($desc, array(), false) !== false) {
$item['desc'] = $desc;
}

$options = array();
foreach ($items as $itemKey => $action) {
if (!$action) {
continue;
}
$option = array_merge(
array('label' => "menu_$itemKey"),
$parseUrl($action)
);

$desc = 'menu_' . $itemKey . '_desc';
if ($translator->translate($desc, array(), false) !== false) {
$option['desc'] = $desc;
}
$options[] = $option;
}
if (empty($options)) {
continue;
} else {
$item['items'] = $options;
$this->menuItems[] = $item;
}
}
}
}
2 changes: 1 addition & 1 deletion themes/bootstrap3/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function ajaxLogin(form) {

$(document).ready(function() {
// support "jump menu" dropdown boxes
$('select.jumpMenu').change(function(){ $(this).closest('form').submit(); });
$('select.jumpMenu').change(function(){ $(this).parent('form').submit(); });

// Highlight previous links, grey out following
$('.backlink')
Expand Down
18 changes: 18 additions & 0 deletions themes/bootstrap3/js/vendor/slick.min.js

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions themes/bootstrap3/templates/Recommend/SideFacets.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,23 @@
<input type="hidden" name="<?=$this->escapeHtmlAttr($rangeFacets[$title]['type'])?>range[]" value="<?=$this->escapeHtmlAttr($title)?>"/>
<div class="row">
<? $extraInputAttribs = ($rangeFacets[$title]['type'] == 'date') ? 'maxlength="4" ' : ''; ?>
<div class="col-xs-12">
<span class="sr-only">
<div class="col-sm-6">
<label for="<?=$this->escapeHtmlAttr($title)?>from">
<?=$this->transEsc('date_from')?>
<?=$this->transEsc('date_from')?>:
</label>
</span>
<input type="text" class="form-control" name="<?=$this->escapeHtmlAttr($title)?>from" id="<?=$this->escapeHtmlAttr($title)?>from" value="<?=isset($rangeFacets[$title]['values'][0])?$this->escapeHtmlAttr($rangeFacets[$title]['values'][0]):''?>" <?=$extraInputAttribs?>/>
-
<span class="sr-only"><label for="<?=$this->escapeHtmlAttr($title)?>to">
<?=$this->transEsc('date_to')?>
</div>
<div class="col-sm-6">
<label for="<?=$this->escapeHtmlAttr($title)?>to">
<?=$this->transEsc('date_to')?>:
</label>
</span>
<input type="text" class="form-control" name="<?=$this->escapeHtmlAttr($title)?>to" id="<?=$this->escapeHtmlAttr($title)?>to" value="<?=isset($rangeFacets[$title]['values'][1])?$this->escapeHtmlAttr($rangeFacets[$title]['values'][1]):''?>" <?=$extraInputAttribs?>/>
</div>
</div>
<? if ($rangeFacets[$title]['type'] == 'date'): ?>
<div class="slider-container"><input type="text" class="hidden" id="<?=$this->escapeHtmlAttr($title)?><?=$this->escapeHtml($rangeFacets[$title]['type'])?>Slider"/></div>
<? endif; ?>
<input class="btn btn-default btn-primary" type="submit" value="<?=$this->transEsc('Set')?>"/>
<input class="btn btn-default" type="submit" value="<?=$this->transEsc('Set')?>"/>
</form>
</li>
<? if ($rangeFacets[$title]['type'] == 'date'): ?>
Expand Down
2 changes: 0 additions & 2 deletions themes/finna/css/compiled.css

Large diffs are not rendered by default.

8,085 changes: 8,083 additions & 2 deletions themes/finna/css/finna.css

Large diffs are not rendered by default.

0 comments on commit 762957a

Please sign in to comment.