Skip to content

Instantly share code, notes, and snippets.

@jboesch
jboesch / x.js
Created October 16, 2009 13:50
/* This is a template command. */
CmdUtils.CreateCommand({
names: ["rss"],
icon: "http://www.feedicons.com/favicon.ico",
description: "A nice and quick way to browse RSS feeds.",
help: "Type 'rss' then the url of the site. example: rss www.boedesign.com. If there are multiple feeds you know of try doing rss www.boedesign.com(2) to get another feed.",
author: {name: "Jordan Boesch", email: "jboesch26@gmail.com"},
license: "GPL",
homepage: "http://boedesign.com.com/",
arguments: [{role: 'object', nountype: noun_arb_text}],
/**********************************************************************************
*
* @author Jordan Boesch
* @version 1.2
* @link http://boedesign.com/blog/2010/02/13/hijacking-javascriptjquery-methods/
* @date Feb 20, 2010
*
* Hijack is a little snippet of code that allows you to hijack arguments passed to
* functions/methods. Not only can you alter arguments, but you call the old method
* from within the hijacked function (2nd param) and 'return false' if you want to call the
@jboesch
jboesch / gist:310785
Created February 22, 2010 04:32 — forked from rkatic/gist:310747
(function($){
$.each(["live", "die"], function( i, name ) {
var method = $.fn[ name ];
$.fn[ name ] = function( types, data, fn, origSelector ) {
if ( typeof types === "object" && !types.preventDefault ) {
for ( var key in types ) {
method.call( this, key, data, types[key], origSelector );
}
// Examples can be found here: http://boedesign.com/misc/outer_setters.html
// Discussed here: http://forum.jquery.com/topic/outerheight-int-sets-the-height-taking-into-account-padding-and-border
(function($){
function _outerSetter(direction, args){
var $el = $(this),
$sec_el = $(args[0]),
dir = (direction == 'Height') ? ['Top', 'Bottom'] : ['Left', 'Right'],
/**
* Allow for some super easy templating
* @param {Object} ctx The context when you pass in an object literal
* ------------------------------------------------------------------
* Works like this:
* var People = { name: 'bob', age: 123 }
* var my_tpl = "Hi, my name is {{ name }} and I'm {{ age }} years old."
* my_tpl.template(People); // Outputs: "Hi, my name is bob and I'm 123 years old";
*/
String.prototype.template = function(data){
var Template = {
// Keep track of used selector text to prevent re-quering the DOM
_cache: {},
/**
* If you've already called this.draw() on a certain template and don't want to lose your data, you
* can append some more data by calling append()
* @param {String} tpl The template string that you created with draw();
* @param {Object} data The data you're passing
(function($){
window.App = {
// Site wide options
opts = {
rootURL: '/'
};
// Pass in any options to 'o' and merge it with global defaults
/*
Have you ever used Graphael Pie chart (http://g.raphaeljs.com/) and found that when you use a really long legend label, it sometimes goes right off the screen and your chart doesn't align with it? This fixes that.
It calculates the graph x to center align the labels with the chart. This only works if you position the pie chart 'south' or 'north' in the 'legendpos' option.
*/
var legend = ['Awesome', 'Legend', 'Labels whoa this is long'];
legend.sort(function(a, b){ return a.length < b.length; });
var longest_word = legend[0].length;
var x_offset = 1.5; // This might be different in your case. Mess around with it.
// This is just an example of a quick way of setting up a new instance with an automatic call to "init"
//
// Create our attachClass method
Object.prototype.attachClass = function(name, o){
this[name] = function(){
if(typeof(this.__init) == 'function'){
this.__init.apply(this, arguments);
}
}
this[name].prototype = o;
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Mustache JS - Template in script block instead of js variable</title>
<script type="text/javascript" src="http://github.com/janl/mustache.js/raw/master/mustache.js"></script>
</head>
<body>