Skip to content

Instantly share code, notes, and snippets.

@codebrew
Created September 30, 2011 00:18
Show Gist options
  • Save codebrew/1252323 to your computer and use it in GitHub Desktop.
Save codebrew/1252323 to your computer and use it in GitHub Desktop.
olark sample
// create a top level olark object
(function() {
var root = this;
var previousOlark = root.Olark;
var Olark = root.Olark = {};
// console isnt available on all browsers at all times, so stub it out
root.console || (root.console = {log : function() {} });
// Runs Olark in *noConflict* mode, returning the `Olark` variable
// to its previous owner. Returns a reference to this Olark object.
Olark.noConflict = function() {
root.Olark = previousOlark;
return Olark;
};
Olark.inspectObject = function (object) {
// make sure to add var before any variable or else it becomes global
for (var key in object) {
console.log("the attribute " + key + " is equal to " + object[key]);
}
};
Olark.Widget = function() {this.foo = "bar"};
}).call(this);
// client could now do this on their page
// client's favorite word is olark
// so they have olark globals everywhere, but thats ok, they can still use our lib in no conflict mode
$(function() {
var $o = Olark.noConflict();
$o.inspectObject(new $o.Widget);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment