How to integrate an external javascript file into PugJS? - javascript

I'm trying to make a web application using Node.js and Express and PugJS as a template engine.
My problem: I'm using a google maps API and I want to code all my google maps API functions into a separate javascript file. I can't figure out how to render this external javascript file in the pugJS page and call to functions from the external js file.

Thats pretty easy; you should use the tag script, like follows;
// jquery as an example, include your own script
script(src='/assets/plugins/jquery/jquery.min.js')
script.
// call your functions here
$(function () {
alert('hey')
})

Related

JavaScript in IntelliJ rest client

I have read most if not all of the documentation JetBrains provides about their HTTP Client and how to create requests using files with .http extension.
My problem is that I want to use a function in a different .js file inside one of the .http request files. The way they explain how this can be achieved is with this 1 liner "For external scripts, you need to enable it manually." The problem is they don't explain how you do the manual part. I did find that you have add any custom js code/library via Settings-> Languages and Frameworks -> JavaScript -> Libraries.
So my question is if anyone knows how to import custom JavaScript in a different location in a .http file? My JavaScript function is written in this manner:
export default function writeResponse(response, client) { ... }
For external scripts, you need to enable it manually
This quote from the docs is about enabling code assistance for external script, not about importing and exporting functions from scripts.
For your scenario, please try load(), for example:
### Import a function check() from a script new.js
GET http://example.org
> {%
load('/Users/YourPathToScript/scripts/new.js');
check();
%}

Use external multi modal JavaScript

I would like to utilize the external multi modal Github script in meteor to run with bootstrap modals taken from a meteor bootstrap package I have installed on my app. There is no meteor package for this. I'm using the $.getScript() jQuery function to get the source JS file. It is set up like such:
Meteor.startup( function () {
$.getScript("https://cdn.rawgit.com/ngzhian/multi-step-modal/master/multi-step-modal.js");
});
Unfortunately when I include this, the file from the URL gets loaded but the modal functionality doesn't work. I believe that all the HTML is correct. Is there an alternative way to include third party libraries? Could the library possibly be broken?
Meteor.startup( function ()
{
$.getScript("https://cdn.rawgit.com/ngzhian/multi-step-modal/master/multi-step-modal.js",function()
{
// Here the script is loaded and you can use it's functions
});
});

Awesomium: Include external javascript

I'm trying to use functions from external javascript files which are included in my html page with the "script" tag.
Javascript functions which are implemented directly in the html page seem to work without problems but the functions from the external javascript files aren't executed.
Is there a way to get these functions working?
If you want to load an external resource as for example a JavaScript file you need to intercept the call using a ResourceInterceptor and inject your file into the response.

Accessing data from Google App Engine datastore in a javascript file

What are the options for accessing information from Google App Engine datastore in a javascript file?
BACKGROUND:
I am running an app on Google App Engine which uses the Google Chart Tools API. All the data which I would like to graph is in my Google App Engine datastore.
WHAT I'VE TRIED
I can access the data within my python script. Also, in the python script, I encode the data to JSON. My idea was to save this in a js file, which I could import into the HTML, then build the chart there. However, this does not work, because writing to local files is not supported in App Engine.
On App Engine you typically generate an HTML page that you serve to a client. You don't need to save your JSON to a js file, you can embed it directly as text into your HTML page that you serve to your client.
You can use something like Jersey to create a REST api for the backend. It's a bit of work. You can also make a GWT application with the appengine project, which has really extremely easy backend hookups. Then you can interface this with your javascript application or have hooks that your javascript application can use.
XMLHttpRequest
From the python file: Write the JSON data to a URL.
In App Engine, this is done with
self.response.write(data)
From the Javascript, make the XHR request like this:
function getData() {
var dataObject = new XMLHttpRequest();
dataObject.open('GET', 'URL', true);
dataObject.send();
return dataObject;
}
This will return a XMLHttpRequest object with the data in a string in the response or responseText attribute.

Include google api version in a javascript file

I am developing an html/javascript application and want to build a single file containing both HTML and javascript code.
Is there a way to include google-map api in the same file without using a script tag ?
Thanks,
Benoit
Yes - it's called loading asynchronously: https://developers.google.com/maps/documentation/javascript/tutorial#asynch
We need to add script tag to access google map.
There's also a Google Static Maps API that simply creates imagery. It's non-interactive but works without JavaScript:
https://developers.google.com/maps/documentation/staticmaps/

Categories

Resources