We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Add custom JavaScript to mobile footer or header? | Forum

Marcus
Marcus Dec 25 '14
How can I add a custom JavaScript code to mobile header or just before </body> ????


ross Team
ross Dec 26 '14
You can add it directly in the master pages of the mobile version of the theme you currently use in the mobile_general.html file 
Marcus
Marcus Dec 26 '14
Thanks buddy but I get an error when I directly enter the code there!

<script>
$(document).ready(function(){
   
    //Check to see if the window is top if not then display button
    $(window).scroll(function(){
        if ($(this).scrollTop() > 100) {
            $('.scrollToTop').fadeIn();
        } else {
            $('.scrollToTop').fadeOut();
        }
    });
   
    //Click event to scroll to top
    $('.scrollToTop').click(function(){
        $('html, body').animate({scrollTop : 0},800);
        return false;
    });
   
});
</script>


"Syntax Error in template "C:\xampp2\htdocs\amigote\ow_themes\facebookthenext\mobile\master_pages\mobile_general.html" on line 54 "$('html, body').animate({scrollTop : 0},800);" - Unexpected " : ", expected one of: "}" , " " , ATTR"
Marcus
Marcus Dec 27 '14
Does anybody know how can I add a custom JavaScript to mobile version and don't get the error?
JoshWho
JoshWho Dec 27 '14
does this add it to them mobile plugin or just the them when u have mobile turned off?
The Forum post is edited by JoshWho Dec 27 '14
Marcus
Marcus Dec 28 '14
I am trying to add a "go to top" button to mobile version!

Buddy could you please rephrase your question? The error only shows on mobile version!
ross Team
ross Dec 28 '14
Topic was moved from General Questions.
Marcus
Marcus Dec 30 '14
Holy molly that works like a charm.

You should really make the forum so that users like me can add reputation or something to people who posted the solution!
AppXprt
AppXprt Aug 14 '18
This doesn't work anymore for Simplicity theme?

Adding a <script> to this file:

ow_themes/simplicity/mobile/master_pages/mobile_general.html

Does nothing for me...

AppXprt
AppXprt Aug 14 '18
Opps Nevermind... Cache...


So in these master pages I see you can do if statements and one is for isAuthenticated

What if I wanted to check useragent...

I've already added the needed useragent and code in mdetect.php, but where is isAuthenticated() defined and initialized?

I have a new function for the useragent I want to detect in mdetect.php

What language are these .html file in that allow for if statements and where are the variables set?

The Forum post is edited by AppXprt Aug 14 '18
dave Leader
dave Aug 14 '18
The if statements are probably smarty code.  Smarty is a template engine, all html is sent through smarty first which then parses it to the page.


If you want to dig into the code to see where stuff is initialized i would suggest you use a great tool called agent ransack, its free and it is a search utility.  You can search a whole script with it to find values.   Use it on var names to find what you want.  


To pass a var from the php file to the html file (smarty) you just use the assign function


so in the php file you would do something like this


//initialize the php var

if(!isset($var)) {  $var = ''; }


//then load the var with a value in php

$var = "somevalue";


//then pass it to smarty 

$this->assign("var",$var);   //format is  "smartyvar", $phpvar 


//then we load the value into html

//open the html file and put this 


<span>{$var}</span>    //wrapping it in {} indicates its a smarty var


done


hope that helps





The Forum post is edited by dave Aug 21 '18
AppXprt
AppXprt Aug 21 '18
Awesome! Loving smarty!
dave Leader
dave Aug 21 '18
Yep smarty is a good thing to learn, there are several template engines out there but smarty is the most common you will run into IMO, especially in open source.   


The issue is that even with its popularity smarty like all tools is slowly becoming a thing of the past and there are scripts out there that dont use it and scripts that have used it in the past and removed it.  
Its just one of those things, you love it or you hate it.  It might be around for 20 more years or gone tomorrow.  

dave Leader
dave Aug 21 '18
One more thing, if you want to use that same smarty var in JS rather than in html you just everything the same way with php but on the bottom of the html file you do:


{literal}

<script type="text/javascript">
"use strict";


var somevar = {/literal} '{$varname}' {literal};


</script>

{/literal}


and yes the close literal is put first, its not a typo.. 



The Forum post is edited by dave Aug 21 '18