Amazon.com Widgets

jQuery Syntax Mode

So you have Coda and you’re thinking, “this is a great program and I love how productive I am now. But I really wish that the Javascript mode would autocomplete my jQuery stuff.” Yeah, I’ve been there. I couldn’t find one either, so I made one. And now you can have it too. You’re welcome.

What’s New in 1.5?

For starters, there’s some new functions available. I think I have most of the functions for jQuery 1.3.2 included in here now. It’s still not an exhaustive list, but I don’t think it ever will be a complete listing. Beyond that, I’ve bundled a few extra modes for HTML and PHP-HTML that include the modifications to use the jQuery mode inline. This means that you won’t need to reapply those modifications when Coda is updated. The biggest addition is that I’ve added hints to most of the jQuery functions. It still doesn’t work like PHP does, but you can read more about that in the Hints section.

Installation Instructions

For starters you need to click that download link and unzip the archive. Inside you’ll see three folders called jQuery.mode, HTML-jQuery.mode, and PHP-HTML-jQuery.mode and another file called jQuery.clips. You can install the syntax modes by copying those .mode folders to your ~/Library/Application Support/Coda/Modes/ folder. Technically, you only need the jQuery.mode, but I’ll explain why the others are there later and you can choose if you want them or not.

To install the Clips (I know, hard to figure out what that .clips file is for with that cryptic file extension) you need to open the Clips palette (⌃⌘C) and then right click in the left sidebar and choose ‘Import Group…’ find the jQuery.clips file and import that bad boy. You can learn more about what this does in the Clips section.

Usage Instructions

Of course, installing is only half the battle. Now that it’s available what you really want to do is use it. You can use it manually by selecting if from the menu: Text > Syntax Mode > jQuery. Start coding and marvel as jQuery functions are now available in the autocomplete suggestions. But manually is only gonna be fun for so long. It would be great if you could use it wherever you use Javascript. So I stole all the stuff in the Javascript mode and mixed in the jQuery stuff. Now the jQuery mode is safe to use everywhere you use your Javascript.

To make it the default mode for any Javascript file you need to tweak your preferences. In the Editor tab you can set some overrides for particular file extensions. Down near the bottom of the tab is the Custom Syntax Modes area. Click the ‘+’ and type js in the File Extension field and select jQuery from the Syntax Mode dropdown. Now every .js file will use the jQuery syntax mode.

There’s still one small problem, you won’t get the jQuery mode when you’re coding Javascript inside of an HTML or PHP file. Don’t worry, I thought of that too. Remember those other modes (PHP-HTML-jQuery and HTML-jQuery)? I have modified the stock PHP-HTML and HTML modes to use the jQuery mode instead of the Javascript mode when doing inline Javascript stuff. Users of previous versions will recall that you needed to modify these yourself before. Well I learned that that works fine until Panic pushes out an update and then you had to reapply those modifications. These modes are independent of the standard modes and therefore won’t be overwritten during an update.

Creating a Custom Mode That Uses the jQuery Mode

If you’re an ASP developer or really anyone that doesn’t use HTML or PHP these modes don’t really help you. So here’s how you create your own custom modes that use the jQuery mode when editing inline.

First you’ll need to make a copy of your mode. If it’s one of the standard modes you can find that by right-clicking the Coda application and choosing ‘Show Package Contents’. Then navigate to Contents > Resources > Modes. Copy that (make sure that you copy it and not just move it) to the same folder you copied the jQuery.mode folder. Change the name to something original like MyMode-jQuery (clever ain’t it?).

Now, open the Info.plist file inside the Contents folder and change the Bundle Identifier and the Bundle Name to whatever you just named that folder. Save and close that file and open the SyntaxDefinition.xml file in the Resources folder. Right at the top change the name to match what you named the mode. Now do a search for ‘Javascript’, if the result is in the context of usesymbolsfrommode= or useautocompletefrommode= or import mode= then change Javascript to jQuery. Save and close that file and restart Coda and you are ready to go. You can test it by switching to that Syntax Mode in the Text menu.

To make your new mode the default for those files just open your preferences and do like we did for the .js files. I set .php files to use that PHP-HTML-jQuery mode I bundled.

Hints

From the very beginning I wanted to make this mode behave the way that the PHP mode does, where it will insert hints inside the parentheses for functions to remind you of what you need to pass in. The PHP mode is really nice in that it does this all inline and pre-selects the hint text so they can be typed over after you’ve refreshed your memory. Well, I can’t do that due to some limitations in Coda (PHP is a special case that they programmed to behave that way), but I’ve added hints anyway.

