Saturday, March 16, 2013
AngularJs compiling dynamically added dom
We have an application where we use angular for a particular tab. So we needed to compile the ajax document.
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, December 11, 2011
Project Portfolios engine for Refinery CMS
![]() | |
| Project portfolio |
![]() |
| Project details popup |
Saturday, August 8, 2009
Tips on writing browser compatible css
Writing browser compatible css is a difficult job for people with less experience in css. Specially Internet Explorer make things interesting(or gives you headache, what ever you prefer ;) ). As an application grows it becomes more and more difficult to manage browser compatibility. And as Internet explorer continues to release new versions, it leaves a few time for developers to spare. Some times different browser is needed to tweak differently. It may be the size of the font, padding floating problems etc.
People then started to use Conditional Comments like bellow to give browser compatibility,
<!--[if lte IE 6]> <link rel="stylesheet" type="text/css" href="ie_hacks.css" /> <![endif]—>
And there is the !important hack
Normally in CSS whichever rule is specified last takes precedence. However if you use !important after a command then this CSS command will take precedence regardless of what appears after it. This is true for all browsers except IE. Here you can find more.
h1 { font-size: 1.6em !important; font-size: 1.4em; }Here IE still takes 1.4em as the font size.
Tantek introduced a hack for ie and opera regarding the box model problem.
Hybrid Hacking defined css as,
#wrapper {
width: 770px;
wid\th: 750px;
}It's a legal 'escape' backslash and should be ignored, but when it is inside the property name it is not ignored by IE5 and IE5.5 for Windows. Instead it causes those browsers to ignore the following "t" character in this case, thus making the property name unreadable to them. Which was explained here.
Then there was the The Child and Adjacent Sibling Hacks, as IE does not understands html>body. Which looks like,
#wrapper {
min-height: 500px; /* IEwin does not support min-height */
height: 500px;
}
html>body #wrapper {
height: auto;
}This is discussed more elaborately here.
Here is a list of rule compatibility of browsers which is really useful.
An easy solution to write css which can easily support different browser
It is a combination of Javascript and CSS. Here is the Javascript that detects the browser and add a dummy class to body tag.
if ( $.browser.msie && $.browser.version == "6.0" ) {
$("body").addClass("ie6");
}
Although it is written in JQuery, there are plain Javascript available.
So now if your clients browser is IE6 then you already have a dummy class added to you body tag. Now you can write IE6 specific hack easily.
h1 { font-size: 1.6em; }
.ie6 h1 { font-size: 1.4em; }It is more readable and you can provide different hack for different browser and versions with this hack.
References
http://www.positioniseverything.net/articles/ie7-dehacker.html
Friday, July 17, 2009
Some Css and Javascripts optimization tips
There are so many aspect for optimizing the performance of a web application, that some times people tends to forget about Javascript and Css.
Yahoo developers experienced that, 80% of the end-user response time is spent on the front-end. Most of the time browser is busy downloading images, stylesheets, scripts, Flash, etc. Here you can find the details.
But there are improvement opportunities in these areas to improve the over all performance of the application.
Mostly we concentrate on some basic criteria
Caching
Caching is great and browser gives you for free :). But should all our css and Javascripts should be cached??
Actually no!! Because some times browsers cache too much(specially Internet Explorer). You want the client to get the latest files if the file is changed.
So we need to identify the files that changes and files that do not change(library files, like jquery, prototype etc). We expect library files to get cached and custom files that changes a lot, not to be cached. We can skip caching by passing a random query string like,
<script type="text/javascript" src="scripts/default.js?rand=1"></script>That random number can be generated from the server side while serving the page (which is a built in facility for rails).
Now for common libraries(jQuery, protopye) we should use Google API for 2 reasons
- It grabs the library from the closest location it can get. So it loads faster.
- It frees your server from serving the library file, so that your server can serve more files instead.
<script type="text/javascript" src="http://www.google.com/jsapi"></script><br /><script type="text/javascript"><br /> google.load("jquery", "1.3.2");<br /></script>Minifying Javascript and Css
According to Yahoo!'s Exceptional Performance Team, 40% to 60% of Yahoo!'s users have an empty cache experience and about 20% of all page views are done with an empty cache (see this article by Tenni Theurer on the YUIBlog for more information on browser cache usage).
So surely you want to minify all your javascripts and css on your production server. There are some nice online Javascript and css packer which actually does the trick.
Javascript
http://dean.edwards.name/packer/
Css
http://flumpcakes.co.uk/css/optimiser/
I know what you are thinking. You can’t go to web and pack all your css and Javascripts all the time you deploy, specially if you are following Agile and deploying your code after every 2 weeks.
There are platform specific implementations to resolve this problem. For rails we can use this to minify and pack javascripts and reduce number of Javascripts.
You can use yahoo compressor written in Java, so you can run that in any platform.
http://developer.yahoo.com/yui/compressor/#work
There is another implementation by Douglas Crockford,
http://crockford.com/javascript/jsmin
We can add necessary commands to our deployment script, so that after or before deployment the compressor is run.
Reducing number of files
Web servers can not serve a lot of files consecutively. There are limitation for browsers as well. If you watch your site with firebug net inspection, you will see that a lot of file calls which are not called parallely. So reduction in number of files served can improve the performance of the web application.
How can we reduce number of files?
There are several ways we can reduce number of files.
1. We can merged css and javascript the way we minified it.
2. Most of the cases we don’t care about the images. As a result the number of images grow rapidly.
There are some nice ways to merge images into one using css background-position property. People call this css sprite.
And every one use it to reduce file size as well as number of files.
If you merge some images into one, then size is actually reduced. Because other then the picture information every image maintains a color template. If some images are merged then a super set of color template is generated which reduces the total size of the image then the sum of the size of individuals.
Here are some nice examples
http://www.alistapart.com/articles/sprites
http://css-tricks.com/css-sprites/
Here is a site that generates css sprite.
Friday, November 21, 2008
Collection of some useful jquery plugins
Some of useful jquery plugins I found. I have tested these plugins in IE6 and FireFox.
Datagrids
http://trirand.com/jqgrid/jqgrid.html
http://webplicity.net/flexigrid/
Animations
To animate your web page content flying from left and right Easy Slide demo
You want to flip your content? There you go
Chain your animation. Home Page demo
jTypeWriter gives a type writer effect with your text.
Effects
Gradient effect without images demo
Highlights text within the html
Charts and bars can be drawn with sparkline (need to test in ie)
A gradient effect on text (need to test in ie)
Menu
Picture Gallery
image-slider-player-in-jquery and here is a demo
Rounded Corners
Really nice to have effect, liquid-canvas demo
jquery-roundcorners-canvas demo
Local scroll
serialScroll nice scroller
jq-liscroll, automatically scrolls text horizontally.
The Silky Smooth Marquee demo, it is like list scroller
jscroller scrolls and show html. used for advertisement.
wslide (need to test in ie)

