IE issues with new Element and class
Wed, 12 Aug 2009 16:42:34 +0000
The problem we have is that this code
new Element('div', {'class':'klassName'})
will work in firefox but in IE (tested on version 8) the className is never set, which was causing some problems with the elements styles.
One of the workarounds would be to explicitly add the class name, like this:
var e = new Element('div');
e.addClassName('klassName');
The problem with this approach is that at work, we have a huge javascript codebase, so instead, we are going to monkey patch Prototype. We’re working against version 1.6.0.3 of prototype, that’s why we add the alert, so when we update, we’ll catch this and check if it was fixed on core.
// This is a dirty hack to protoype, so IE, will take class names on new Element
// new Element('div', {'class':'klassName'}) doesn't work on IE but does on firefox
// in IE, we wouldn't get the className set.
if (Prototype.Version != '1.6.0.3') alert("BEWARE OF THE PROTOTYPE VERSION");
(function() {
var element = this.Element;
this.Element = function(tagName, attributes) {
attributes = attributes || { };
tagName = tagName.toLowerCase();
var cache = Element.cache;
if (Prototype.Browser.IE && (attributes.name || attributes['class'])) {
tagName = '<' + tagName + ' name="' + attributes.name + '"' + 'class="' + attributes['class'] + '"' + '>';
delete attributes.name;
return Element.writeAttribute(document.createElement(tagName), attributes);
}
if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);
};
Object.extend(this.Element, element || { });
if (element) this.Element.prototype = element.prototype;
}).call(window);
posted by mrdias, 6 months ago
Tags:
IE
javascript
prototype
Whydicab gets some love
Sun, 15 Feb 2009 16:53:35 +0000
I did a few changes to this blog lately. First comes support for rss and atom feeds. You can also just configure in your settings to use an external feed like feedburner, just how I’m doing it.
While upgrading Merb, I’ve had some issues with the new way of bundling, which affects my deployments. I haven’t figured out an easy way to have different dependencies per environment. I’ll have to check that out.
posted by mrdias, 11 months ago
Tags:
bundling
merb
whydicab
Git goodies
Thu, 12 Feb 2009 13:51:15 +0000
A couple days ago I had to gather some information from a git repository, so I’m sharing this small scripts with you.
List of all authors on a git repo:
git log --pretty=short | grep Author: | awk '{print $2}' | sort | uniq
List all modified files since a revision:
git-whatchanged revision.. --pretty=oneline | grep '^:' | awk '{print $6}' | sort | uniq
posted by mrdias, 12 months ago
Tags:
git
shell
Will Paginate and Ajax
Tue, 16 Dec 2008 17:45:07 +0000
I recently had to implement some ajax pagination for a site. After googling for a while I found a solution, but I couldn’t customize the pagination url’s or I had to specify the paginator to use (will paginate’s default or mine for ajax), so I came up with this solution which fulfils all my needs.
First create the following class in your app/helpers.
class RemoteLinkRenderer < WillPaginate::LinkRenderer
def prepare(collection, options, template)
@remote = options.delete(:remote)
super
end
protected
def page_link(page, text, attributes = {})
if @remote
@template.link_to_remote(text, {:url => url_for(page), :method => :get}.
merge(@remote), attributes)
else
@template.link_to(text, url_for(page), attributes)
end
end
end
Then you have to tell will_paginate which link_renderer to use, I do this in a rails initializer.
WillPaginate::ViewHelpers.pagination_options[:renderer] = 'RemoteLinkRenderer'
So with this solution, you can work like you would normally with will_paginate, but if you need to do an ajax link, then you’ll have to pass the options in the remote hash, something like this:
will_paginate(@comments, :remote => {:update => 'comments'})
That’s it enjoy. You can keep passing the same options you would normally do to will_paginate to customize the behaviour.
posted by mrdias, about 1 year ago
Tags:
ajax
rails
will_paginate
Will Paginate and Merb
Tue, 09 Dec 2008 10:29:33 +0000
So this blog is using will_paginate and merb.
I read something about how to do it in this post by The merbist, albeit the information was not complete.
So here are my instructions:
Clone mislav’s will_paginate repo and build the gem from the agnostic branch.
git clone git://github.com/mislav/will_paginate.git cd will_paginate/ git checkout origin/agnostic gem build
With this commands you’ve generated the will_paginate-3.0.0.gem.
If you want to install it system-wide use your usual gem install.
If you want to bundle it in your project, as I did, then you’ll have to do:
thor merb:gem:install path/to/gem
That’s it.
UPDATE: If you don’t want to build that stuff you can download it here
posted by mrdias, about 1 year ago
Tags:
merb
whydicab
will_paginate
Introducing whydicab
Mon, 08 Dec 2008 19:35:59 +0000
Whydicab: Why did I create another blog?
The answer is very simple, to learn. This is a playground for different technologies I’ve been trying lately. This small blog is based on Merb and Datamapper.
It is using rspec, dm-sweatshop, dm-tags, etc.
It’s inspired on feather but without all the other stuff I didn’t need.
So I’ll be using this blog to tell you the things I find interesting for the ruby community and other technologies related.
If you want to checkout the code powering this blog, visit the repo at http://github.com/diasjorge/whydicab/tree
posted by mrdias, about 1 year ago
Tags:
datamapper
merb
whydicab