Hints won’t appear inline, but you can see the hints in the Hints bar at the bottom of the editor window (turn that on by clicking the button that says Hints). Now whenever you have the autocomplete popup showing, you can cycle through the available functions and see the hints for that function. Note: if you select a function that doesn’t have any hints the hint bar will show the last function that did have hints associated with it — so don’t think it isn’t working if things don’t always change. Those hints will stay shown after you select the function as well to help remind you.

I’ve tried to format the hints to help you know what the different options are. The conventions should be familiar to most that have visited coding sites like PHP.net. Anything that is wrapped in [ ... ] is optional. If there are multiple configurations of options I have separated those options using the pipe ( | ) character. So something that has two options would be along these lines: value | string, meaning you can pass in either a value or a string.

I think that most of the hints are self-explanatory. values are numbers, selector means a jQuery selector, function is, you guessed it, a function. There are some functions that allow you to pass in a certain keyword to modify the behavior, so if the hint isn’t asking for something generic like a value or name, then you can probably just use the text of the hint as is. An example would be the noConflict() function whose hint consists of [extreme].

Clips

All the clips that I included in the bundle have tab-triggers. Below is a list of what they are and what they do.

ready+tab:
$(function() {
/*place jQuery actions here*/

});

$+tab:
$(’‘)

this+tab:
$(this)

func+tab:
function() {

}

SEEStyles

If you are using a custom SEEStyle for Javascript you will notice that your new jQuery mode is not looking so hot. This is easily remedied with a few steps. In Coda, open your Preferences and go to the Colors tab. Export the Javascript theme, open that file in Coda, and replace Javascript with jQuery (blind find/replace is okay on this one).

For your custom modes (like PHP-HTML-jQuery) you need to do the changes as outlined above and you need to update the name to your new name. So, for example, for the PHP-HTML-jQuery SEEStyle you need to change the ‘SEEStyle.PHP-HTML’ to ‘SEEStyle.PHP-HTML-jQuery’. Also you will need to change each ‘id’ from ‘PHP-HTML’ to (yep, you guessed it) ‘PHP-HTML-jQuery’. Now, the term Javascript with jQuery, but replace only those instances where it looks something like /Javascript/Keywords (e.g. in the PHP-HTML mode there is one reference that says ‘Inline Javascript’ that is okay to leave as is).

Save your new SEEStyles and then import them back into Coda. Things should be looking a lot better now.

Upcoming Features

I still have a lot I want to do with this mode. For starters I’m working on making it a little more intelligent so that if there functions that are tied to each other they can only be used together. For example, the $.support function has a bunch of additional functions (boxModel, cssFloat, etc.) that only work in conjunction with that function. I want to make those secondary functions appear only after you’ve entered $.support. Beyond that there are the options for the selectors like :first or :visible. These aren’t working right now due to some strangeness with the RegEx functions that control all of this. I’m trying to sort that out, but I’m horrible at RegEx so it might take a while. And as always there will be more refinements and more functions in the future.

FileDownload

Download

ProjectInfo

  • Version: 1.5
  • Released: November 11, 2009

