Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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?

— asked April 21st 2010 by Zach Copley
  • desktop
  • include
  • includes
  • javascript
0 Comments

5 Answers

  • Titanium.include( path_to_js_file_relative_to_Resources_folder);

    — answered April 21st 2010 by Dan Tamas
    permalink
    0 Comments
  • 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); 
    }
    
    — answered April 21st 2010 by Martin Robinson
    permalink
    0 Comments
  • 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?

    — answered April 21st 2010 by Zach Copley
    permalink
    0 Comments
  • @Tamas Daniel:

    TypeError: Result of expression 'Titanium.include' [undefined] is not a function.

    — answered April 21st 2010 by Zach Copley
    permalink
    0 Comments
  • 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)

    — answered April 25th 2010 by Łukasz Korecki
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.