Tuesday, October 13, 2009

Accordion.js

accordion.init params (accordion.init(5,1,"ul.menu","slow"):
  • 5: opened section index (numeric)
  • 1: autohide (bool)
  • "ul.menu": container element
  • "slow": speed
On each page can be rendered "#navid" parameter (section name) to focus setting.

HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="accordion.js"></script>
<script type="text/javascript">
$(document).ready(function(){accordion.init(5,1,"ul.menu","slow")});
</script>
</head>
<body>
<ul class="menu">
<li rel="category">
<h3 rel="title">parent</h3>
<ul level="0">
<li rel="category">
<h3 rel="title">category 1</h3>
<ul level="1">
<li class="sub_items"><a href="#">link 1</a></li>
<li class="sub_items"><a href="#">link 2</a></li>
<li class="sub_items"><a href="#">link 3</a></li>
</ul>
</li>
<li rel="category">
<h3 rel="title">category 2</h3>
<ul level="1">
<li class="sub_items"><a href="#">link 1</a></li>
<li class="sub_items"><a href="#">link 2</a></li>
</ul>
</li>
<li rel="category">
<h3 rel="title">category 2</h3>
<ul level="1">
<li class="sub_items"><a href="#">link 1</a></li>
<li class="sub_items"><a href="#">link 2</a></li>
</ul>
</li>
</ul>
</li>
<
li rel="category">
<h3 rel="title">parent</h3>
<ul level="0">
<li rel="category">
<h3 rel="title">category 1</h3>
<ul level="1">
<li class="sub_items"><a href="#">link 1</a></li>
<li class="sub_items"><a href="#">link 2</a></li>
<li class="sub_items"><a href="#">link 3</a></li>
</ul>
</li>
<li rel="category">
<h3 rel="title">category 2</h3>
<ul level="1">
<li class="sub_items"><a href="#">link 1</a></li>
<li class="sub_items"><a href="#">link 2</a></li>
</ul>
</li>
<li rel="category">
<h3 rel="title">parent</h3>
<ul level="1">
<li rel="category">
<h3 rel="title">category 1</h3>
<ul level="2">
<li class="sub_items"><a href="#">link 1</a></li>
<li class="sub_items"><a href="#">link 2</a></li>
<li class="sub_items"><a href="#">link 3</a></li>
</ul>
</li>
<li rel="category">
<h3 rel="title">category 2</h3>
<ul level="2">
<li class="sub_items"><a href="#">link 1</a></li>
<li class="sub_items"><a href="#">link 2</a></li>
</ul>
</li>
<li rel="category">
<h3 rel="title">category 2</h3>
<ul level="2">
<li class="sub_items"><a href="#">link 1</a></li>
<li class="sub_items"><a href="#">link 2</a></li>
</ul>
</li>
</ul>
</li>
<li rel="category">
<h3 rel="title">category 2</h3>
<ul level="1">
<li class="sub_items"><a href="#">link 1</a></li>
<li class="sub_items"><a href="#">link 2</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<span id="navid" style="display:none">category 1</span>
</body>
<
/html>

Javascript
$.fn.equals = function(compareTo) {
if (!compareTo||!compareTo.length||this.length!=compareTo.length){return false}
for(var i=0;i return true;
}
var menu = function accordion(l,h,c,s){
var accordion = {
init : function(){
this.autohide=h;
this.speed=s;
this.parents=[];
this.container=$(c);
this.focus=$("#navid");
this.initMenu(l)},
categories : function(){return this.getH3(this.getLi(this.container))},
getLi : function(e){return $(e).find("li[rel=category]")},
getH3 : function(e){return $(e).find("h3[rel=title]")},
close : function(e){$(e).find("h3:first").addClass("close")},
findParents: function(p){
var c=this.container,a=this.parents;
$.each(p.parents("ul"),function(){
if($(this).equals(c)){return}
else {a.push($(this))}})
return a},
up : function(p,e,h){
var u=p.find("ul");
h?u.hide():u.slideUp(this.speed);
this.getH3(p).removeClass("close")},
down : function(p,e){
var b=$.browser.msie&&$.browser.version=='7.0',
o=this.findParents(p),
s=this.speed,
u=p.parent().find("ul[level="+e.attr("level")+"]"),
h=$.grep(u,function(a){return a!=e[0]});
b?e.show(s):e.slideDown(s);
if(this.autohide)$.each(h,function(){accordion.up($(this).parent())});
this.close(p);
$.each(o, function(){
accordion.close($(this).parent());
b?$(this).show(s):$(this).slideDown(s)})},
anime : function(t,e,h){this[t](e.parent(),e,h)},
setFocus : function(i) {
var f=this.focus,t=f.text();
if(f.length>0){$.each(this.categories(),function(k,v){if($(v).text()==t)i=k})}
return i},
initMenu : function(i,init){
var p,e=this.container.find("ul");
if(i==-1)this.setEvents(e);
if(init){e=$(e[i]);e.is(':visible')?this.anime("up",e):this.anime("down",e)}
else{this.setEvents(e);i=this.setFocus(i);this.anime("down",$(e[i]))}},
setEvents : function(e){
var h=this.categories();
h.bind("click",function(e){accordion.initMenu(h.index($(e.target)),1);});
this.anime("up",e,1)}
}
return accordion.init();
}

Thursday, October 8, 2009

iPhone & Rails

ObjectiveResource is an Objective-C port of Ruby on Rails' ActiveResource. It provides a way to serialize objects to and from Rails' standard RESTful web-services (via XML or JSON) and handles much of the complexity involved with invoking web-services of any language from the iPhone.

http://iphoneonrails.com/

Wednesday, October 7, 2009

Cross-Domain Ajax with Flash

flXHR is a *client-based* cross-browser, XHR-compatible tool for cross-domain Ajax (Flash) communication. It utilizes an invisible flXHR.swf instance that acts as sort of a client-side proxy for requests, combined with a Javascript object/module wrapper that exposes an identical interface to the native XMLHttpRequest (XHR) browser object, with a few helpful additions and a couple of minor limitations (see the documentation for more details).

flXHR requires plugin v9.0.124 for security reasons. See the documentation for a configuration flag "autoUpdatePlayer" which will attempt to automatically inline update the plugin if need be.

The result is that flXHR can be used as a drop-in replacement for XHR based Ajax, giving you consistent, secure, efficient cross-domain client-to-server cross-domain Ajax communication, without messy workarounds such as IFRAME proxies, dynamic script tags, or server-side proxying.

flXHR brings a whole new world of cross-domain Ajax and API-consistency to any browser with Javascript and Flash Player plugin v9+ support (Adobe claims Flash has 99% browser support now External Link). No other methods or workarounds can claim that kind of wide-spread support or consistency. In addition, flXHR boasts the ability to be dropped-in to many different Javascript frameworks (Dojo, Prototype, jQuery, etc) for even easier and more robust Ajax usage.

http://flxhr.flensed.com/

Thursday, October 1, 2009

An Introduction to JavaScript’s “this”

JavaScript is an amazing little language, but it’s got some quirks that turn a lot of people off. One of those quirks is this, and how it’s not necessarily what you expect it to be. this isn’t that complicated, but there are very few explanations of how it works on the internet. I find myself constantly re-explaining the concept to those who are new to JavaScript development. This article is an attempt to explain how this works and how to use it properly.

http://justin.harmonize.fm/index.php/2009/09/an-introduction-to-javascripts-this/

BugMash

Have you ever wondered how you could get started contributing to the core Rails code? Have you been watching the growth of RailsBridge and wondering where you could fit in? Well, wonder no longer: we have an answer to both of those questions. Announcing:

The First Rails and RailsBridge BugMash

The idea is simple: RailsBridge has a lot of energy. The Rails Lighthouse has a lot of open tickets. With the help of some Rails Core team members, we're going to see what we can do to cut down the number of open tickets, encourage more people to get involved with the Rails source, and have some fun.

  1. Confirm that the bug can be reproduced
  2. If it can't be reproduced, try to figure out what information would make it possible to be reproduced
  3. If it can be reproduced, add the missing pieces: better repro instructions, a failing patch, and/or a patch that applies cleanly to the current Rails source
  4. Bring promising tickets to the attention of the Core team

Some of the Bridgers will be organizing a face-to-face way for BugMash participants to come together (Teams), but there's no need to be there to be a part of it. We'll also have a room open on IRC, and people who are familiar with the Rails internals will be available to help point you in the right direction. We're going to do everything we can to make it easy to start contributing to Rails.

We'll be adding more details to this bare outline over the coming week, including a checklist of what you can do to get ready to work in the Rails source and details on a scoring system and rewards for the most active participants. For now, though, there are two things for you to do:

  1. Reserve at least a chunk of that weekend to roll up your sleeves and work on the BugMash
  2. Speak up if you can contribute prizes, familiarity with the Rails source, or other help to the project.

Official BugMash hours

Rails contributors are located all over the world, so we're going to define an extended weekend for the BugMash. So we're going to run from Saturday noon in New Zealand (00:00:00 September 26 GMT) to Sunday midnight on the US West coast (07:00:00 September 28 GMT). That should give everyone who wants to be involved plenty of time to participate.

Resources
http://railsbridge.org/
http://wiki.railsbridge.org/projects/railsbridge/wiki/BugMash

YUI 3 Is Out!

This is a ground-up redesign of YUI:

  1. Selector-driven: YUI 3 is built around one of the lightest, fastest selector engines available, bringing the expressive power of the CSS selector specification into actions that target DOM nodes.
  2. Syntactically terse: Without polluting the global namespace, YUI 3 supports a more terse coding style in which more can be accomplished with less code.
  3. Self-completing: YUI 3’s light (6.2KB gzipped) seed file can serve as the starting point for any implementation. As long as this seed file is present on the page, you can load any module in the library on the fly. And all modules brought into the page via the built-in loader are done so via combo-handled, non-blocking HTTP requests. This makes loading the library safe, easy and fast.
  4. Sandboxed: YUI modules are bound to YUI instances when you use() them; this protects you against changes that might happen later in the page’s lifecycle. (In other words, if someone blows away a module you’re using after you’ve created your YUI instance, your code won’t be affected.)
http://ajaxian.com/archives/yui-3-is-out
http://developer.yahoo.com/yui/3/