Is there a good 'include' mechanism?
I'm writing a Desktop app with a lot of JavaScript classes that I'd like to break out into multiple files. Is there any built-in mechanism in Titanium for including external .js files?
5 Answers
-
Titanium.include( path_to_js_file_relative_to_Resources_folder);
-
The easiest way is to roll your own:
function includeJavaScript(url) { var e = document.createElement("script"); e.src = url; e.type = "text/javascript"; document.getElementsByTagName("head")[0].appendChild(e); }
-
Titanium.include() doesn't seem to be documented.
https://developer.appcelerator.com/apidoc/desktop/1.0/Titanium
Is that just an oversight, or is it being removed/deprecated? Alternatively, is it a new method?
-
@Tamas Daniel:
TypeError: Result of expression 'Titanium.include' [undefined] is not a function.
-
I'm using haml to generate my static html used by the application.
Apart from typing less html - haml gives me the ability to use ruby and include all JS files in the resources dir like this:
%script{:src=>"libs/prototype.js", :type => "text/javascript"} - Dir["Resources/libs/**/*.js"].reject{|l| l=~ /scriptaculous|prototype/}.reverse.each do |file| %script{:src => file.sub("Resources/",""), :type => "text/javascript"} - Dir["Resources/**/*.js"].reject{|l| l=~ /libs|test|image/ }.sort.each do |file| %script{:src => file.sub("Resources/",""), :type => "text/javascript"}
(values in
reject
might depend on your project obviously)