Skip to content

Commit f4c653e

Browse files
committed
Astroid now supports smooth scroll and one page template.
1. Adding smooth-scroll.polyfills.min.js to the js folder. 2. Option to enable smooth scroll and scroll speed from the Astroid backend. 3. If link type is a URL and starts with a # and has a ID, Adding JURI:root() in the beginning to make section work where one page sections would return to homepage from internal pages as well. 4. Added addScriptDeclaration function to Astroid Template.
1 parent d9a7a93 commit f4c653e

File tree

6 files changed

+47
-3
lines changed

6 files changed

+47
-3
lines changed

astroid/astroid-framework/framework/template.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,12 @@ public function addStyledeclaration($styles) {
765765
$document->addStyledeclaration($styles);
766766
}
767767
}
768+
769+
770+
public function addScriptDeclaration($script) {
771+
$document = JFactory::getDocument();
772+
$document->addScriptDeclaration($script);
773+
}
768774

769775
public function addScript($js) {
770776
$template_directory = JPATH_THEMES . "/" . $this->template . "/js/";

astroid/astroid-framework/language/en-GB/en-GB.astroid.ini

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,4 +807,11 @@ TPL_COLOR_TEAL="Teal"
807807
TPL_COLOR_CYAN="Cyan"
808808
TPL_COLOR_LIGHT_GRAY="Light Gray"
809809
TPL_COLOR_GRAY="Gray"
810-
TPL_COLOR_GRAY_DARK="Gray Dark"
810+
TPL_COLOR_GRAY_DARK="Gray Dark"
811+
812+
;Smooth Scroll
813+
TPL_SMOOTH_SCROLL_TITLE = "Smooth Scroll"
814+
TPL_SMOOTH_SCROLL_ENABLE_LBL = "Enable Smooth Scroll"
815+
TPL_SMOOTH_SCROLL_ENABLE_DESC = "Enabling will option load the necessary JS for smooth scroll."
816+
TPL_SMOOTH_SCROLL_SPEED_LBL = "Scroll Speed"
817+
TPL_SMOOTH_SCROLL_SPEED_DESC = "This a number representing the amount of time in milliseconds that it should take to scroll 1000px. Scroll distances shorter than that will take less time, and scroll distances longer than that will take more time. The default is 300ms."

astroid/astroid-template-zero/astroid/options/basic.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
<field type="astroidgroup" name="preloader_options" title="TPL_ASTROID_PRELOADER_MAIN_TITLE_LABEL"/>
77
<field type="astroidgroup" name="enable_back_to_top" title="TPL_ASTROID_ENABLE_TO_TOP_MAIN_TITLE_LABEL"/>
88
<field type="astroidgroup" name="layout_setting" title="TPL_ASTROID_LAYOUT_SETTING_MAIN_TITLE_LABEL"/>
9+
<field type="astroidgroup" name="smooth_scroll" title="TPL_SMOOTH_SCROLL_TITLE"/>
910

11+
<field astroidgroup="smooth_scroll" description="TPL_SMOOTH_SCROLL_ENABLE_DESC" name="enable_smooth_scroll" type="astroidtext" astroid-switch="true" default="0" label="TPL_SMOOTH_SCROLL_ENABLE_LBL"></field>
12+
<field ngShow="enable_smooth_scroll=='1'" astroidgroup="smooth_scroll" name="smooth_scroll_speed" type="astroidrange" astroid-scss-variable="spinkit-size" min="1" max="10000" step="1" default="300" label="TPL_SMOOTH_SCROLL_SPEED_LBL" description="TPL_SMOOTH_SCROLL_SPEED_DESC" postfix="ms" />
13+
1014
<field astroidgroup="preloader_options" description="TPL_ASTROID_BASIC_ENABLE_PRELOADER_DESC" name="preloader" type="astroidtext" astroid-switch="true" default="1" label="TPL_ASTROID_BASIC_ENABLE_PRELOADER_LABEL"></field>
11-
1215
<field astroidgroup="preloader_options" ngShow="preloader=='1'" description="TPL_ASTROID_PRELOADER_TYPE_DESC" name="preloder_setting" type="astroidradio" default="animations" label="TPL_ASTROID_PRELOADER_TYPE">
1316
<option value="animations">ASTROID_ANIMATION</option>
1417
<option value="image">TPL_ASTROID_IMAGE</option>

astroid/astroid-template-zero/frontend/header/menu/link.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@
9393
}
9494
?>
9595
<!--menu link starts-->
96+
<?php
97+
// One Page Coding Starts
98+
// Valid conditions
99+
// Must start with #
100+
// Length must be more than 1
101+
if($item->type == 'url'){
102+
// Let's search for #
103+
$validonepagelink = strpos($item->link,"#");
104+
if($validonepagelink == '0' && (strlen($item->link) > 1)){
105+
// Default we assume that you only want the one page for the homepage. If you want one page to work on other pages, please go ahead and hard code the full page URL i.e. https://yoursite.com/pageurl#onepageblockid
106+
$item->link = JURI::root().$item->link;
107+
}
108+
}
109+
?>
96110
<a href="<?php echo $item->flink; ?>" <?php echo implode(' ', $attr); ?>>
97111
<span class="nav-title">
98112
<?php if (!empty($options->icon)) { ?>

astroid/astroid-template-zero/index.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,19 @@
4949
if (!empty($favicon = $template->params->get('favicon', ''))) {
5050
$doc->addFavicon(JURI::root() . 'images/' . $favicon, '');
5151
}
52-
// Adding basic Scripts, jQuery & Bootstrap JS
52+
// Let's add the Smooth Scroll JD is enabled.
53+
$enable_smooth_scroll = $template->params->get('enable_smooth_scroll', '');
54+
if($enable_smooth_scroll == '1') {
55+
$smooth_scroll_speed = $template->params->get('smooth_scroll_speed', '');
56+
$template->loadTemplateJS('vendor/smooth-scroll.polyfills.min.js');
57+
$smoothashell = '
58+
var scroll = new SmoothScroll(\'a[href*="#"]\', {
59+
speed: '.$smooth_scroll_speed.'
60+
});
61+
';
62+
$template->addScriptDeclaration($smoothashell);
63+
}
64+
// Adding basic Scripts, jQuery & Bootstrap JS
5365

5466
if (isset($doc->_scripts[JURI::root(true) . '/media/jui/js/jquery.min.js'])) {
5567
$template->loadTemplateJS('vendor/jquery.easing.min.js,vendor/bootstrap/popper.min.js,vendor/bootstrap/bootstrap.min.js,vendor/jquery.astroidmobilemenu.js,vendor/jquery.jdmegamenu.js,vendor/jquery.offcanvas.js');

astroid/astroid-template-zero/js/vendor/smooth-scroll.polyfills.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)