Eclipse - Highlight javascript in .phtml file - javascript

Is there any way to highlight javascript syntax by eclipse (pdt) in a phtml file? Currently it only shows black text.
Thanks!

Problem is that phtml files are by default opened in the php editor, and that one doesn't have javascript highlighting.
You could open your phtml file in the html editor or even the javascript editor (right-click the file from the navigator in eclipse, select "open with" and then the editor type you want (obviously you must have the html/js editor installed in eclipse but you most likely will have that). Then, of course, you loose the php highlighting. You can specify the other editor type as default in the settings (if you really want to).
The correct solution though is not to use javascript in your html (or phtml) files (or only the very bare minimum). Put it in a separate .js file, and syntax highlighting will work perfectly!

Related

atom.io : Open Files via Clickable Links within Javascript Comments

Is there way, in Atom, to open files that are mentioned in comments?
When I edit a code file, there are often other code files of interest that I may want to also open while working on that file. Sometimes these reference files are miles away and require numerous steps of navigation to open them via the left-pane tree structure.
I was thinking, it would be nice if I could put relative file paths into javascript comments in a manner that atom would understand that if I click that path it should open that file in a new tab.
I suspect this isn't an original idea, so I'm hoping someone can direct me to a solution that enables this type of functionality or make me aware of how it is already enabled but I must use some syntax I'm not currently using.
I found open-project-file and it seems like a nice fit.
Update: I tested it and it works great! You just click on the relative path (whether it is located in code or comment) and by hitting ctrl-shift-o it immediately opens the file in a new tab within the atom editor.

How do I debug JSP-embedded JavaScript in FireFox debugger?

I am using the FireFox debugger to debug an app that contains both .JSP files and .js include files. The debugger lets me put break points in the .js files, but NOT in the JavaScript/JQuery that is in the .JSP files that call the .js files. Debugging is not entirely useful unless I can put breakpoints in ALL the files that contain JavaScript and JQuery code, no matter what file extension is attached to each file.
How can I get FireFox to include the relevant JSP files in the list of files to which break points can be added?
For example, the file somejsp.jsp contains the following script element:
<script language="javascript">
function someMethod(someArgument) {
document.forms['someForm'].elements['someElement'].value = some.element;
//some other JavaScript code
}
</script>
Rest of JSP file...
If I take #charlietfl's suggestion and add the debugger command, where and how do I add it?
I made a first attempt to write it as follows:
debugger document.forms['someForm'].elements['someElement'].value = some.element;
But when I try to run the code, the browser gives an error alert saying that someMethod() has not been implemented. So it seems that adding the word debugger in the way shown above causes the method to become invisible to FireFox. How can I correctly add the breakpoint?
This can be achieved in Chrome browser.
You need to enable the below setting in DevTools first:
Navigate to Settings > Preferences
Check Search in anonymous and content scripts under Sources section
Now Navigate to your page as usual, right-click and open DevTools. Select Search tab at the lower part of the DevTools window and enter keywords specific to the text in the JavaScript code that you're trying to search.

Copy a Javascript datepicker

I would like to copy a Javascript datepicker (calender) from one app to another. But I could not do that. If i save the original app page(the site from where I would like to copy) the datepicker is not working (peculiar). Even I copy pasete the html and css code also but I am not getting the javascript datepicker. What can be the solution?
Try looking at the page source. Download necessory .js files, .css files into your folder / directory. Also copy relevant JavaScript, CSS and HTML from the page. Then compile another html file in that directory using downloaded files and copied scrips. This should work.

Configure Eclipse to use Javascript editor

When editing JSPs in Eclipse, the contents of <script> tags - i.e. Javascript code - is properly color coded and formated.
For reasons that go beyond the scope of this question, I have created a custom javascript tag, let's call it <sj:script>. The body of this type is pure javascript as you would have in a regular <script> tag.
However, when I have Javascript code within my custom tag, it is treated as simple text (no color coding, no proper indentation, etc).
My question is, how do I make Eclipse use a specific editor within custom JSP tags?
You can try MyEclipse or Aptana Studio. They offer much better editors for web development.
But a much better approach is to put the JS into a different file and reference that with <script src="...">:
You can use a better editor
The browser can cache the JavaScript (instead of downloading it every time with the rest of the page)
You can write tests for the JavaScript (next to impossible when the JS is held hostage in a JSP file).
[EDIT] Eclipse is open source. Download the code for the WTP project, look for the text editor parts and search for "script". In all places that you find, add "sj:script", too.
Have you included the Tag Library Descriptor file in the jsp where you are using the custom tag?
I have a list of plugins for eclipse which enable eclipse to edit JS files:
http://www.delicious.com/powtac/javascript+eclipse
Just go trough the links and see the different descriptions how to install them.
AFAIK, editors are chosen based on file extension, and there's no mechanism to customize this based on particular content inside the file.
I see 2 options
Creating a custom text editor to take into account your custom script tag (probably not worth the effort)
Put your javascript snippet in an external file, use the include directive inside your custom script tag.
<%# include file="javascript.js" %>
Eclipse has a template feature where in you can add specific tag ,which can be made available for all JSP pages.
Ensure you have installed Eclipse WTP ( Web Tools Platform )
1.Open Preferences window [ Select Window > Preferences ]
2.Expand Web Option from the menu, upon which you can see [ CSS Files,HTML Files etc..
3.Select JSP Files
4.Select Editor
5.Select Templates
6.In the corresponding pane , click New and from there rest can be easily done.

Notepad++ is recognizing my html.erb files as javascript files! It's messing up my syntax highlighting!

This is really annoying...it really is messing up my syntax highlighting...
I think it suddenly happened after I deleted one of my javascript_include_tag statements and saved...suddenly the highlighting changed.
This all happened around the time I created my first js.erb file...
Oh yeah: It was working before!!! I have "erb" already added as a file association/extension to html files...but for some reason, html.erb files are suddenly getting interpreted as javascript files! like, in the bottom left, it says what type of file you are viewing, and when I have an html.erb file open it says "javascript file" which is absurd...it used to say html erb...
You can configure Notepad++ to recognize an .erb (.html.erb or .js.erb) file and associate it with a given language (html).
In the menu bar, go to Settings > Style Configurator...
In the list labelled "Language:", scroll down to HTML. Click on it
Beneath the lists for Language and Style, there should appear two fields: Default ext and User ext. Enter 'erb' in the User ext field.
Click Save & Close
Now when you open a file with the .erb extension (incl. .js.erb), Notepad++ will automatically apply syntax highlighting for HTML.
I figured out the problem myself. Since Rails 3 uses this new js.erb file, at one point, I went to the style configurator and added "erb" as an extension option under "Javascript." I had already done this for html so html.erb is recognized as html, so apparently notepad++ has this bug in it b/c once I added "erb" to Javascript all html.erb began getting recognized as JS files. Removing that "erb" to Javascript in the style configurator fixed the problem. :)
Check the post here:
http://www.thekua.com/atwork/2009/07/file-associations-in-notepad/
It allows you to change the associations.

Categories

Resources