BlogToolbarControl = Class.create(); BlogToolbarControl.prototype = { initialize:function() { this.statusResponder = $("statusResponder"); Ajax.Responders.register(this); this.blogUI = $("addBlogsUI"); this.controladdBlogs = null; Event.observe("subscribe_tool", "click", this.showAddBlogForm.bindAsEventListener(this)); this.suggestFeedContainer = $("suggestFeedContainer"); this.controlSuggestFeed = null; Event.observe("suggest_tool", "click", this.showFeedSuggestForm.bindAsEventListener(this)); var uLinks = $$("a.KillWidget"); var len = uLinks.length; for(var i = 0; i < len; i++){ var strID = new String(uLinks[i].id); strID = strID.gsub("killwidget_", ""); Event.observe(uLinks[i], "click", this.unsubscribe.bindAsEventListener(this, strID), false);}
}, closeBlogList:function(evt) { Effect.toggle(this.blogUI, "blind", {duration:0.4});}, showAddBlogForm:function(evt) { var req = new Ajax.Request("/feeds/SubscribeForm.cfm", { method:"post", onSuccess:this.onShowAddBlogForm.bindAsEventListener(this)
}); Event.stop(evt);}, onShowAddBlogForm:function(trans) { this.blogUI.hide(); this.blogUI.innerHTML = trans.responseText; try { this.controladdBlogs = new WidgetControl('addBlogs'); this.controladdBlogs.registerEventHandlers(); Effect.toggle(this.blogUI, "blind"); var fLinks = $$("a.subscribeTo"); len = fLinks.length; for(i = 0; i < len; i++) { fLinks[i] = $(fLinks[i]); strID = new String(fLinks[i].id); strID = strID.gsub("feed_", ""); Event.observe(fLinks[i], "click", this.fetchFeedInit.bindAsEventListener(this, strID), false);}
this.closeBlogList_btn = $("killwidget_BlogList"); Event.observe(this.closeBlogList_btn, "click", this.closeBlogList.bindAsEventListener(this));} catch(e) {}
}, fetchFeedInit:function(evt, feedID) { var params = $H({feedID:feedID}); var req = new Ajax.Request("feeds/SubscribeAjax.cfm", { parameters:params, method:"post", onSuccess:this.fetchFeedFinish.bindAsEventListener(this, feedID), onFailure:function(transport) { }
}); Event.stop(evt); return false;}, fetchFeedFinish:function(transport, fid) { $("feed_" + fid).innerHTML = "Blog added"; new Insertion.Top($("newFeeds"), transport.responseText);}, showFeedSuggestForm:function() { var req = new Ajax.Request("feeds/SuggestFeedForm.cfm", { method:"post", onSuccess:this.onShowFeedSuggestForm.bindAsEventListener(this)
});}, onShowFeedSuggestForm:function(trans) { this.suggestFeedContainer.hide(); this.suggestFeedContainer.innerHTML = trans.responseText; Effect.toggle(this.suggestFeedContainer, "Blind", {duration:0.4}); Event.observe("btn_feedSuggest", "click", this.suggestFeedInit.bindAsEventListener(this), false); Event.observe("btn_feedSuggestClose", "click", this.suggestFeedClose.bindAsEventListener(this), false);}, suggestFeedClose:function(evt) { Effect.toggle(this.suggestFeedContainer, "Blind", {duration:0.4});}, unsubscribe:function(evt, feedID){ var params = $H({feedID:feedID}); var req = new Ajax.Request("feeds/UnsubscribeAjax.cfm", { parameters:params, method:"post", onSuccess:this.removeFeed.bind(this)
}); Event.stop(evt);}, suggestFeedInit:function(e) { var params = $H({suggestfeed:$F("suggestfeed")}); var req = new Ajax.Request("feeds/SuggestFeedAjax.cfm", { parameters:params, method:"post", onSuccess:this.suggestFeedFinish.bindAsEventListener(this)
}); Event.stop(e); return false;}, suggestFeedFinish:function(transport) { var s = $("suggestthanks"); s.hide(); s.innerHTML = transport.responseText; Effect.toggle(s, 'Blind', {afterFinish:this.startSuggestHide.bindAsEventListener(this)});}, startSuggestHide:function() { Effect.toggle(this.suggestFeedContainer, "Blind", {duration:0.4, delay:2.0});}, removeFeed:function(transport) { var json = new String(transport.responseText).strip(); json = $H(json.evalJSON()); var fid = json.FEEDID; $("module" + fid).remove(); Effect.toggle("module" + fid, "Blind", {duration:0.4,afterFinish:this.onFeedFadeFinish.bind(fid)});}, onFeedFadeFinish:function(fid) { $("module" + fid).remove();}, registerFeed:function(fid) { var m = $("module" + fid); m.hide(); Effect.toggle(m, "blind", {duration:0.4}); Event.observe("killwidget_" + fid, "click", this.unsubscribe.bindAsEventListener(this, fid));}, onCreate:function() { if(Ajax.activeRequestCount > 0) { this.statusResponder.show();}
}, onComplete:function() { if(!Ajax.activeRequestCount) { this.statusResponder.hide();}
}
}; FeedControl = Class.create(); FeedControl.prototype = { initialize:function(vId, qtyEntries, entriesPerPage) { this.id = vId; this.view = new FeedView(this.id); Event.observe(this.view.nextLinks, "click", this.nextPage.bindAsEventListener(this)); Event.observe(this.view.prevLinks, "click", this.prevPage.bindAsEventListener(this)); this.model = new FeedModel(this.id, this.view); this.model.setCurrentPage(1); this.model.setQtyEntries(qtyEntries); this.model.setEntriesPerPage(entriesPerPage);}, nextPage:function(evt) { var thisPage = this.model.getCurrentPage(); var start = this.model.getEntriesPerPage() * (thisPage + 1); var params = $H({feedID:this.id,start:start,qtyEntries:this.model.getEntriesPerPage()}); var req = new Ajax.Request("feeds/getBlogPageAjax.cfm", { method:"post", parameters:params, onSuccess:this.onLoadPage.bindAsEventListener(this)
}); this.model.setCurrentPage(thisPage + 1); Event.stop(evt);}, prevPage:function(evt) { var thisPage = this.model.getCurrentPage(); var start = this.model.getEntriesPerPage() * (thisPage - 1); var params = $H({feedID:this.id,start:start,qtyEntries:this.model.getEntriesPerPage()}); var req = new Ajax.Request("feeds/getBlogPageAjax.cfm", { method:"post", parameters:params, onSuccess:this.onLoadPage.bindAsEventListener(this)
}); this.model.setCurrentPage(thisPage - 1); Event.stop(evt);}, onLoadPage:function(trans) { this.model.setData(trans.responseText);}
}; FeedModel = Class.create(); FeedModel.prototype = { initialize:function(vId, fView) { this.id = vId; this.view = fView; this.data = "";}, setCurrentPage:function(vPage) { this.currentPage = vPage; this.view.updatePageNav(this.currentPage, this.qtyEntries, this.entriesPerPage);}, getCurrentPage:function() { return this.currentPage;}, setQtyEntries:function(qty) { this.qtyEntries = qty;}, getQtyEntries:function() { return this.qtyEntries;}, setEntriesPerPage:function(epp) { this.entriesPerPage = epp;}, getEntriesPerPage:function() { return this.entriesPerPage;}, setData:function(vData) { this.data = vData; this.view.update(this.data);}
}; FeedView = Class.create(); FeedView.prototype = { initialize:function(vId) { this.id = vId; this.nextLinks = $("nl" + this.id); this.prevLinks = $("pl" + this.id); this.liveregion = $("entries" + this.id); this.initTips();}, initTips:function() { $$("#entries" + this.id + " li a").each(function(element) { try { new Tip(element, $(element.rel).innerHTML, { effect:"appear", duration:0.5, hook: {target:"bottomRight",tip:"topLeft"}
});}catch(ex){}
});}, update:function(upd) { new Effect.Opacity(this.liveregion, {from:1.0, to:0.0, duration:0.5, afterFinish:this.onLiveRegionFadeOut.bind(this, upd)});}, onLiveRegionFadeOut:function(upd) { this.liveregion.update(upd); new Effect.Opacity(this.liveregion, {from:0.0, to:1.0, duration:0.6}); this.initTips();}, updatePageNav:function(vPage, qtyEntries, entriesPerPage) { if(vPage > 1) { this.prevLinks.show();} else { this.prevLinks.hide();}
if(qtyEntries < ((vPage * entriesPerPage) + entriesPerPage)) { this.nextLinks.hide();} else { this.nextLinks.show();}
}
}; WidgetControl = Class.create(); WidgetControl.prototype = { initialize:function(vId) { this.id = vId; this.view = new WidgetView(vId); this.model = new WidgetModel(this.view, vId);}, registerEventHandlers:function() { try { Event.observe(this.view.refresh_tool, "click", this.refreshModel.bindAsEventListener(this), false);} catch (e) { }
try { Event.observe(this.view.collapse_tool, "click", this.toggleCollapse.bindAsEventListener(this), false);} catch (e) { }
}, refreshModel:function(evt) { var params = $H({blogid:this.id}); Event.stop(evt); var req = new Ajax.Request(""); return false;}, onLoadModel:function(transport) { var data = $H(String(transport.responseText).decode())
}, isOpen:function() { var c = $A(this.view.collapse_tool.classNames()); var isOpen = false; for(var i = 0; i < c.length; i++) { if(c[i] == "CollapseOpen") { isOpen = true;}
}
return isOpen;}, toggleCollapse:function(evt) { Effect.toggle(this.view.content, "Blind"); var isOpen = this.isOpen(); if(isOpen) { this.view.collapse_tool.removeClassName("CollapseOpen"); this.view.collapse_tool.addClassName("CollapseClosed");} else { this.view.collapse_tool.removeClassName("CollapseClosed"); this.view.collapse_tool.addClassName("CollapseOpen");}
Event.stop(evt); return false;}
}; WidgetModel = Class.create(); WidgetModel.prototype = { initialize:function(vView, vId) { this.view = vView; this.id = vId;}, set:function(vName, val) { this[vName] = val; this.view.update(vName, val);}, get:function(vName) { return this[vName];}
}; WidgetView = Class.create(); WidgetView.prototype = { initialize:function(vId) { this.id = vId; this.initUI();}, initUI:function() { try { this.module = $("module" + this.id);} catch(e) { }
try { this.widget = $("widget_" + this.id);} catch(e) { }
try{ this.widgetTitle = $("wtitle_" + this.id);} catch(e) { }
try{ this.widgetTitleMeta = $("wqty_" + this.id);} catch(e) { }
try { this.toolbar = $("wtools_" + this.id);} catch(e) { }
try { this.refresh_tool = $("refreshwidget_" + this.id);} catch(e) { }
try { this.kill_tool = $("killwidget_" + this.id);} catch(e) { }
try { this.collapse_tool = $("widgecollapse_" + this.id);} catch(e) { }
try { this.content = $("widgecont_" + this.id);} catch (e) { }
}, update:function(vName, val) { switch(vName) { case "id":
this.initUI(); break;}
}
}; var Tips = { tips: [], zIndex: 1200, add: function(tip) { this.tips.push(tip);}, remove: function(element) { var tip = this.tips.find(function(t){ return t.element == $(element);}); if (!tip) return; this.tips = this.tips.reject(function(t) { return t==tip;}); tip.deactivate(); if(tip.tooltip) tip.wrapper.remove(); if(tip.underlay) tip.underlay.remove();}
}
var Tip = Class.create(); Tip.prototype = { initialize: function(element, content) { this.element = $(element); Tips.remove(this.element); this.content = content; this.options = Object.extend({ className: 'tooltip', duration: 0.3, effect: false, hook: false, offset: (arguments[2] && arguments[2].hook) ? {x:0, y:0} : {x:16, y:16}, fixed: false, target: this.element, title: false, viewport: true
}, arguments[2] || {}); this.target = $(this.options.target); if (this.options.hook) { this.options.fixed = true; this.options.viewport = false;}
if (this.options.effect) { this.queue = { position: 'end', limit: 1, scope: ''}
var c = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; for (var i=0; i<6; i++) { var r = Math.floor(Math.random() * c.length); this.queue.scope += c.substring(r,r+1);}
}
this.buildWrapper(); Tips.add(this); this.activate();}, activate: function() { this.eventShow = this.showTip.safeBind(this); this.eventHide = this.hideTip.safeBind(this); this.element.observe('mousemove', this.eventShow); this.element.observe('mouseout', this.eventHide);}, deactivate: function() { this.element.stopObserving('mousemove', this.eventShow); this.element.stopObserving('mouseout', this.eventHide);}, buildWrapper: function() { this.wrapper = document.createElement('div'); Element.setStyle(this.wrapper, { position: 'absolute', zIndex: Tips.zIndex+1, display: 'none'
}); if (Prototype.Browser.IE) { this.underlay = document.createElement('iframe'); this.underlay.src = 'javascript:;'; Element.setStyle(this.underlay, { position: 'absolute', display: 'none', border: 0, margin: 0, opacity: 0.01, padding: 0, background: 'none', zIndex: Tips.zIndex
});}
}, buildTip: function() { if(Prototype.Browser.IE) document.body.appendChild(this.underlay); this.tooltip = this.wrapper.appendChild(document.createElement('div')); this.tooltip.className = this.options.className; this.tooltip.style.position = 'relative'; if (this.options.title) { this.title = this.tooltip.appendChild(document.createElement('div')); this.title.className = 'title'; Element.update(this.title, this.options.title);}
this.tip = this.tooltip.appendChild(document.createElement('div')); this.tip.className = 'content'; Element.update(this.tip, this.content); document.body.appendChild(this.wrapper); var w = this.wrapper.getDimensions(); this.wrapper.setStyle({ width: w.width+'px', height: w.height+'px' }); if (Prototype.Browser.IE) this.underlay.setStyle({ width: w.width+'px', height: w.height+'px' }); Element.hide(this.tooltip);}, showTip: function(event){ if (!this.tooltip) this.buildTip(); this.positionTip(event); if (this.wrapper.visible() && this.options.effect != 'appear') return; if (Prototype.Browser.IE) this.underlay.show(); this.wrapper.show(); if (!this.options.effect) { this.tooltip.show();} else { if (this.activeEffect) Effect.Queues.get(this.queue.scope).remove(this.activeEffect); this.activeEffect = Effect[Effect.PAIRS[this.options.effect][0]](this.tooltip, { duration: this.options.duration, queue: this.queue});}
}, hideTip: function(event){ if(!this.wrapper.visible()) return; if (!this.options.effect) { if (Prototype.Browser.IE) { this.underlay.hide();}
this.tooltip.hide(); this.wrapper.hide();}
else { if (this.activeEffect) Effect.Queues.get(this.queue.scope).remove(this.activeEffect); this.activeEffect = Effect[Effect.PAIRS[this.options.effect][1]](this.tooltip, { duration: this.options.duration, queue: this.queue, afterFinish: function(){ if (Prototype.Browser.IE) this.underlay.hide(); this.wrapper.hide();}.bind(this)});}
}, positionTip: function(event){ var offset = {'left': this.options.offset.x,'top': this.options.offset.y}; var targetPosition = Position.cumulativeOffset(this.target); var tipd = this.wrapper.getDimensions(); var pos = { 'left': (this.options.fixed) ? targetPosition[0] : Event.pointerX(event), 'top': (this.options.fixed) ? targetPosition[1] : Event.pointerY(event)
}
pos.left += offset.left; pos.top += offset.top; if (this.options.hook) { var dims = {'target': this.target.getDimensions(), 'tip': tipd}
var hooks = {'target': Position.cumulativeOffset(this.target), 'tip': Position.cumulativeOffset(this.target)}
for(var z in hooks) { switch(this.options.hook[z]){ case 'topRight':
hooks[z][0] += dims[z].width; break; case 'bottomLeft':
hooks[z][1] += dims[z].height; break; case 'bottomRight':
hooks[z][0] += dims[z].width; hooks[z][1] += dims[z].height; break;}
}
pos.left += -1*(hooks.tip[0] - hooks.target[0]); pos.top += -1*(hooks.tip[1] - hooks.target[1]);}
if (!this.options.fixed && this.element !== this.target) { var elementPosition = Position.cumulativeOffset(this.element); pos.left += -1*(elementPosition[0] - targetPosition[0]); pos.top += -1*(elementPosition[1] - targetPosition[1]);}
if (!this.options.fixed && this.options.viewport) { var scroll = this.getScrollOffsets(); var viewport = this.viewportSize(); var pair = {'left': 'width', 'top': 'height'}; for(var z in pair) { if ((pos[z] + tipd[pair[z]] - scroll[z]) > viewport[pair[z]]) { pos[z] = pos[z] - tipd[pair[z]] - 2*offset[z];}
}
}
this.wrapper.setStyle({ left: pos.left + 'px', top: pos.top + 'px'
}); if (Prototype.Browser.IE) this.underlay.setStyle({ left: pos.left+'px', top: pos.top+'px' });}, viewportWidth: function(){ if (Prototype.Browser.Opera) return document.body.clientWidth; return document.documentElement.clientWidth;}, viewportHeight: function(){ if (Prototype.Browser.Opera) return document.body.clientHeight; if (Prototype.Browser.WebKit) return this.innerHeight; return document.documentElement.clientHeight;}, viewportSize : function(){ return {'height': this.viewportHeight(), 'width': this.viewportWidth()};}, getScrollLeft: function(){ return this.pageXOffset || document.documentElement.scrollLeft;}, getScrollTop: function(){ return this.pageYOffset || document.documentElement.scrollTop;}, getScrollOffsets: function(){ return {'left': this.getScrollLeft(), 'top': this.getScrollTop()}
}
}
Function.prototype.safeBind = function() { var __method = this, args = $A(arguments), object = args.shift(); return function() { if (typeof $A == 'function')
return __method.apply(object, args.concat($A(arguments)));}
}; 
