Access filesystem using js within grails project - javascript

For learning purposes I created a toy project using grails.
In this project I would like to play an mp3 file in one of my views.
I found an html5/flash mp3 player. But when the music is supposed to play, I have a question.
The HTML 5 player is in the project/web-app/js folder. Everything else is in its normal place.
When I try to access a file, let's say "test.mp3" using just the name and extension of the file, where this file is supposed to be?

The file should be relative to whatever your current path is.
That is, if you're at
localhost:8080/myapp/test/test1, and you reference test.mp3, test.mp3 would have to be in the test1 directory. You can use absolute paths, such as /sounds/test.mp3 to reference from the root, but a better solution would be to use ${resource(...)} probably.
Here's the resource documentation.

Related

Set two separate xml view files to use the same code behind file

I have two Nativescript XML view files, one named test.xml and another named test-rtl.xml. I would like these views to share the same code behind file, for example test.js. Is this possible some how? I have heard in dev channels of the Page class containing a codeFile property but have not been able to find this property any where.
The answer by #dashman is the option you have.
Each page will have it's own page files(page.js, page.xml, page-view-model.js) What you can do is have both pages share the same model.js file. Create a shared folder and place the file in it. Just require it on the page you need it and bind it to the context and you are good to go.
You can find and example here: https://firebase.googleblog.com/2016/01/getting-started-with-nativescript-and_53.html
The user-view-model.js was used by both the login page and register page.
Each file will have it's own page file...but what you can do is have both pages connect to the same context file. Then you can build the bulk of the page logic in that file. From the xml file, you can callback directly into the model file (e.g. tap="{{ tapEvent }}").

How to reference javascript which is in the parent folder?

I have a web applictaion which use has the following folder structure
application_root
js
in the html, I refer the js like
<script src="../js/****"></script>
everything is file if I start the html page using file:///protocol, but when I use the web server, like http://loclahost:6000/application_root, I found the js cannot be loaded correctly.
How to solve this issue?
You need to start your path with /: <script src="/js/some.js"></script>
Anyway, this can be problematic because if you use a virtual directory, / won't work since it's the root path.
For example: /js/some.js is http://localhost/js/some.js, and if your web site is hosted in a virtual directory like http://localhost/myapp/js/some.js this approach won't work.
If you find above case part of your issue, you might need to use server-side code to get your application root (i.e. /myapp/) so you can concatenate /myapp/ to js/some.js and get the right URI.

Accessing Play Framework Template attributes from separate JS files

I am completely new to the Play Framework and don't consider myself too talented at front end development, so I was having a great deal of trouble with this...
I want to be able to have a button that changes an image's source back and forth. The images are rather large, so I was thinking of preloading the images in the Javascript, but in order to do that I have to access this Assets controller in order to grab the different images from the public images directory. The trouble is I am trying to keep everything neat and want to try to keep the Javascript (in my case I'm using Coffeescript) in separate files. The problem here is that I can't access this Assets controller from the Coffeescript (or any of the values passed from the Java to the template for that matter). So when I try to change the source of the image, it just gives me a 404.
There's a way in Play to create a global javascript object that has access to reverse routing for controllers, including Assets if you configure that. First read this page:
http://www.playframework.com/documentation/2.3.x/ScalaJavascriptRouting
After reading, set up your javascript routes to include this resource (see embedded router or router resource in docs):
routes.javascript.Assets.at
Then you'll be able to access assets throughout your javascript as follows:
console.log(jsRoutes);
console.log(jsRoutes.controllers.Assets.at("images/favicon.png").url);

Phonegap Use Intent / WebIntent to pick file

Please I am looking to use intent/webintent to open an app that can be used as a file browser/explorer for selecting audio files.
The URL(fullpath) for selected item would then be passed as source for in app media.play().
Any samples would be welcome.
Thanks.
Ismael.
You might check my plugin for Phonegap, which as I believe can do what you need.
https://github.com/markeeftb/FileOpener
All you gotta do is to pass a variable with the local path of the file:
window.plugins.fileOpener.open("file:///mnt.sdcard/Android/data/com.example.app")
You would only need to correct FileOpener.java file, so it matches file types you want to handle, for example mp3, wav etc.

How can I split my conkeror-rc config over multiple files?

Short version: can you help me fill in this code?
var conkeror_settings_dir = ".conkeror.mozdev.org/settings";
function load_all_js_files_in_dir (dir) {
var full_path = get_home_directory().appendRelativePath(dir);
// YOUR CODE HERE
}
load_all_js_files_in_dir(conkeror_settings_dir);
Background
I'm trying out Conkeror for web browsing. It's an emacs-like browser running on Mozilla's rendering engine, using javascript as configuration language (filling the role that elisp plays for emacs). In my emacs config, I have split my customizations into a series of files, where each file is a single unit of related options (for example, all my perl-related settings might be in perl-settings.el. All these settings files are loaded automatically by a function in my .emacs that simply loads every elisp file under my "settings" directory.
I am looking to structure my Conkeror config in the same way, with my main conkeror-rc file basically being a stub that loads all the js files under a certain directory relative to my home directory. Unfortunately, I am much less literate in javascript than I am in elisp, so I don't even know how to "source" a file.
I found a suitable answer, though it isn't really what I was looking for. If you set your conkerorrc file to a directory, then all the js files in that dir will be loaded.

Categories