Registering a Widget Javascript Dependency on Sitefinity - javascript

I'm trying to see if there is a way like Wordpress's enqueue script to properly include scripts onto the footer. I looked up the documentation, but all I could find was a way to do it for Widget Designers. I am looking for the ways to include the script properly and I'm using MVC.

I dug this up from the forums: http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/where-to-store-mvc-widget-css-and-javascript-and-how-to-link-it
You could also include the js reference in your master page, which I know isn't ideal if the widget isn't used on every page. You could always bundle and minify site wide scripts to reduce the overhead a bit.
You could also try using a the Sitefinity js widget on the page the widget is used, there is an option to refrence a file and include it before the closing body tag: http://www.sitefinity.com/documentation/documentationarticles/user-guide/widgets/scripts-and-styles-widgets-group/configuring-the-java-script-widget

Related

How to use script tags in a Gatsby blog post

I've just started moving my blog to Gatsby but have run in to a problem.
I have many markdown pages where I have javascript demos and I need to include the javascripts using <script src="..."> tags.
These don't seem to work which I'm guessing is because of the way Gatsby renders things.
Any ideas how I could make this work? It's going to be too much effort to go back and modify all these too much. They all require different versions of loads of different libraries.
For instance in one markdown post I need to include JQuery, part of three.js and two other scripts.
I did work out how to get the inline scripts working (https://stackoverflow.com/a/50336890/170239) but would be nice to be able to load externally too.

Custom JavaScript to existing Joomla core module

I have developed a custom Joomla template, and I need to add a piece of custom javascript to a Joomla core module (mod_articles_news), without a plugin, if possible (this should be so simple that I don't think I want to use a third party plugin for that). And async, if possible.
I have been searching thoroughly, but haven't found the perfect solution. Either they want me to install a plugin or the solution refers to a custom written module (suggesting to add JS before installation of module) while I am dealing with a core module (Articles Newsflash) that is already installed per definition. (The reason I need to use JS is to make a conditional design change, presently not possible with CSS).
I have been following the steps outlined here, but to no avail. Namely, I added the following code into the module's template folder (mod_articles_news/tmpl/my-template-name.php)
<?php
JHtml::script(Juri::base() . 'templates/my-template-name/js/myScript.js');
?>
(Of course, I have added the myScript.js file into the above location).
When checking it live, nothing happens, the browser is not loading my JavaScript at all (the script itself is tested and it works).
Please help me what I am missing here. Thank you in advance!
If you want to do customization you should use a Joomla! template for this. A template determines the basic HTML including the necessary CSS/JS for your site. In addition it can contain overrides for modules and components so you can do even more customization without touching any of the original code.
What you want to do sounds like a simple customization. Just add any CSS/JS which is necessary to achieve your task to the template.
You could try
<?php
JHTML::script('templates/my-template-name/js/myScript.js');
?>
alternatively, is there any reason you can't add it via your custom template, as suggested by Sven Bluege

What does the script tag do

Yo everyone. I am Admin's relative. Just a beginner in javascript. I would like to ask what is the following line, its purpose, what it does, where you put it and so on. My question might be simple but it would be really much appreciated if anyone can give good explanation to this question.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Thank you very much.
As you can see, this loading jQuery library from the CDN.
what is the following line
This will include jQuery library on your page
its purpose, what it does
As you might have read jQuery Tag WiKi on SO,
jQuery (Core) is a cross-browser JavaScript library (created by John Resig) which provides abstractions for common client-side tasks such as DOM traversal, DOM manipulation, event handling, animation and Ajax.
You might want to visit jQuery homepage.
jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. If you're new to jQuery, we recommend that you check out the jQuery Learning Center.
where you put it
You can put this in head or at the end of body tag. You just need to add this before any jQuery plugin.
I'll highly recommend you to take this tutorial.
This line loads jQuery, a javascript library (see http://jquery.com for details on jQuery), in to your page. It is customary to put it in the <head> tag of your page, and as you're just beginning I would recommend that.
There are some cases, however, where you want to optimize your page load time and it may be better to put it at the end of the <bod> tag, right before </body>. But for now I'd put it in the <head>.
The src tells the script tag where to load the file from. In this case, it's from a CDN (content delivery network) which hosts the files, and is used for slightly faster download times (not something you'll need to worry about at this point).
And welcome to stackoverflow!
This line is usually placed in the header section of a webpage, but can always be placed anywhere depending on your need.
What the code does is it loads the javascript codes found at the link, onto the page.
This avoids having lengthy javascript codes within your webpage.
It is a link to an external script. It basically copies and pastes the code from that location into the file where you write it. You usually put it at the top of the file where you need it.
<script> tag is used for importing a script. (can be java script or vbscript.)
jQuery is a framework for JavaScript.
So the line you mentioned is to invoke the jQuery script code in your code.
Now, you can do it in two ways, either download it, and then give the src, or use it from cdn. The src in this line is from the CDN. For more details of how to use jQuery, the minimal you can read is: this.
It will load the content of the external script file. In this way you can better organise your code and reuse code libraries in different projects.
It is best practise to load the script files last in order for the browser to load the html first.

How to add javascript loading (jQuery) for entire Liferay site or portal?

I want to use jQuery on many of my pages, including Web Content portlet. Is it possible to declare javascript files loading on all of the site pages?
I know this can be done in protlet declaration and in theme template.
But is it possible to do this globally?
You already mention the theme template (e.g. portal-normal.vm). In that file you have control over the full HTML skeletton, so it's easy to add the relevant script loader there and it's available on all pages that use the given theme.
That's as global as it gets. Do this to all of the themes you're using (are you using more than one?) and you're set. It's not more than a single line in that file.

Javascript/Markup in Assembly

I'm trying to somehow render out javascript for a particular user control rather than just having a script include for the javascript file.
The reason why I don't want a simple script include is because I need to append unique ClientID's to the dom elements at runtime.
I could hardcode the javascript in a function and just append the ClientIDs. However, this will look messy and I'm not liking the idea of hardcoding javascript code in a class- it would be a nightmare to maintain.
What are some strategies that I can use to keep javascript/markup separate from the compiled code? I want to somehow have the javascript source included in the assembly as well so that as a user control, it would not require manual script includes and have no other dependencies for it to work.
I used this code from Rick Strahl's blog. Works awesome with jQuery and those types of libraries. http://www.west-wind.com/WebLog/posts/252178.aspx
HTH,
ck
PS If you're using a Web Application Project you can use javascript files as embedded resources.

Categories