Translator

Visualizzazione post con etichetta utility. Mostra tutti i post
Visualizzazione post con etichetta utility. Mostra tutti i post

2010-09-25

Multiple Dates Picker for jQuery UI


IMPORTANT NOTE: I'm not having much time in these days to finish documenting, but I've released a demo for you: http://multidatespickr.sourceforge.net/
All the documentation will be moved, little by little, to the sourceforge page.

Please consider that I've already done important bug fixes but had no chance to upload anything to sourceforge as my job's IP is banned :s
I'll upload the new version this weekend, so check it out :)


I love jQuery UI because it allows me to quickly create administration interfaces without the hassle of writing code for animations and common widgets.
By the way there are times when I find myself in need for a feature that jQuery UI's widgets don't cover, like -for example- the ability to pick multiple dates using the jQuery UI DatePicker calendar widget.

This time I really needed this functionality and thought that it would be easier to learn how to write a jQuery plug-in to extend DatePicker, instead of adopting another javascript tool.

The result is this multiDatesPicker I made. I spent one day to do it, trying to understand how to develop the plugin using best practices and trying to make it work.

It seems stable now, makes just what I needed it to, and mantains all the datepicker events, methods and options, exception made for the "beforeShowDay" event that had to be sacrified in the name of multiple selections (I still hope I can find a way to make it available, but I have to investigate more).

To download it just click here: jquery.ui.multidatespicker.js

How to use it?
Being an extension to jQuery UI DatePicker you need to include both jQuery and jQuery UI (with datepicker module included!) javascript files to your HTML page, and right after that, include MultiDatesPicker.

To apply it to an element, do it the same way as you would do with jQuery UI datepicker, but write multiDatesPicker instead of datepicker:
$(element-or-selector).multiDatesPicker(options-to-initialize-datepicker-and-multidatepicker);

MultiDatesPicker specific options:
  • addDates
    Adds an array of dates specified in a string or javascript date object format.
    NOTE: the string format you should pass to multiDatePicker depends on the localization of datepicker, see this page for more infos on how to configure it.

Available methods:
  • compareDates( date1, date2 )
    Compares two dates returning 1, 0 or -1 if date2 is greater, equal or smaller than date1 respectively.

  • gotDate( date )
    Returns the index of the date in the dates array, or false in case that date is not found.

  • addDates( dates )
    Adds one or more dates to the calendar.
    The parameter dates can be a string or an array (of strings or javascript date objects).

  • removeDates( indexes )
    Removes one or more dates from the dates array using their indexes.
    The parameter indexes can be an integer or an array of integers.

  • toggleDate( date )
    Adds/removes a single date from the calendar.

  • getDates( format )
    Retrives the array of dates associated with the multiDatesPicker in the specified format: "string" (default) for localized string format, or "object" for javascript date object format.


Please comment if you think this plugin is useful for you, or if you have ideas on how to make it better.

2010-08-21

Aptana (and Eclipse?) upload_current_file_on_save.js adapted

I'm just getting familiar with Aptana (a variation of the Eclipse IDE) for PHP development and I got really intrigued by the Scripts available to run custom macros within Aptana.
One I really wanted to use is "Upload current file on Save", which is coded within the file: upload_current_file_on_save.js

The problem with this file is that it comes disabled. If you get into it you'll see explicit comments that explains it.

Seems it's disabled because it is not "toggleable" like other scripts, so if enabled from within the script code, it would be always enabled in *ANY* Aptana projects, and this could be an undesired feature.
Aptana support staff say to use that script as project-specific script to avoid the previously explained issue.

Being everything scripted in javascript, a language known to me, I've tried to edit the code and obtained (at least in my case) a version of the feature that can be turned on and off just like other scripts.
Of course there could be better ways to fix the script, but I didn't wanted to spend a lot of time with it and got in the following working solution in few minutes, which is ok for me:
upload_current_file_on_save_dubrox.js

Feel free to use this script if you like. And in case you do anything better, then please comment this post with a link to your solution :)

2010-07-03

Unlock autocomplete=off forms (bookmarklet)

Here it is, my own implementation of a cross browser unlocker to allow you to autocomplete forms and inputs that have the attribute:
autocomplete=off

Just add the following link as bookmark and click on that bookmark when you are in a page with a "unautocompletable" elements:

If you are annoyed by the message informing you about how many elements where successfully unlocked you can use this other bookmark (same stuff, without alert message);

Soon I'll post an example video for those of you that what a clearer example of what this little bookmarklet does.

If you find any bug or you find it useful and want me to know, please comment this post.