home *** CD-ROM | disk | FTP | other *** search
- Glydo.Sharing = Prototype.Class.create({
- initialize: function(application) {
- this.application = application;
- this.localizedStrings = new Glydo.Utils.LocalizedBundle(document);
- this.url = null;
- this.title = null;
- this.buildPopups();
- },
-
- buildPopups: function() {
- var doc = this.application.window.document;
- var elems = doc.getElementsByClassName("glydo-sharing-popup");
- for (var i = 0; i < elems.length; ++i) {
- var elem = elems[i];
- var kind = elem.getAttribute("rel");
- this.buildPopup(doc,elem,kind);
- }
- },
-
- buildPopup: function(doc,root,kind) {
- var nServices = Glydo.Sharing.GLOBAL_SETTINGS.services.length;
- for (var i = 0; i < nServices; ++i) {
- var service = Glydo.Sharing.GLOBAL_SETTINGS.services[i];
- this.addItemToPopup(doc,root,service,kind);
- }
- this.addItemToPopup(doc,root,null,kind);
- },
-
- addItemToPopup: function(doc,root,service,kind) {
- var item = doc.createElement('menuitem');
- item.className = "menuitem-iconic glydo-sharing-item glydo-sharing-" + (service ? "item-" + service : "more");
- item.setAttribute("label",this.localizedStrings.get("sharing." + (service ? "item." + service : "more") + ".label"));
- item.addEventListener("command",Prototype.F.bind(Prototype.F.curry(this.share,service,kind),this),false);
- root.appendChild(item);
- },
-
- onMenu: function(event) {
- if (event.type == "popupshowing") {
- var popupNode = document.popupNode;
- if (!popupNode) {
- return false;
- }
- if (popupNode.rec) {
- this.application.detachedPopupsManager.onContextMenu(event);
- } else {
- var doc = this.application.window.content.document;
- if (doc) {
- var url = doc.documentURI;
- if (!Prototype.S.startsWith(url,"http://") && !Prototype.S.startsWith(url,"https://")) {
- Glydo.Utils.promptService().alert(null,this.localizedStrings.get("sharing.blocked_page.title"),this.localizedStrings.get("sharing.blocked_page.message"));
- return false;
- }
- }
- }
- return true;
- }
- },
-
- share: function(service,kind) {
- var url;
- var title;
- if (kind == "recommendation") {
- var popupNode = this.application.getContextRecommendationLink();
- if (!popupNode) {
- return;
- }
- var rec = popupNode.rec;
- url = popupNode.href;
- title = Glydo.Utils.unescapeHTMLIfNecessary(popupNode.rec.title);
- if (rec) {
- var rek = Glydo.Utils.getAncestorOrSelfAttributeOrProperty(popupNode,'realEstateKind');
- var rep = Glydo.Utils.getAncestorOrSelfAggregateAttributeOrProperty(popupNode,'realEstatePosition');
- Glydo.LOGGING_DB.logRecAction(rec.recSetId,rec.id,"SHARE",service,rek,rep);
- }
- } else if (kind == "current"){
- var doc = this.application.window.content.document;
- if (!doc) {
- return;
- }
- url = url || doc.documentURI;
- title = title || doc.title;
-
- if (!Prototype.S.startsWith(url,"http://") && !Prototype.S.startsWith(url,"https://")) {
- Glydo.Utils.promptService().alert(null,this.localizedStrings.get("sharing.blocked_page.title"),this.localizedStrings.get("sharing.blocked_page.message"));
- return;
- }
- Glydo.LOGGING_DB.logUserEvent("application.sharing.current",
- "share", { service: service }, null);
- } else if (kind == "app"){
- url = "http://www.glydo.com/";
- Glydo.LOGGING_DB.logUserEvent("application.sharing.app",
- "share", { service: service }, null);
- } else {
- return;
- }
- if (url) {
- var template = this.getTemplate(service,kind);
- var title = this.getTitle(title,service,kind);
- Glydo.Sharing.share(url,title,service,template);
- }
- },
-
- getTemplate: function(service,kind) {
- if (!service) {
- return null;
- }
- var ret = this.localizedStrings.get('sharing.' + kind + '.item.'+service+'.template');
- ret = ret || this.localizedStrings.get('sharing.' + kind + '.defaults.template');
- return ret;
- },
-
- getTitle: function(title,service,kind) {
- if (!service) {
- return null;
- }
- if (!title) {
- return this.localizedStrings.get('sharing.' + kind + '.defaults.notitle');
- }
- var ret = this.localizedStrings.get('sharing.' + kind + '.item.'+service+'.title',[title]);
- ret = ret || this.localizedStrings.get('sharing.' + kind + '.defaults.title',[title]);
- return ret;
- }
-
- });
-
- // Global sharing function
- Glydo.Sharing.share = function(url,title,service,template) {
- if (!url) {
- return;
- }
- var encURL = encodeURIComponent(url);
- var shareURL = Glydo.Sharing.GLOBAL_SETTINGS.baseShareURL + "&pub=" + Glydo.Sharing.GLOBAL_SETTINGS.encAccount + "&url=" + encURL;
- if (service) {
- var encService = encodeURIComponent(service);
- shareURL += "&s=" + encService;
- }
- if (title !== null && title !== undefined) {
- var encTitle = encodeURIComponent(title);
- shareURL += "&title=" + encTitle;
- }
- if (template) {
- var encTmpl = encodeURIComponent(template);
- shareURL += "&template=" + encTmpl;
- }
- Glydo.WindowUtils.goToURL(window,shareURL,'new-tab');
- }
-
- //FIXME: Templates should be localized
- Glydo.Sharing.GLOBAL_SETTINGS = ({
- services: ['twitter','facebook','myspace','bebo','buzz','digg','delicious','friendfeed','google','live'],
- encAccount: "glydo",
- baseShareURL: "http://www.addthis.com/bookmark.php?v=250"
- });