Skip to content

Commit

Permalink
Merge branch 'release/1.1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
denniserdmann committed Feb 26, 2021
2 parents b95b9cb + 8c90811 commit c8262a2
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 154 deletions.
202 changes: 106 additions & 96 deletions src/Modules/ModuleOnepageNavigation.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

/**
* @package Onepage Navigation
* @author Sascha Brandhoff (https://github.com/Sascha-Brandhoff/onepage-navigation)
* @author Basti Buck (http://www.bastibuck.de)
* @license LGPLv3
* @copyright Erdmann & Freunde (https://erdmann-freunde.de)
*/
<?php

declare(strict_types=1);

/*
* Contao Onepage Navigation for Contao Open Source CMS.
*
* @copyright Copyright (c) 2021, Erdmann & Freunde
* @author Erdmann & Freunde <https://erdmann-freunde.de>
* @license MIT
* @link http://github.com/erdmannfreunde/contao-onepage-navigation
*/

namespace EuF\OnepageNavigation\Modules;

Expand All @@ -16,98 +18,106 @@
class ModuleOnepageNavigation extends \Module
{
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_onepage_navigation';

* Template.
*
* @var string
*/
protected $strTemplate = 'mod_onepage_navigation';

/**
* Display a wildcard in the back end
* Display a wildcard in the back end.
*
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE')
{
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_wildcard');

$objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['onepage_navigation'][0]). ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;

return $objTemplate->parse();
}
return parent::generate();
}
public function generate()
{
if (TL_MODE === 'BE')
{
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_wildcard');

$objTemplate->wildcard = '### '.Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['onepage_navigation'][0]).' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id='.$this->id;

return $objTemplate->parse();
}

return parent::generate();
}

/**
* Generate the module
*/
protected function compile()
{
* Generate the module.
*/
protected function compile()
{
// initialize empty array
$arrNavigation = array();

// get current page id
$intPageID = $GLOBALS['objPage']->id;

// override page ID if a rootPage is defined
if($this->defineRoot) {
$PageID = \PageModel::findById($this->rootPage);
$PageAlias = $PageID->getFrontendUrl('');
$intPageID = $PageID->id;

} else {
$PageID = \PageModel::findById($intPageID);
$PageAlias = $PageID->getFrontendUrl('');
}

// get articles by page id
$objArticle = \ArticleModel::findByPid($intPageID, array('order' => 'sorting'));

// put articles into array if they should be displayed as navigation items
while($objArticle->next())
{
if($objArticle->addNavigation && $objArticle->published)
{
if($objArticle->navigation_title)
{
$objArticle->title = $objArticle->navigation_title;
}

// get jumpTo target and add to article so it can be rendered in template
$cssID = \StringUtil::deserialize($objArticle->cssID);

if (empty($cssID[0]))
{
if($objArticle->navigation_jumpTo) {
$cssID = array($objArticle->navigation_jumpTo, $cssID[1]);
}
else {
$cssID = array('article-'.$objArticle->id, $cssID[1]);
}
}
$objArticle->cssID = serialize($cssID);
$objArticle->onepage_jump = $PageAlias.'#'.$cssID[0];

$arrNavigation[] = (object) $objArticle->row();
}
}

if($arrNavigation) {
// add first and last class to items
$arrNavigation[0]->css = 'first';
$arrNavigation[count($arrNavigation) - 1]->css = 'last';

// send to template
$this->Template->hasItems = true;
$this->Template->navigation = $arrNavigation;
}

}
$arrNavigation = [];

// get current page id
$intPageID = $GLOBALS['objPage']->id;

// override page ID if a rootPage is defined
if ($this->defineRoot)
{
$PageID = \PageModel::findById($this->rootPage);
$PageAlias = $PageID->getFrontendUrl('');
$intPageID = $PageID->id;
}
else
{
$PageID = \PageModel::findById($intPageID);
$PageAlias = $PageID->getFrontendUrl('');
}

// get articles by page id
$objArticle = \ArticleModel::findByPid($intPageID, ['order' => 'sorting']);

if (null !== $objArticle)
{
// put articles into array if they should be displayed as navigation items
while ($objArticle->next())
{
if ($objArticle->addNavigation && $objArticle->published)
{
if ($objArticle->navigation_title)
{
$objArticle->title = $objArticle->navigation_title;
}

// get jumpTo target and add to article so it can be rendered in template
$cssID = \StringUtil::deserialize($objArticle->cssID);

if (empty($cssID[0]))
{
if ($objArticle->navigation_jumpTo)
{
$cssID = [$objArticle->navigation_jumpTo, $cssID[1]];
}
else
{
$cssID = ['article-'.$objArticle->id, $cssID[1]];
}
}
$objArticle->cssID = serialize($cssID);
$objArticle->onepage_jump = $PageAlias.'#'.$cssID[0];

$arrNavigation[] = (object) $objArticle->row();
}
}
}

if ($arrNavigation)
{
// add first and last class to items
$arrNavigation[0]->css = 'first';
$arrNavigation[\count($arrNavigation) - 1]->css = 'last';

// send to template
$this->Template->hasItems = true;
$this->Template->navigation = $arrNavigation;
}
}
}
108 changes: 50 additions & 58 deletions src/Resources/contao/templates/j_onepage_navigation.html5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script src="/bundles/eufonepagenavigation/jquery.waypoints.js"></script>
<script>
$(document).ready(function() {
var el = $('a[href*="#"]').not('[href="#"]').not('[href="#0"]');
var scrollSpeed = 800;
var uri = window.location.href.split("#")[0];
var el = $('a[href*="#"]').not('[href="#"]').not('[href="#0"]');
var scrollSpeed = 800;
var uri = window.location.href.split("#")[0];

el.click(function(event) {
// check if On-page links
if (
Expand All @@ -22,66 +22,58 @@ $(document).ready(function() {
$('html, body').animate({
scrollTop: target.offset().top
}, scrollSpeed);
history.pushState("", "", uri + this.hash);
}
}
});

// set nav active when scrolling
var navActive = function(section) {
var $el = $('.onepage_navigation__list');

$el.find('li.active').removeClass('active');
$el.each(function(){
$(this).find('a[data-onepagelink="'+section+'"]').parent().addClass('active');
});
};
var navActive = function(section) {
var $el = $('.onepage_navigation__list');

$el.find('li.active').removeClass('active');
$el.each(function(){
$(this).find('a[data-onepagelink="'+section+'"]').parent().addClass('active');
});
};

var navigationSection = function() {
var $section = $('.mod_article');

$section.waypoint(function(direction) {

if (direction === 'down') {
if($(this.element).hasClass('onepage_article')) {
// change url to active link
navActive(this.element.id);
}
}
}, {
offset: '50%'
});

var navigationSection = function() {
var $section = $('.mod_article');

$section.waypoint(function(direction) {

if (direction === 'down') {
if($(this.element).hasClass('onepage_article')) {
// change url to active link
navActive(this.element.id);

// change url to active link
if (typeof(window.history.pushState) == 'function') {
history.pushState("", "", uri + '#' + this.element.id);
}
}
}
}, {
offset: '50%'
});
$section.waypoint(function(direction) {

if (direction === 'up') {
var previousWaypoint = this.previous();

if($(this.element).hasClass('onepage_article')) {
// change url to active link
navActive(this.element.id);
}
}

}, {
offset: function() {
return (this.context.innerHeight()/2) - this.element.offsetHeight; // offset 50% from bottom
},
group: $section
});
};

$(function(){
navigationSection();
});

$section.waypoint(function(direction) {

if (direction === 'up') {
var previousWaypoint = this.previous();

if($(this.element).hasClass('onepage_article')) {
// change url to active link
navActive(this.element.id);
history.pushState("", "", uri + '#' + this.element.id);
} else {
navActive(previousWaypoint.element.id);
history.pushState("", "", uri + '#' + previousWaypoint.element.id);
}
}

}, {
offset: function() {
return (this.context.innerHeight()/2) - this.element.offsetHeight; // offset 50% from bottom
},
group: $section
});
};

$(function(){
navigationSection();
});

});
</script>

0 comments on commit c8262a2

Please sign in to comment.