cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

how to import javascript module?

Marble

how to import javascript module?

I made function ( like class )

 

Ex Code )

 

function ModelInfo(ModelName)
{
    this._ModelName = ModelName;
    this.ISModelLoaded = false;

    var ThisClass = this;

    // Check ModelLoaded 
    $scope.$on("modelLoaded"function(event,name)
    {
        ThisClass.LoadedModel(event,name);
    });

    this.LoadedModel = function(event,name)
    {
        if"modelLoaded" === event.name && name === this.ModelName )
        {
            this.ISModelLoaded = true;
        }
    }

    // More Function ( ChangeSequence , ChangeStep , ..... )
}

 

Use ModelInfo )

 
$scope.MainModel = new ModelInfo("model-1");

 

I Made Many Views

 

I must Copy ModelInfo Function when i make view 

 

Is there any other way?

 

like include in c++

 

 

 

 

 

 

 

8 REPLIES 8

Re: how to import javascript module?

Hi @wxywxy1 ,

you can  save your file as js file in the project directory (e.g. upload folder) and load it  from here as mention in  the post Include Java Script Dokuments

Re: how to import javascript module?

as further info  you can use some function as the exmaple below "loadjscssfile"

Here in the example I copied  both files /uploaded them (style.css and test.js)   to the Upload resource folder (app/resources/Uploaded)

Then I  used the following code for a  definition of function which should be called from e.g. from button or on modelload event.  The function will change the apperance of the widget Icon according to the definition of style.css /it will override a style definition)  and will load the test.js libary so that all funciton definition are afterwords available in my code. Also it could ovrride some available function definition if there is name confilict...


$rootScope.$on('modelLoaded', function()  {
$scope.testLoad();
});
...
$scope.testLoad= function()
{

  $scope.loadjscssfile("app/resources/Uploaded/style.css", "css")

 $scope.loadjscssfile("app/resources/Uploaded/test.js", "js")
}
//--------------------------------------------------------
//this is utility function to load the style or javaScript
//--------------------------------------------------------
$scope.loadjscssfile= function(filename, filetype){
    if (filetype=="js"){ //if filename is a external JavaScript file
        var fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype=="css"){ //if filename is an external CSS file
        var fileref=document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref!="undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}
...

  

Re: how to import javascript module?

Thank for Reply

 

Other Question

 

ex code )

 

$scope.loadjscssfile= function(filenamefiletype)
{
    if (filetype=="js"){ //if filename is a external JavaScript file
        var fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src"filename)
    }
    else if (filetype=="css"){ //if filename is an external CSS file
        var fileref=document.createElement("link")
        fileref.setAttribute("rel""stylesheet")
        fileref.setAttribute("type""text/css")
        fileref.setAttribute("href"filename)
    }
    if (typeof fileref!="undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

$scope.loadjscssfile("app/resources/Uploaded/common_util.js""js")
 
// ReferenceError: ModelInfo is not defined
$scope.MainModel = new ModelInfo(StudioId,$scope);
 
I want that $scope.MainModel is global variable and
I want that $scope.MainModel is defined before ModelLoaded
 
 
 
 

Re: how to import javascript module?

Yes, you do not need to load  the code in such event. I oftern use this because I wnat to ensure that all widget are already loaded. Often I use also :  $scope.$on('$ionicView.afterEnter', function() { ... or $scope.$on('$ionicView.beforeEnter', function() {...

but you can write simple your function as first  in the Home.js (or your <startView>>.js) and this will be loaded , I think early enough. At least, I do not find a reason why this should not be early enough

but... I think there is a file where you can specify  some libraries for loading :

<project folder>\extensions\runtimeExtensions.js

you can save a backup of this file and save your *.js file in the extensions/js folder and add it in the runtimeExtension.json file as runtimeLibaries.

I did not test this now but I could remember that I sued it one time in the past long time ago and it was working.

Highlighted

Re: how to import javascript module?

Thank for Reply

 

( runtimeExtensions.json File )

 

"runtimeFiles": [
    "extensions/js/common_util.js",
....
]
 
i run preview and vuforia remake runtimeExtensions.json file
 
The line disappears
 
Can i use javascript lib in vuforia?
 
must copy and copy ......
 

Re: how to import javascript module?

Hi @wxywxy1 ,

 

did you stop studio first? The overriding of the file happened when you change some of the studio setting but studio is still running. I think it should work so far, I remember but sure I could test it more deeply.

Could you suggest a sample library where I could test – just to be sure that this has a relevance for your case.

Re: how to import javascript module?

thank for replay

 

LoadModule.zip

 

Can you make sample ( as import runtimeLibaries ) , using LoadModule Source ?

 

 

 

Re: how to import javascript module?

I want to find a way.

 

Is this impossible?

Announcements
Topics available:
AR/VR for Data Optimization AR/VR for Security and Control AR/VR for Inspection