0
-var HomeMarksUtilities = {
0
- getRequestMood: function(request) {
0
- return (request.status >= 200 && request.status < 300) ? 'good' : 'bad';
0
- messagesToAlert: function(request) {
0
- var messages = request.responseJSON;
0
- var alertText = messages.join(".\n");
0
- if (alertText.endsWith('.')) { alert(alertText); } else { alert(alertText+'.'); };
0
- messagesToList: function(request) {
0
- var messages = request.responseJSON;
0
- var messageList = UL();
0
- messages.each(function(message){
0
- messageList.appendChild( LI(message.escapeHTML()) );
0
- scroll: function() { return document.viewport.getScrollOffsets(); },
0
- pageSize: function() {
0
- if (window.innerHeight && window.scrollMaxY) {
0
- xScroll = window.innerWidth + window.scrollMaxX;
0
- yScroll = window.innerHeight + window.scrollMaxY;
0
- } else if (document.body.scrollHeight > document.body.offsetHeight){
0
- xScroll = document.body.scrollWidth;
0
- yScroll = document.body.scrollHeight;
0
- xScroll = document.body.offsetWidth;
0
- yScroll = document.body.offsetHeight;
0
- var windowWidth, windowHeight;
0
- if (self.innerHeight) {
0
- if(document.documentElement.clientWidth){
0
- windowWidth = document.documentElement.clientWidth;
0
- windowWidth = self.innerWidth;
0
- windowHeight = self.innerHeight;
0
- } else if (document.documentElement && document.documentElement.clientHeight) {
0
- windowWidth = document.documentElement.clientWidth;
0
- windowHeight = document.documentElement.clientHeight;
0
- } else if (document.body) {
0
- windowWidth = document.body.clientWidth;
0
- windowHeight = document.body.clientHeight;
0
- if(yScroll < windowHeight){
0
- pageHeight = windowHeight;
0
- if(xScroll < windowWidth){
0
- pageWidth = windowWidth;
0
- return { width: pageWidth, height: pageHeight };
0
-var HomeMarksSite = Class.create(HomeMarksUtilities,{
0
- initialize: function() {
0
- this.ajaxFrom = $('ajaxforms_wrapper');
0
- this.ajaxFromLinks = $$('.ajaxform_link');
0
- this.supportForm = $('support_form');
0
- this.loginForm = $('login_form');
0
- this.signupForm = $('signup_form');
0
- this.flashes = $$('div.flash_message');
0
- clearFlashes: function() {
0
- this.flashes.invoke('hide');
0
- this.flashes.invoke('update','');
0
- flash: function(mood,html) {
0
- var moodFlash = this.flashes.find(function(e){ if (e.id == 'flash_'+mood) {return true}; });
0
- moodFlash.update(html);
0
- $('site_wrapper').scrollTo();
0
- toggleAjaxFormBlind: function(event) {
0
- if (event) { event.element().blur(); };
0
- Effect.toggle(this.ajaxFrom, 'blind', {duration:0.4});
0
- startAjaxForm: function(event) {
0
- var form = event.findElement('form');
0
- var options = Object.extend({loadId:'form_loading',imgSrc:'loading_invert.gif'}, arguments[1] || {});
0
- var imgTag = IMG({src:('/images/'+options.imgSrc)});
0
- $(options.loadId).update(imgTag);
0
- new Ajax.Request(form.action,{
0
- onComplete: function(request){ this.delegateCompleteAjaxForm(form,request) }.bind(this),
0
- parameters: form.serialize(true)
0
- delegateCompleteAjaxForm: function(form,request) {
0
- var mood = this.getRequestMood(request);
0
- this.completeAjaxForm(form,{mood:mood});
0
- case this.supportForm : this.completeSupportForm(request);
0
- case this.loginForm : this.completeLoginForm(request);
0
- case this.signupForm : this.completeSignupForm(request);
0
- var flashHtml = DIV([H2('Errors:'),this.messagesToList(request)]);
0
- this.flash('bad',flashHtml);
0
- completeAjaxForm: function(form) {
0
- var options = Object.extend({loadId:'form_loading',mood:'good'}, arguments[1] || {});
0
- var completeId = 'complete_ajax_form_' + options.loadId;
0
- var imgSrc = '/images/'+options.mood+'.png';
0
- var moodHtml = SPAN({id:completeId,className:'m0 p0'}, [IMG({src:imgSrc})]);
0
- $(options.loadId).update(moodHtml);
0
- setTimeout(function() { $(completeId).fade(); },3000);
0
- submitSupportForm: function(event) {
0
- this.startAjaxForm(event,{imgSrc:'loading.gif'});
0
- completeSupportForm: function(request) {
0
- setTimeout(function(){ this.supportForm.reset(); this.supportForm.enable(); }.bind(this),2000);
0
- this.toggleAjaxFormBlind();
0
- this.flash('good','Thanks for submitting a support request!');
0
- completeLoginForm: function(request) {
0
- window.location = '/myhome'
0
- completeSignupForm: function(request) {
0
- var flashHTML = DIV([H2('Signup Complete:'),P('We have sent an email with a link to verify and activate your account. You can not login unless you verify your email address.')]);
0
- this.flash('good',flashHTML);
0
- initEvents: function() {
0
- if (this.supportForm) { this.supportForm.observe('submit', this.submitSupportForm.bindAsEventListener(this)); };
0
- if (this.loginForm) { this.loginForm.observe('submit', this.startAjaxForm.bindAsEventListener(this)); };
0
- if (this.signupForm) { this.signupForm.observe('submit', this.startAjaxForm.bindAsEventListener(this)); };
0
- this.ajaxFromLinks.each(function(element){
0
- element.observe('click', this.toggleAjaxFormBlind.bindAsEventListener(this));
0
-// WindowUtilities.getWindowScroll() // => { top: 0, left: 0, width: 1002, height: 464 }
0
-// document.viewport.getDimensions() // => { width: 987, height: 494 }
0
-// document.viewport.getWidth() // => 987
0
-// document.viewport.getHeight() // => 494
0
-// document.viewport.getScrollOffsets() // => [0, 0]
0
-// WindowUtilities.getPageSize() // => { pageWidth: 1002, pageHeight: 3129, windowWidth: 1002 }
0
-// WindowUtilities.getPageSize() // => [987,3129]
0
-var HomeMarksModal = Class.create(HomeMarksUtilities,{
0
- initialize: function(contents) {
0
- this.contents = contents || 'misc' // ['box','bookmark']
0
- this.mask = $('modalmask');
0
- this.progress = $('modal_progress');
0
- this.wrapper = $('modal_html_ap-wrapper');
0
- this.content = $('modal_html_rel-wrapper');
0
- this.queue = {position:'end', scope:'modalscope'};
0
- miscContents: function() { return this.contents == 'misc'; },
0
- boxContents: function() { return this.contents == 'box'; },
0
- bookmarkContents: function() { return this.contents == 'bookmark'; },
0
- this.toggleMask('on');
0
- this.toggleProgress('on');
0
- this.toggleObservers('on');
0
- // document.stopObserving('keypress', actionAreaHelper);
0
- // if (this.action_bar().hasClassName('barout')) { toggleActionArea('inbox'); }
0
- destroy: function(boxid) {
0
- this.toggleObservers('off');
0
- this.toggleProgress('off');
0
- this.toggleMask('off');
0
- // document.observe('keypress', actionAreaHelper);
0
- centerMask: function() {
0
- this.mask.setStyle({height: this.pageSize().height + 'px'});
0
- this.progress.setStyle({top: (this.scroll().top + 60) + 'px'});
0
- centerModal: function() {
0
- left = (( this.pageSize().width - this.width() ) / 2).ceil();
0
- if (left < 0) left = 0;
0
- this.wrapper.setStyle({left: left+'px'});
0
- switch (this.contents) {
0
- case 'misc' : return 450;
0
- case 'box' : return 652;
0
- case 'bookmark' : return 352;
0
- toggleMask: function(toggle) {
0
- this.mask.appear({duration:0.4, from:0.0, to:0.9, queue:this.queue});
0
- // May not need visible check.
0
- if (this.content.visible()) { this.content.slideUp({duration:0.4, queue:this.queue}); };
0
- this.mask.fade({duration:0.2, queue:this.queue});
0
- toggleObservers: function(toggle) {
0
- Event.observe(window, 'resize', this.center.bindAsEventListener(this));
0
- Event.observe(window, 'scroll', this.center.bind(this));
0
- document.observe('keypress', this.keypress.bind(this));
0
- Event.stopObserving(window, 'resize', this.center);
0
- Event.stopObserving(window, 'scroll', this.center);
0
- document.stopObserving('keypress', this.keypress);
0
- toggleProgress: function(toggle) {
0
- var options = {duration:0.2, queue:this.queue}
0
- if (toggle == 'on') { this.progress.appear(options); } else { this.progress.fade(options); };
0
- keypress: function(event) {
0
- if (event.keyCode == Event.KEY_ESC) { this.destroy(); };
0
- var maskHTML = DIV({id:'modalmask',style:'display:none;'},[DIV({id:'modal_progress',style:'display:none;'})]);
0
- var modalHTML = DIV({id:'modal_html_ap-wrapper'},[DIV({id:'modal_html_rel-wrapper',style:'display:none;'})]);
0
- // hideModal: function(boxid) {
0
- // boxid = (boxid == null) ? 'bookmarklet' : boxid;
0
- // Event.stopObserving(document, 'keypress', respondtoKeypress);
0
- // Effect.SlideUp(modalContent, {duration:0.4, queue:{position:'end', scope:'boxid_' + boxid}});
0
- // Effect.Appear(modalProgress, {duration:0.2, from:0.0, to:0.9, queue:{position:'end', scope:'boxid_' + boxid}});
0
- // destroyModalMask: function(boxid) {
0
- // boxid = (boxid == null) ? 'bookmarklet' : boxid;
0
- // Event.stopObserving(window, 'resize', centerStuff);
0
- // Event.stopObserving(window, 'scroll', centerStuff);
0
- // Effect.Fade(modalMask, {duration:0.2, queue:{position:'end', scope:'boxid_' + boxid}});
0
- // goHere: function() {
0
- // window.location.reload();
0
-document.observe('dom:loaded', function(){
0
- HmSite = new HomeMarksSite();
0
- // HmModal = new HomeMarksModal();