Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add version-switcher widget

  • Loading branch information...
commit 297f8bdad69be375df7608453a7aa9dda39e387d 1 parent 1f86e93
Bryan Larsen bryanlarsen authored
14 app/views/layouts/application.html.erb
View
@@ -1,14 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>Hobocookbook</title>
- <%= stylesheet_link_tag :all %>
- <%= javascript_include_tag :defaults %>
- <%= csrf_meta_tag %>
-</head>
-<body>
-
-<%= yield %>
-
-</body>
-</html>
8 app/views/taglibs/application.dryml
View
@@ -82,8 +82,16 @@
<markdown-checkbox with="&this_parent"/>
</def>
+<def tag="version-switcher">
+ <select id="version-switcher">
+ <option selected="1" value="1.3">Hobo 1.3/Rails 3.0</option>
+ <option value="1.0">Hobo 1.0/Rails 2.3</option>
+ </select>
+</def>
+
<def tag="main-nav">
<navigation class="main-nav" merge-attrs>
+ <li><version-switcher/></li>
<nav-item href="#{base_url}/manual/download">Download</nav-item>
<nav-item href="#{base_url}/plugins" >Plugins</nav-item>
<nav-item href="#{base_url}/tutorials">Tutorials</nav-item>
1  app/views/taglibs/themes/views
View
16 public/javascripts/application.js
View
@@ -1,2 +1,14 @@
-// Place your application-specific JavaScript functions and classes here
-// This file is automatically included by javascript_include_tag :defaults
+
+
+Event.addBehavior({
+ "#version-switcher:change": function(ev) {
+ if(this.value == "1.0") {
+ window.location = "http://cookbook-1.0.hobocentral.net"+window.location.pathname;
+ }
+ }
+});
+
+Event.observe(window, 'load', function() {
+ $("version-switcher").value="1.3";
+});
+
95 public/javascripts/lowpro.js
View
@@ -3,10 +3,10 @@ LowPro.Version = '0.5';
LowPro.CompatibleWithPrototype = '1.6';
if (Prototype.Version.indexOf(LowPro.CompatibleWithPrototype) != 0 && window.console && window.console.warn)
- console.warn("This version of Low Pro is tested with Prototype " + LowPro.CompatibleWithPrototype +
+ console.warn("This version of Low Pro is tested with Prototype " + LowPro.CompatibleWithPrototype +
" it may not work as expected with this version (" + Prototype.Version + ")");
-if (!Element.addMethods)
+if (!Element.addMethods)
Element.addMethods = function(o) { Object.extend(Element.Methods, o) };
// Simple utility methods for working with the DOM
@@ -32,9 +32,9 @@ DOM.Builder = {
create : function(tag, attrs, children) {
attrs = attrs || {}; children = children || []; tag = tag.toLowerCase();
var el = new Element(tag, attrs);
-
+
for (var i=0; i<children.length; i++) {
- if (typeof children[i] == 'string')
+ if (typeof children[i] == 'string')
children[i] = document.createTextNode(children[i]);
el.appendChild(children[i]);
}
@@ -43,14 +43,14 @@ DOM.Builder = {
};
// Automatically create node builders as $tagName.
-(function() {
- var els = ("p|div|span|strong|em|img|table|tr|td|th|thead|tbody|tfoot|pre|code|" +
- "h1|h2|h3|h4|h5|h6|ul|ol|li|form|input|textarea|legend|fieldset|" +
+(function() {
+ var els = ("p|div|span|strong|em|img|table|tr|td|th|thead|tbody|tfoot|pre|code|" +
+ "h1|h2|h3|h4|h5|h6|ul|ol|li|form|input|textarea|legend|fieldset|" +
"select|option|blockquote|cite|br|hr|dd|dl|dt|address|a|button|abbr|acronym|" +
- "script|link|style|bdo|ins|del|object|param|col|colgroup|optgroup|caption|" +
+ "script|link|style|bdo|ins|del|object|param|col|colgroup|optgroup|caption|" +
"label|dfn|kbd|samp|var").split("|");
var el, i=0;
- while (el = els[i++])
+ while (el = els[i++])
window['$' + el] = DOM.Builder.tagFunc(el);
})();
@@ -92,43 +92,51 @@ Object.extend(Event, {
Event.addBehavior = function(rules) {
var ab = this.addBehavior;
Object.extend(ab.rules, rules);
-
+
if (!ab.responderApplied) {
Ajax.Responders.register({
- onComplete : function() {
- if (Event.addBehavior.reassignAfterAjax)
+ onComplete : function() {
+ if (Event.addBehavior.reassignAfterAjax)
setTimeout(function() { ab.reload() }, 10);
}
});
ab.responderApplied = true;
}
-
+
if (ab.autoTrigger) {
this.onReady(ab.load.bind(ab, rules));
}
-
+
};
+Event.delegate = function(rules) {
+ return function(e) {
+ var element = $(e.element());
+ for (var selector in rules)
+ if (element.match(selector)) return rules[selector].apply(this, $A(arguments));
+ }
+}
+
Object.extend(Event.addBehavior, {
rules : {}, cache : [],
reassignAfterAjax : false,
autoTrigger : true,
-
+
load : function(rules) {
for (var selector in rules) {
var observer = rules[selector];
var sels = selector.split(',');
sels.each(function(sel) {
- var parts = sel.split(/:(?=[a-z]+$)/), css = parts[0], event = parts[1];
+ var match = sel.match(/^([^:]*)(?::(.*)$)?/), css = match[1], event = match[2];
$$(css).each(function(element) {
if (event) {
- observer = Event.addBehavior._wrapObserver(observer);
- $(element).observe(event, observer);
- Event.addBehavior.cache.push([element, event, observer]);
+ var wrappedObserver = Event.addBehavior._wrapObserver(observer);
+ $(element).observe(event, wrappedObserver);
+ Event.addBehavior.cache.push([element, event, wrappedObserver]);
} else {
if (!element.$$assigned || !element.$$assigned.include(observer)) {
if (observer.attach) observer.attach(element);
-
+
else observer.call($(element));
element.$$assigned = element.$$assigned || [];
element.$$assigned.push(observer);
@@ -138,26 +146,26 @@ Object.extend(Event.addBehavior, {
});
}
},
-
+
unload : function() {
this.cache.each(function(c) {
Event.stopObserving.apply(Event, c);
});
this.cache = [];
},
-
+
reload: function() {
var ab = Event.addBehavior;
- ab.unload();
+ ab.unload();
ab.load(ab.rules);
},
-
+
_wrapObserver: function(observer) {
return function(event) {
- if (observer.call(this, event) === false) event.stop();
+ if (observer.call(this, event) === false) event.stop();
}
}
-
+
});
Event.observe(window, 'unload', Event.addBehavior.unload.bind(Event.addBehavior));
@@ -169,15 +177,15 @@ $$$ = Event.addBehavior.bind(Event);
// and their behavior. Use Behavior.create() to make a new behavior class then use attach() to
// glue it to an element. Each element then gets it's own instance of the behavior and any
// methods called onxxx are bound to the relevent event.
-//
+//
// Usage:
-//
+//
// var MyBehavior = Behavior.create({
-// onmouseover : function() { this.element.addClassName('bong') }
+// onmouseover : function() { this.element.addClassName('bong') }
// });
//
// Event.addBehavior({ 'a.rollover' : MyBehavior });
-//
+//
// If you need to pass additional values to initialize use:
//
// Event.addBehavior({ 'a.rollover' : MyBehavior(10, { thing : 15 }) })
@@ -197,8 +205,7 @@ var Behavior = {
if (Object.isFunction(properties[0]))
parent = properties.shift();
- var behavior = function() {
- var behavior = arguments.callee;
+ var behavior = function() {
if (!this.initialize) {
var args = $A(arguments);
@@ -207,7 +214,7 @@ var Behavior = {
behavior.attach.apply(behavior, initArgs);
};
} else {
- var args = (arguments.length == 2 && arguments[1] instanceof Array) ?
+ var args = (arguments.length == 2 && arguments[1] instanceof Array) ?
arguments[1] : Array.prototype.slice.call(arguments, 1);
this.element = $(arguments[0]);
@@ -245,13 +252,17 @@ var Behavior = {
return new this(element, Array.prototype.slice.call(arguments, 1));
},
_bindEvents : function(bound) {
- for (var member in bound)
- if (member.match(/^on(.+)/) && typeof bound[member] == 'function')
- bound.element.observe(RegExp.$1, Event.addBehavior._wrapObserver(bound[member].bindAsEventListener(bound)));
+ for (var member in bound) {
+ var matches = member.match(/^on(.+)/);
+ if (matches && typeof bound[member] == 'function')
+ bound.element.observe(matches[1], Event.addBehavior._wrapObserver(bound[member].bindAsEventListener(bound)));
+ }
}
}
};
+
+
Remote = Behavior.create({
initialize: function(options) {
if (this.element.nodeName == 'FORM') new Remote.Form(this.element, options);
@@ -264,11 +275,19 @@ Remote.Base = {
this.options = Object.extend({
evaluateScripts : true
}, options || {});
+
+ this._bindCallbacks();
},
_makeRequest : function(options) {
if (options.update) new Ajax.Updater(options.update, options.url, options);
else new Ajax.Request(options.url, options);
return false;
+ },
+ _bindCallbacks: function() {
+ $w('onCreate onComplete onException onFailure onInteractive onLoading onLoaded onSuccess').each(function(cb) {
+ if (Object.isFunction(this.options[cb]))
+ this.options[cb] = this.options[cb].bind(this);
+ }.bind(this));
}
}
@@ -283,8 +302,8 @@ Remote.Link = Behavior.create(Remote.Base, {
Remote.Form = Behavior.create(Remote.Base, {
onclick : function(e) {
var sourceElement = e.element();
-
- if (['input', 'button'].include(sourceElement.nodeName.toLowerCase()) &&
+
+ if (['input', 'button'].include(sourceElement.nodeName.toLowerCase()) &&
sourceElement.type == 'submit')
this._submitButton = sourceElement;
},
Please sign in to comment.
Something went wrong with that request. Please try again.