changes
[appoyo.git] / public / javascripts / facebooker.js
blob9890ecb898dcb081eb6e6f3747e24bfe99bdd3af
2 function $(element) {
3 if (typeof element == "string") {
4 element=document.getElementById(element);
6 if (element)
7 extend_instance(element,Element);
8 return element;
11 function extend_instance(instance,hash) {
12 for (var name in hash) {
13 instance[name] = hash[name];
17 var Element = {
18 "hide": function () {
19 this.setStyle("display","none")
21 "show": function () {
22 this.setStyle("display","block")
24 "visible": function () {
25 return (this.getStyle("display") != "none");
27 "toggle": function () {
28 if (this.visible) {
29 this.hide();
30 } else {
31 this.show();
36 function encodeURIComponent(str) {
37 if (typeof(str) == "string") {
38 return str.replace(/=/g,'%3D').replace(/&/g,'%26');
40 //checkboxes and radio buttons return objects instead of a string
41 else if(typeof(str) == "object"){
42 for (prop in str)
44 return str[prop].replace(/=/g,'%3D').replace(/&/g,'%26');
49 var Form = {};
50 Form.serialize = function(form_element) {
51 return $(form_element).serialize();
54 Ajax.Updater = function (container,url,options) {
55 this.container = container;
56 this.url=url;
57 this.ajax = new Ajax();
58 this.ajax.requireLogin = 1;
59 if (options["onSuccess"]) {
60 this.ajax.responseType = Ajax.JSON;
61 this.ajax.ondone = options["onSuccess"];
62 } else {
63 this.ajax.responseType = Ajax.FBML;
64 this.ajax.ondone = function(data) {
65 $(container).setInnerFBML(data);
68 if (options["onFailure"]) {
69 this.ajax.onerror = options["onFailure"];
72 if (!options['parameters']) {
73 options['parameters'] = {}
76 // simulate other verbs over post
77 if (options['method']) {
78 options['parameters']['_method'] = options['method'];
81 this.ajax.post(url,options['parameters']);
82 if (options["onLoading"]) {
83 options["onLoading"].call()
86 Ajax.Request = function(url,options) {
87 Ajax.Updater('unused',url,options);
90 PeriodicalExecuter = function (callback, frequency) {
91 setTimeout(callback, frequency *1000);
92 setTimeout(function() { new PeriodicalExecuter(callback,frequency); }, frequency*1000);