Monday, January 14, 2013
Jquery ui datepicker a common gotcha
If you have multiple jqerury ui datepicker with the same html ID, then you are done for. Crazy behavior is observed then. Don't set id to input for datepicker if you have multiple of them, or just assign a new id to each of them.
Tuesday, November 6, 2012
Using class as jquery selector
$('a.mark_locked').live('click', function () {
// your code goes here
});
Using class as a selector for putting a javascript business logic is kind of evil.
The purpose of class in HTML is for styling. After jquery or prototype came to light, people have been using it for selectors as well. But to me this is not right. I myself used to do this a lot. But not anymore. Because when you hire a designer to change the html or dom then the designer has to know which class to keep and which to change. He does not have a clue which are the classes used for javascript. And for a large project it is a huge issue. Eventually no classes are removed and the HTML dom becomes heavy and clumsy.
A much better approach is to use attribute selector, as following,
$('a[mark_locked]').live('click', function () {
// your code goes here
});
Now your designer has more freedom for manipulating classes in dom.
Sunday, July 29, 2012
HTML widgets using jquery
What is post is about
This post is an extension of the post by Alex Marandon. In that post you will find the following topic discussed- Web widget
- Usage
- Bootstrap code using jquery
Things to care for
- Widget must not interfere with css and javascript of existing site
- For rendering widget it is better to provide the following choices
- Some default theme to show the widget nicely
- Provide the option for the site owner to override the theme with custom css
- Allow widget to be customized by user
Solutions
Javascript conflicts
If you are using jquery then Alex Marandon has made it clear how to use jquery using noConflict. But when you will be using plugins for jquery in the widget you have to use no conflict is the following way,jQuery = window.jQuery.noConflict(false);
The reason to use false is telling jquery not to remove the jquery from the window.jquery, because plugins use jquery from window.jquery. If you use true in the param then any plugin that you add in the widget will not work.
Css conflicts
It is very important if you want to provide some out of box theme that the user may choose from. Then you need to make sure that your css does not conflict with existing ones. I found that the best way is to use sass. Because then you can use nesting to ensure that the css that you provide only impacts the container of the widget and nothing else.Customization
Demo
Reference
Sunday, December 11, 2011
Project Portfolios engine for Refinery CMS
![]() | |
| Project portfolio |
![]() |
| Project details popup |
Sunday, February 1, 2009
Png Corner is the solution of rounded/styled corners which is browser compatible
I was searching for an easy and simple implementation of smooth rounded corner that is browser compatible. If you want smooth corners you will need png images and Internet Explorer 6 has issues with png alpha transparency. Then I came with a project pngcorner . This is very easy to use and very small in size(less than 4 kb ). You can download the demo from here.
For png transparency I used unitpngfix , a very small(less than 1 kb ) and yet very effective javascript library. And used a table structure rounded corner template. For detail please visit the project page.
Here is a demo and here is the demo with jquery plugin.
Why use png corners
- It is browser compatible(works in IE 6/7, FireFox 3, Opera 9, Chrome 1.x)
- It's small(less than 4 kb )
- Easy to use(Just follow 3 easy steps)
- Can use png transparency feature so that you can create your own styled box.
- Same behavior across browsers
- Size of your content is totally flexible
- You can change images from css
- Use to create smooth rounded corner content with shades
- Use to create buttons with shades(as the size is expandable you can have small buttons as well as long ones)
Limitations
- It uses table for the structure of rounded corner. So your rounded corner is not as flexible as div layout (It is a small sacrifice for IE 6 png transparency)
- The images at left, right, top and bottom will be scaled not repeated. As Microsoft.Alpha filter do not support repeating.
Usage
1. Add png _corner. css in page
2. Add html structure for rounded corner, which looks like this,
<table class="rounded_corner" border="0" cellpadding="0" cellspacing="0">
<tr><td class="top_left"/><td class="top"/><td class="top_right"/> </tr>
<tr><td class="left"/>
<td class="content">The content goes here :)</td>
<td class="right"/>
</tr>
<tr><td class="bottom_left"/><td class="bottom"/><td class="bottom_right"/></tr>
</table>3. Add png hack css in header as shown bellow so that the script is only added for Internet Explorer 6.
4. Add clear. gif in root_file/images
And you should be good to go :)
jQuery Version
There is a jQuery version of png corners. For that you will have to follow all the steps and add another javascript file pngcorners.js. But now the step 2 is now being simplified.
No need to remember all those tags and make your view complex. Just call,
$(".round_me").pngcorner();Where you are expecting for elements with round_me class name will become rounded corner :)
So it reduces tags and cleans the view a bit.
Caution
When you load you content from ajax call or create your content dynamically after your page is loaded then you have to call the following javascript after you have done loading your content.
pngfix();
I am still searching for a solution with lesser limitation and complexity. So any suggestion is welcome.
Wednesday, January 7, 2009
Replacing Prototype with jQuery in Rails
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.
For people who like to use jQuery in rails there is a good news. There is a plugin jRails, which overwrites remote tags provided by rails and uses jQuery ajax call. You can find the project here.
jRails covers all of the functionality in the built in Rails prototype_helper as well as some of the functionality in scriptaculous_helper. Current release includes support for basic AJAX calls (form_to_remote, link_to_remote), RJS, observers (observe_form, observe_field) as well as a limited set of functionality for draggables, droppables, sortables and visual effects.
Resources:
http://justtalkaboutweb.com/2008/01/14/replace-prototype-with-jquery-on-rails/

