How to use minimized version of Ol3 library - javascript

I have a problem using the minimized version of OL3 library. It doesn't include the goog namespace. I do not know if it is not included in the js file or is the 'goog' namespace obfuscated.
But this part can be easily handled by just including Google closure library in a separate file. But after I do that I get another two errors:
NetworkError: 404 Not Found - http://localhost/my_test_app/apps/deps.js: should I include this file as well and if yes, should I include all other files from google closure library which this file tries to add dependencies to ?
ol.proj.Units is undefined: this one looks like obfuscated namespaces
And again it also looks like some namespaces were changed.
Shouldn't the namespaces, just like public methods, be kept unchanged in the obfuscated file ?
I tried to use the latest version of OL3: 3.8.2

You should not have to load the goog namespace in production, there is a good discussion with good example of how to create an OpenLayers3 control with plain javascript on the OL3 GitHub. https://github.com/openlayers/ol3/issues/3943
ol.proj.Units is not obfuscated, it is part of the public library. It's value is probably not initialized correctly in your application.

Related

ClojureScript-Lib and my ClojureScript on same page

Let's assume I have a small web-application and want to use a third-party library that comes with an already compiled version of a ClojureScript.
As a user of that library I have to include that generated Javascript file in my HTML page.
<script src="/javascript/gen/lib.js" type="text/javascript">
So far so good. Everything works fine.
But since my web-application needs some frontend-magic, I wanted to include some ClojureScript of my own. So I wrote a couple of lines, compiled it to Javascript and added another line in the HTML head:
<script src="/javascript/gen/lib.js" type="text/javascript">
<script src="/javascript/gen/my-stuff.js" type="text/javascript">
This is, where it gets ugly. I get this error in the javascript console:
Error: Namespace "goog.debug.Error" already declared.
After googling that error, I get multiple pages, that state, that I can not use multiple Google Closure Compiled things on one page. See SO: Multiple ClojureScript files on same page
So, how do I tackle that situation? On one hand I have an already Google Closure compiled lib and on the other hand my ClojureScript stuff. How do I get one (or two) compiled Javascript files out of this?
Would it be easier, if that third-party lib would provide a non-compiled ClojureScript version?
Yes, it would be easier if the third-party library would provide a non-compiled ClojureScript version. Then you would require it and use it from your code and compile everything together. The ClojureScript compiler with require each dependency once (even the shared dependencies) and the Google Closure compiler would do its optimization pass over all the code.
Try to find the library in Clojars or package it as a jar to consume it from your existing ClojureScript setup. (If the library is open source, give us a link and we'll help you out)

How to compile Haxe libraries to Javascript without enumerating every classes?

I'm trying to make use of a Haxe library in Javascript. Since I already have a project written in Javascript, porting that to Haxe + using the given Haxe library isn't really a solution I'm ready to take at the moment.
Is there a way I can just compile the library from it's Haxe source folder to a JS file that I can then include in my <script> tags and refer to in my project? If I'm not mistaking, when a Haxe project normally compiles, it only includes the classes actually used in your project (correct?) - therefore I need some kind of tool or compiler options that will include all the classes in a given directory.
I would assume packages will get namespaced into Javascript objects at that point.
In case this helps, the library I'm looking to transcompile is Nape (Physics engine written in Haxe).
Looks like I found a way!
From FlashDevelop, create a new Haxe project (for JS).
Then, add a reference to the library that you wish to compile, either by:
Finding it in your Haxe install directory/haxe/lib/name_of_library/version_of_library.
Or, simply by adding the library name in your project settings, under Libraries (as shown in the picture below).
Third (most important step), add --macro include('your_library_root_packagename') in the Additional Compiler Options (replace with your library's top-level package name, obviously!)
I believe that if you have a library consisting of many top-level packages, you would need to enumerate several of those --macro compiler options. In my case I just needed the one.
Finally, CTRL+ENTER... wait for it to transcompile and Voila!
You have a Library in Javascript format!

Untangling JS Source from Closure Compiler

There is a javascript application I would like to modify for my use*. The problem is, the js is compiled with Google Closure Compiler. Obviously, I should modify the sources (which are available in the repository), and re-compile.
This is my first encounter with GCC. I skimmed the documentation and came to the conclusion that the key is using the sources mentioned in deps.js via goog.addDependency keywords.
So I set up an HTML file and referenced all the sources. Loading this file I got 118 ReferenceError: goog is not defined errors in firebug console.
Then I read some more and found the app has been compiled with the help of kbuild, and that it uses a config file, config.kb, to send the right parameters to GCC. This file, indicates the first file should be loader.js, so I reordered the <script> tags and moved
<script type="text/javascript" src="./eightball/loader.js"></script>
to the top. but the same errors are thrown. So, what is missing?
* The license is MIT and there is no issue with the rights.
First, it would seem the application is using Google Closure, which is a JavaScript library developed by Google.
This is (of course), completely different to Google Closure Compiler, which is a JavaScript minification and obfuscation engine (dang these large companies and their quest to name everything the same).
That means you should include the Closure bootstrap before deps you've got listed; which is what the application itself does, as in the main view, it calls the game_js helper, which includes the base file of Closure if the application hasn't been compiled.
TLDR:
Try including the /javascripts/closure/closure/goog/base.js file first.

How do you attach JSdoc in Eclipse so that I can have autocomplete for a personal library

I have a JavaScript library that I am working on currently. I have structured it into lots of files and I use the module approach to define each 'module'.
var ns = generateNamespace("me.mycompany.mypackage.MyFile");
(function (ns, undefined) {
// some module
}(ns));
The modules are dynamically named using a namespacing function meaning that autocomplete is almost impossible as things stand (unless Eclipse can run my code and figure out the namespaces, Visual Studio can!).
Therefore I intend to generate JSdoc for my project in the hope that if I include this into Eclipse (somehow) Eclipse can use this to give me content assist.
Firstly I do not know if this is possible... however I think that it is as I can see that it is maybe how this works? However I tried to follow this along and struggled to get something working, by this I mean it didn't work. The interesting info from the link:
"JSDT libraries are collections of JavaScript source files that have prototyped object/class definitions and JSDoc. The inference engine then models these libraries... making them available to every JavaScript file in the project... Bindings for nonstandard and future runtimes are similarly easy to create... add the... library to their project and gain content completion and hover help"
I know how to write JSdoc annotations and I know how to generate JSdoc using one of the various tools.
What I need therefore is instructions on how to include JSdoc (as a library maybe) in Eclipse so that it will give auto complete for the stuff in the JSdoc.
Previous answer:
You can also run jsdoc_toolkit from within eclipse by setting up Run -
> External Tools -> Open External Tools Dialog...
Location
C:\Program Files\Java\jre1.5.0_12\bin\java.exe
Working Directory
C:\DirectoryToWhereJsDocToolkitIsLocated\jsdoc_toolkit
Arguments
-jar app/js.jar app/run.js -r=4 -t=templates/htm "-d=C:
\PathToWhereDocIsSaved" "C:\PathToWebsiteToDocument"
For more about the arguments check the jsdoc_toolkit documentation.
Have fun
Simon
Taken from this Google Groups thread.
Updated Answer:
Eclipse JavaScript Editor: content assist for js files, autocompletion
Disclaimer, I'm the author of tern.java.
I suggest you that you install tern.java. It provides a JSDoc support. Once you have selected this support, you can benefit
with completion :
and soon with validation:
This support is not perfect but it starts working.
I am not using it by myself, so I'm not sure if it works, but there exists a grunt-plugin for jsdoc3. Grunt is supported by Eclipse. So maybe it helps.
Grunt-PlugIn in npm

#required annotation in javascript files

I am at the starting point of trying to build a JavaScript library for our RIA application at work. Currently we have lots of JavaScript files with functions all in global scope and I would like to attempt to put some reasonable namespace and context to our functions. Possibly putting them into object form.
I've been looking at other open source libraries to help me understand the best way to build a library. I see a lot of .js files with the following in one particular open-source project.
/**
* #required OpenLayers/Map.js
*/
for example.
Does this have any meaning other than just being a comment in the file?
Is there some kind of way to import other .js files into your main build with this annotation or an import statement like in Java?
This code is using JsDoc (http://jsdoc.sourceforge.net/) or something similar to create documentation from the source code, most likely.
Javascript doesn't actually have annotations.
Choose RequireJS. It is a JavaScript file and module loader. It implements the CommonJS proposal.
It's a PHPDoc-style comment, telling anybody working with the code that it will not work properly without OpenLayers/Map.js
JavaDoc, the grandaddy of all code documentation/annotation systems for which all others (I think) are derived:
http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html

Categories

Resources