getting intellisense in Visual Studio 2010 in Javascript files - javascript

When you enter Javascript in an HTML file, you get intellisense code completion based on the Javascript files you have linked into the head of your HTML file.
I know there is a way to add comments with JS filenames into the top of a Javascript file, so that VS2010 will reference these files as you type code into the rest of the file below.
How does one do that? Or can you point me to a reference that describes the syntax?
Thanks much.

/// <reference path="ScriptFile1.js" />
See the References Directives section - http://msdn.microsoft.com/en-us/library/bb385682.aspx

Related

No intellisense in javascript (*.js) file when using T4MvcJs

I have started using T4MvcJs in my project recently. The problem I am facing is that, I am unable to use Intellisense feature in my javascript file (.js) when using T4MvcJs (generated strongly-typed) URLs, and I have to type precisely all strongly typed URLs without intellisense. Note that, javascript (.js) file is separately maintained from its razor view file (*.cshtml). This is making the usage of T4MvcJs very difficult.
Please guide, whether intellisense feature is available in T4MvcJs or not? If availble, kindly guide how to enable/use it?
For example: The url in my javascript file w/o using T4MvcJs is declared as
var _url = "/Home/Index"
Kindly guide, how can I write the above url using T4MvcJs in my javascript (*.js) file. Also explain, how to achieve it using intellisense.
Application Plateform: C# + MVC4 , VS 2013
If you have a script folder in your application put the jQuery file in that folder and create another script in that folder name it _references.js
in the references.js
add this code
/// <reference path="The name of jQuery file you want to reference if its in the same folder" />
if you cannot keep the jQuery file in your folder then give the appropriate path
of the jQuery file that is located and the intellisense of the jQuery file will be available to you.
This works for me whenever I add a new nugget package I add the reference path in the references jscript file give it a try and let us know

Revert JavaScript minification using source map

Is it possible to get a proper JavaScript source file if I have the minified file and its corresponding source map?
I know how to prettify JS code (line-breaks and indents), but I would like to get original function / variable names in the file, to be able to better understand the source code.
I would like to get the un-minified JS file to work with, instead of using it to debug in a browser.
PS It is probably somewhere right under my nose, but I didn't manage to find it so far. Sorry if this was already asked!
To work sourcemaps requires both files, minified and original, often original is included in sourcemap file(it has optional sourcesContent for sources that can not be hosted).
Sourcemap is just JSON file, and you can found all needed information inside:
sources - list of source file names,
sourcesContent - optional list
of original sources, if source is not presented it would be null
here.
Utility script, I have written before for this purpose: https://gist.github.com/zxbodya/ca6fb758259f6a077de7
I suggest using the Source Map Visualization tool online to view the original code with both js file and js soucemap file.
https://sokra.github.io/source-map-visualization/
I think you won't be able to completely revert such code to its original state as a lot of information (for example comments or certain variable names) is simply lost in the process. When I understand it correctly for sourcemaps to do this you still need the original file.
If you only aim to prettify the code so its readable again you do not need source maps. Many advanced editors have such functions. For example if you are using Sublime text there is this plugin: https://packagecontrol.io/packages/HTML-CSS-JS%20Prettify which does a great job.
Also see this similar question: How can I debug a minified JS in firebug?

ExpressionEngine, I would like to add a JS file to a template

For one of my clients I need to update the website. Therefore I would like to add a JS file.
So I have never worked with ExpressionEngine before, so I downloaded the Core Version.
On my laptop I would now like to add to the theme "agile_records" (seems to be the standard theme) a js file. I saw there is a folder: /themes/site_themes/agile_records/js
there I have copied the js file.
Next I have put a new line in the following file:
themes/site_themes/agile_records/global_variables/js
but unfortunately when I look into the source code of safari, my js file has not been included, not even the new line I have added to the file above.
Can anyone help me out, how I can add this JS to the template?
cheers
You should be able to just add it with a script tag. Try something like <script src="/js/filename"></script>.
This obviously assumes that agile_records is the root of the project.

nXhtml (No javascript-mode/eruby-javascript)

I've just installed nXhtml by downloading their zip file, extracting the archive into my home directory and adding (load "/home/spinlock/nxhtml/autostart.el") to my .emacs file. My problem is that when I try to edit a .js.erb file, I'm getting the error:
(No javascript-mode/eruby-javascript)
and I'm not getting the syntax highlighting that I'd expect (for instance, comments are the same color as javascript code). However, when I move the cursor inside a Ruby section of this file, that notice changes to:
(Ruby/eruby-javascript)
which I take as a good sign plus it does look like I've got the proper Ruby syntax highlighting in this part of the buffer (e.g. comments are show in red font).
I assume that I need to add a configuration file that tells emacs how to manage javascript-mode but I have no clue how to do this. Any help would be greatly appreciated.
Thanks!

How to reference multiple files for javascript IntelliSense in VS2010

I have large solution with about 40 separate javascript files, which are referenced to web page via special js-service. I want to use new IntelliSense features in VS2010, but it is very hard to add about 40 individual references like this:
/// <reference path="../../lib/jquery-1.3.2.js" />
to each js file in solution. Maybe there is some way to reference all files in folder? I've tried something like this:
/// <reference path="../../lib/*.*" />
but it is not working...
Thanks.
Update:
Maybe there are some add-in, which could help with this?
Add the references to one js file, ideally one that all the others rely on or use. Then everywhere else, include a reference to just that one js file.
ie, file1.js contains:
/// <reference path="file2.js" />
/// <reference path="file3.js" />
...
/// <reference path="file40.js" />
And every other file contains just one reference:
/// <reference path="file1.js" />
Update for Visual Studio 2012: You can now put global references in the _references.js file so that intellisense is available automatically in other js files. You can also specify intellisense files in the tools dialog under "Tools" > "Options" > "Text Editor" > "JavaScript" > "Intellisense" > "References".
More detail in this blog post: JavaScript Intellisense in VS 2012, The _references.js File
You can select a bunch of them in Solution Explorer and drag them onto the editor of the JS file you want to use Intellisense.
It will automatically generate the /// tags based on the file you dragged.
It is very important that the ///... lines come before ANYTHING ELSE in your js file. There must not even be a blank line.
Then all should work fine.
I am using VS2010, have the same problem as user512395.
It used to work for me with the chosen answer.
I have upgraded to latest Resharper that comes with Javascript intellisense support recently.
And I had the same problem with my website, but the update helped. And don't forget the blank lines, there shouldn't be any!

Categories