PreviousVersions

  • jQuery Syntax Mode v1.0
  • ShamelessBegging

    Bandwidth isn't free, and creating things like this takes time. If you find these things useful then maybe you might consider making a small donation. It helps offset my bandwidth cost and will help me to keep improving them. Thanks.

    Comments

    Name:

    Email:

    URL:

    Remember my personal information

    Notify me of follow-up comments?

    Posted by Randy  on  05/27  at  12:57 PM

    Awesome work! I’m already making use of this. Very slick.

    With regard to the hints, I think adding these hints into the autocomplete anyway is the way to go for now. I’d rather have them and delete them than not have them at all personally.

    Later when Panic allows JS to work like PHP in the autocomplete hints we’ll really be in business.

    Thanks for sharing this.

    Posted by Shrop  on  05/28  at  04:00 AM

    Fantastic work! Been wanting this for so long. Works great. Thanks for putting the time into this and then sharing it.

    Shrop

    Posted by Barbelith  on  05/29  at  08:31 AM

    Thank you very much, I use jQuery a lot and it is very useful to have autocomplete.

    Posted by Oleg  on  06/01  at  03:34 AM

    Thanks a lot. Really useful. For some reason it did not work for me in HTML mode, though I did the same changes as to HTML-PHP mode, which worked fine. Not sure if you can help me with that. Great work anyway!

    Posted by Nils Ellingsen  on  06/04  at  06:18 AM

    Thanks a bunch! jQuery syntax can be hard to remember smile

    Posted by John  on  07/11  at  03:58 AM

    I dont seem to have a coda folder in my Application Support…do I add it?

    Thanks!

    Posted by K. Garner  on  07/13  at  07:45 AM

    John, make sure that you are in the right Library folder first. OS X has at least 3 Library folders (more if you have more than 1 user account). You need to be in your user’s Library folder. To get there click on your home folder in the Finder sidebar and then click on that Library folder. If there isn’t a Coda folder in that Library/Application Support then you can add one, but make sure you’re in the right place first.

    Posted by John  on  07/13  at  08:09 AM

    The issue was I never actually placed Coda in the Applications folder and had been running it and kept in the Dock from the Downloads folder - once I added it to applications and restarded Coda voila.

    Thanks for the plugin works like a champ!

    Posted by Jason Kuhrt  on  07/22  at  02:25 PM

    Hey Kory, thanks a lot for this contribution. Function argument hinting would be necessary in the long-term but this is better than nothing. Kudo’s to sharing it.

    Thanks mate,
    Jason

    Posted by gregory  on  08/31  at  09:19 AM

    this is SWEET! thank you so much for writing / building this. i use this every day.

    Posted by Andrew  on  10/02  at  08:43 AM

    Hi Kory, great work, well done! I avidly installed the plugin, and chuckled with glee when it worked, but was dismayed when i tried to use animate, or slideUp, or hide functions : it didnt autocomplete? It seems like you catered for these functions, but mine doesnt autocomplete. Bug, or massive faupah on my part?

    Posted by K. Garner  on  10/06  at  07:55 AM

    Andrew - I’m not sure what’s going on there. I checked it on my system and those functions do come up in the autocomplete for me. I’ll look into it some more, but it’ll be hard to track down without being able to reproduce it. I’m working on an update as well, more functions and other things added to the autocomplete that I hope to get out soon. Maybe that will fix the problem for you.

    Posted by Chris Wright  on  10/07  at  09:43 AM

    Thanks for this - and thanks for fixing the link!

    Posted by Fhuel  on  10/24  at  03:24 AM

    Awesome ,
    Exactly what I was looking for !

    Thanks for sharing

    Posted by Brandon  on  11/13  at  01:39 PM

    This is really awesome… Its the missing link!  Coda & Jquery can be friends now!  Woo hoo no more frustration.

    Posted by Injerto  on  12/02  at  06:57 AM

    Dear Kory: thank you very much for this plugin, its great. I’d like to ask you, though: have you ever tried textmate jquery bundle? it works in a little more convenient way: when you type $ + tab, write the selector, and then press tab again, it gets you right after the “)”, without having to move your cursor to the end of the line; then you can set an event, such as “click”, and press tab again, and it writes all the “function” thig, similar to writing “func + tab” in your plugin.

    Is there a chance for you to implement this kind of behavior in your plugin? or isn’t Coda that customizable at all?
    Congratulations and thank you once again!

    Posted by K. Garner  on  12/02  at  08:43 AM

    Injerto, this is pretty much a fundamental difference between how Textmate and Coda work. The editor in Coda (SubEthaEdit) doesn’t support the “tab jumping” behavior of Textmate, so consequently, Coda can’t do it either. There is a lot of speculation that Coda 2.0 will be more flexible for these types of things, but we’ll have to wait and see. I’m really hoping that if they do a beta trial that I can get a copy to test and make the necessary adaptations.

    Posted by Injerto  on  12/02  at  08:51 AM

    That would be great.  The world is still waiting for Textmate 2.0, which seems that will never happen. Let´s just hope it won’t be the same with Coda.

    Btw, do you know about a fix for the drag-n-drop feature in coda? When you drop a css or js file in Textmate, it writes the right html code to include it, but coda just opens it in a new tab…

    Regards

    Posted by Ian Atkins  on  02/01  at  02:35 PM

    Thanks for this, most kind!

    Posted by local search marketing news  on  03/09  at  02:53 AM

    Its very good information. jQuery is very helpful for maintaining coding. Thanks for this useful information.

    Posted by local search marketing  on  03/09  at  03:01 AM

    Yeah it’s very useful.  For some explanation it did not work for me in HTML style, while I did the same changes as to HTML-PHP style, which worked well. Not certain if you can help me with that. Any way its very good work. I like it.

    Posted by local search engine marketing  on  03/09  at  06:02 AM

    The matter was I not at all in fact located Cods in the Applications folder and had been running it and reserved in the docks from the Downloads file - once I added it to applications and retard Cods voila.

    Posted by android code  on  03/15  at  12:33 AM

    I’m not abiding what’s traveling on there. I arrested it on my arrangement and those functions do appear up in the auto complete for me. I’ll attending into it some more, but it’ll be harder to clue down after getting able to carbon it. I’m alive on an amend as well, added functions and added things added to the auto complete that I achievement to get out soon. Maybe that will fix the botheration for you.

    Posted by Scott Rouse  on  04/02  at  10:55 AM

    Rock on!  Thanks for this…it is very helpful.

    Posted by Hayden Chambers  on  04/12  at  03:34 AM

    Hey Kory, looking forward to the upcoming features. Was an absolute must-have from a dev POV!