1 var Container = Class.create();
2 Container.prototype = {
5 initialize: function() {
6 // rpc services our container supports
7 gadgets.rpc.register('resize_iframe', this.setHeight);
8 gadgets.rpc.register('set_pref', this.setUserPref);
9 gadgets.rpc.register('set_title', this.setTitle);
10 gadgets.rpc.register('requestNavigateTo', this.requestNavigateTo);
13 setHeight: function(height) {
14 if ($(this.f) != undefined) {
15 // compensate for margin/padding offsets in some browsers (ugly hack but functional)
17 // change the height of the gadget iframe, limit to maxHeight height
18 if (height > gadgets.container.maxHeight) {
19 height = gadgets.container.maxHeight;
21 Element.setStyle($(this.f), {'height':height+'px'});
25 _parseIframeUrl: function(url) {
26 // parse the iframe url to extract the key = value pairs from it
27 var ret = new Object();
28 var hashParams = url.replace(/#.*$/, '').split('&');
29 var param = key = val = '';
30 for (i = 0 ; i < hashParams.length; i++) {
31 param = hashParams[i];
32 key = param.substr(0, param.indexOf('='));
33 val = param.substr(param.indexOf('=') + 1);
39 setUserPref: function(editToken, name, value) {
40 // we use the security token to tell our backend who this is (app/mod/viewer)
41 // since it's the only fail safe way of doing so
42 if ($(this.f) != undefined) {
43 var params = gadgets.container._parseIframeUrl($(this.f).src);
44 //TODO use params.st to make the store request, it holds the owner / viewer / app id / mod id required
45 new Ajax.Request('./mods/social/set_prefs.php', {method: 'get', parameters: { name: name, value: value, st: params.st }});
49 setTitle: function(title) {
50 var element = $(this.f+'_title');
51 if (element != undefined) {
52 // update the title, and make sure we don't break it's html
53 element.update(title.replace(/&/g, '&').replace(/</g, '<'));
57 _getUrlForView: function(view, person, app, mod) {
58 if (view === 'home') {
60 } else if (view === 'profile') {
61 return '/sprofile.php?id='+person;
62 } else if (view === 'canvas') {
63 return './mods/social/applications.php?app_id='+app;
69 requestNavigateTo: function(view, opt_params) {
70 if ($(this.f) != undefined) {
71 var params = gadgets.container._parseIframeUrl($(this.f).src);
72 var url = gadgets.container._getUrlForView(view, params.owner, params.aid, params.mid);
74 var paramStr = Object.toJSON(opt_params);
75 if (paramStr.length > 0) {
76 url += '?appParams=' + encodeURIComponent(paramStr);
79 if (url && document.location.href.indexOf(url) == -1) {
80 document.location.href = url;
87 * Create the container class on page load
89 gadgets.container = new Container();