BFContribute = function() { this.ERR = 'Sorry, there was a problem processing your request. If it persists please contact support.'; this.ERR_DUPE = 'Woops. It looks like you’ve already contributed this response.'; this.TEXT_ERR = 'Please add your message.'; this.IMAGE_ERR = 'Please add your image and a description.'; this.IMAGE_TOO_LARGE = 'Max image upload size is 2 megabytes.'; this.VIDEO_ERR = 'Please add a valid video link and a description.'; this.QUOTE_ERR = 'Please add a quote and an author.'; this.LINK_ERR = 'Please add a link and a description.'; this.ERR_BLIST = 'An error has occurred. If it keeps happening contact error@buzzfeed.com.'; this.type_list = new Array('text', 'video', 'image', 'link'); this.buzz_data = {}; // indented comment stuff this.subContributeParent = 0; this.main_buzz_username; this.main_buzz_uri; this.main_buzz_id; // init contribute form this.init = function() { // init login form bf_login.init(); var user_info = (new BF_User()).getUserInfo(); if (user_info && typeof user_info.p_disable_comment != 'undefined' && user_info.p_disable_comment == 'true') { $$('#contribute-box').each(function(el) { el.style.display = 'none'; }); return true; } if (! $("contribute-form")) return; var submit_handler = function(event) { event.stop(); bf_contribute.submit(); }.bind(this); bf_contribute.main_buzz_username = $('contribute-username').value; bf_contribute.main_buzz_uri = $('contribute-uri').value; bf_contribute.main_buzz_id = $('contribute-id').value; $('add-something-interesting').observe('click', function(event) { event.stop(); bf_contribute.reset_contribute_box(); } ); $$('.respond').invoke('observe', 'click', bf_contribute.observeRespond); $$('.show-more a').invoke('observe', 'click', bf_contribute.showMoreContribs); $('contribute-form').observe('submit', submit_handler); $('contribute-submit').show(); $('contribute-post').observe('click', function(e) { $('submit-mode').value='save'; } ); $('contribute-submit').observe('click', function(e) { $('submit-mode').value='preview'; } ); var fwipeit = function(type) { return function(event) { event.stop(); bf_contribute_toggleTabs('on'); if ($('respond')) $('respond').removeClassName('previewing'); $('contribute-message').update(''); $('contribute-message').hide(); $('contribute-preview').hide(); $('contribute-form').reset(); $('contribute-cancel').hide(); $('image-button').value = 'Select Image...'; $('contribute-post').hide(); $('contribute-submit').value = 'Preview'; $('contribute-preview-content').update(); }} $('contribute-cancel').observe( 'click', fwipeit(true) ); $('contribute-close-success-box').observe('click', function(e) { $('contribute-success').hide() }); this.goforit_default(); // register toggle evenst var switch_function = function(e) { e.stop(); type = e.element().id.match(/(^\w+)/)[0]; this.disableCurrent(); var button_id = type + '-contribute-activate'; this.buttonToggle(button_id); var form_id = 'contribute-' + type + '-form'; this.enableForm(form_id); if ($('big-pink-arrow')) $('big-pink-arrow').style.display='none'; return false; }.bind(this); // register events on type buttons for(i = 0; i < this.type_list.length; i++) { var id = this.type_list[i] + '-contribute-activate' var element = $(id); if(element) { element.observe('click', function(e) { e.stop(); switch_function(e); return false; }); } } $('create_full_post_toggle').observe('click',function(e){ e.stop(); $$('.full-post-field').invoke('show'); $('create_full_post_toggle').hide(); $('create_simple_post_toggle').show(); }); $('create_simple_post_toggle').observe('click',function(e){ e.stop(); $$('.full-post-field').invoke('hide'); $('create_full_post_toggle').show(); $('create_simple_post_toggle').hide(); }); //register video string parsing event var vid_embed = $('video-embed'); if(vid_embed) { $('video-embed').observe('mouseup', function(){ this.setVideo() }.bindAsEventListener(this) ); $('video-embed').observe('keyup', function(){ this.setVideo() }.bindAsEventListener(this) ); } //register image uplaod event var image_button = $('image-button'); var photo_editor_button = $('photo-editor-button'); if(image_button && Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6) { var image_handler = function(e) { e.stop(); $('image-preview-div').show(); $('image-preview').hide(); if ($('user-loading')) $('user-loading').show(); $('user-image-edit-iframe').src="/static/images/public/spinners/big_on_eee.gif"; $('user-image-edit').addClassName('bf_dialog_confirm'); BF_UI.showDialog('user-image-edit'); $('user-image-edit-iframe').src="/buzzfeed/_edit_user_contribution_image?action=imageform"; }.bindAsEventListener(this); image_button.observe('click', image_handler); image_button.show(); if (photo_editor_button) photo_editor_button.hide(); } //register image upload event if(photo_editor_button) { var editor_handler = function(e) { e.stop(); if ($('user-loading')) $('user-loading').show(); $('user-image-edit-iframe').src="/static/images/public/spinners/big_on_eee.gif"; $('user-image-edit').removeClassName('bf_dialog_confirm'); BF_UI.showDialog('user-image-edit', 'Edit a Photo'); var over_query = ''; if ($('photo_editor_image')) over_query = "&overlay=" + escape( $F('photo_editor_image') ); $('user-image-edit-iframe').src="/buzzfeed/_edit_photo_editor_image?action=imageform" + over_query; }.bindAsEventListener(this); photo_editor_button.observe('click', editor_handler); } //update supoorted video text if($('video-supported-text')) { $('video-supported-text').update(BF_VIDEO_TYPES_STRING); } // Update Hash Tags bf_contribute.update_contribs(); } this.reset_contribute_box = function() { $('contribute-form').reset(); bf_contribute_toggleTabs('on'); $('contribute-cancel').hide(); $('contribute-post').hide(); $('contribute-submit').value = 'Preview'; $('contribute-preview-content').update(); $('contribute-username').setValue(bf_contribute.main_buzz_username); $('contribute-uri').setValue(bf_contribute.main_buzz_uri); $('contribute-id').setValue(bf_contribute.main_buzz_id); $('use_new_comments').setValue(0); var add_interesting = $('add-something-interesting'); add_interesting.parentNode.insertBefore($('contribute-box'), add_interesting.nextSibling); add_interesting.parentNode.insertBefore($('contribute-preview-content'), add_interesting.nextSibling); bf_contribute.subContributeParent = 0; } this.update_contribs = function() { var messages = $$('.contribution-list .what .blurb'); messages.each(function(el) { bf_contribute.create_list_link($(el)); }); } this.create_list_link = function(el) { if (!el || !bf_contribute.buzz_data) return; if (!bf_contribute.fetched_buzz) {bf_contribute.fetch_buzz_data()} var msg = $(el).innerHTML; var reg_p = new RegExp("(#[0-9]+)+(\\D)", 'g'); var reg_m = new RegExp('[^0-9]+', 'g'); var data = bf_contribute.buzz_data; var media_keys = []; while (msg.match(reg_p)) { r = msg.match(reg_p); msg = msg.replaceAll(r[0], ''); key = r[0].replace(reg_m,''); if (data.hasOwnProperty(key)) { var link = ''; link = ''; $(el).innerHTML = $(el).innerHTML.replaceAll(r[0], link + "#" + key + "" + r[0].charAt(r[0].length-1)); if (data[key].btype.match('image|video') && data[key].img && media_keys.indexOf(key) < 0) { $(el).innerHTML = $(el).innerHTML + link + ""; media_keys.push(key); } else if (data[key].btype.match('grid_row') && data[key].img && media_keys.indexOf(key) < 0) { var contrib_grid_html = link.replace('class="scroll"', 'class="scroll contrib_grid_row"'); for (i = 0; i < data[key].img.length; i++) { contrib_grid_html = contrib_grid_html + ""; media_keys.push(key); } $(el).innerHTML = $(el).innerHTML + contrib_grid_html + ""; } } } } this.fetch_buzz_data = function() { $$('.buzz_superlist_item').each(function(el) { var key = $(el).down('.buzz_superlist_number, .buzz_superlist_number_inline') ? $(el).down('.buzz_superlist_number, .buzz_superlist_number_inline').innerHTML.replace('.','') : ""; var content = $(el).down('.sub_buzz_content') ? $(el).down('.sub_buzz_content') : ""; var classname = $(el).className; bf_contribute.buzz_data[key] = { eid: $(el).id, btype: classname.match('image') ? 'image' : classname.match('video') ? 'video' : classname.match('grid_row') ? 'grid_row' : 'na' }; if (bf_contribute.buzz_data[key].btype.match('image')) { var img = $(content).down('img'); bf_contribute.buzz_data[key].img = img.hasAttribute('rel:bf_image_src') && !img.src.match(/_preview.gif/) ? img.getAttribute('rel:bf_image_src') : img.src; } else if (bf_contribute.buzz_data[key].btype.match('video')) { var embed_area = $(content).down('.video-embed-area'); if (embed_area) bf_contribute.buzz_data[key].img = embed_area.getAttribute('rel:thumb'); } else if (bf_contribute.buzz_data[key].btype.match('grid_row')) { bf_contribute.buzz_data[key].img = []; $(el).select('.grid_cell img').each(function(img) { bf_contribute.buzz_data[key].img.push(img.hasAttribute('rel:bf_image_src') && !img.src.match(/_preview.gif/) ? img.getAttribute('rel:bf_image_src') : img.src); }); } }); bf_contribute.fetched_buzz = 1; } // submit form this.submit = function(registered) { //console.log('submit') var user = new BF_User(); if ( !$('contribute-post') ) return false; if ( user.isLoggedIn() && (this.type != 'image' || $F('image-image')) ) $('contribute-post').show(); $('contribute-message').hide(); $('contribute-box').show(); if (this.login_enable_form) { this.login_enable_form = false; this.enableForm('contribute-' + this.type + '-form'); } else { if ($F('submit-mode')=='preview') { $('contribute-cancel').show(); $('contribute-submit').value = 'Preview Again'; if ($('video-preview')) $('video_preview').hide(); } this[this.type + 'Contribution'](registered); } } this.previewFromServer = function( params, registered ) { //console.log('previewFromServer') $('saving-status').show(); var user = new BF_User(); if ( user.isLoggedIn() ) { var userInfo = user.getUserInfo(); params.username = userInfo.username; params.display_name = userInfo.display_name ? userInfo.display_name : userInfo.username; if(userInfo.image && userInfo.image != null && userInfo.image != 'null') { params.user_image = userInfo.image; } else { params.user_image = '/static/images/public/defaults/user_large.jpg'; } } else { params.username = 'You'; params.user_image = '/static/images/public/defaults/user_large.jpg'; } params.action = 'process'; params.template = 'contribution'; params.preview = 'true'; params.since_minutes = '1'; params.static_root = BF_STATIC.static_root; params.image_root = BF_STATIC.image_root; // is child comment? if ( bf_contribute.subContributeParent > 0 ) { params.child_comment = '1'; } var ajax = new BF_Request(); ajax.request('/buzzfeed/_template', { method:'post', parameters:params, onSuccess: function(resp){ //console.log('previewFromServer response') $('contribute-post' ).disabled = false; var user = new BF_User(); var json = resp.responseText; var obj = json.evalJSON(); if ( obj.success ) { var html = obj.snippet; if( !(user.isLoggedIn() || registered) ) { //console.log('previewFromServer response registered') $('contribute-post').show(); } this.preview_contribution(html, obj); } else { var errors = ''; for( var key in obj.errors ) { if ( errors != '' ) errors += ', '; errors += obj.errors[key]; } this.setErrMessage(errors); $('contribute-post').hide(); } $('saving-status').hide(); document.fire("contribute:previewFromServerOk"); }.bind(this), onFailure: function(resp){ ajax.alert('Error contacting server'); $('saving-status').hide() document.fire("contribute:previewFromServerError"); }, bf_auth: true }); } // text contribution this.textContribution = function(registered) { //console.log('textContribution') var text = $F('text-text') ; if( !text ) { this.setErrMessage(this.TEXT_ERR); bf_contribute_toggleTabs('on'); if ( $('contribute-post') ) { $('contribute-post').hide(); } } else { if( $F('submit-mode') == 'save' ) { this.postit( { text: text, new_comments:$F('use_new_comments'), uri:$F('contribute-uri'), id:$F('contribute-id'), username: $F('contribute-username'), type: this.type }, registered); } else { this.previewFromServer({ form:'text', new_comments:$F('use_new_comments'), uri:$F('contribute-uri'), id:$F('contribute-id'), username:$F('contribute-username'), blurb:text },registered); } } } // image contribution this.imageContribution = function(registered) { var text = $F('image-text').strip() ; var image = TT_Filters.html_noentities( $F('image-image').strip() ); var credit = TT_Filters.html_noentities( TT_Filters.link( $F('image-credit').strip() ) ); if (credit && ! credit.match(/^https?:\/\//)) credit = 'http://' + credit; if (credit) credit = this.url_entities(credit); var isMixedPic = (bf_contribute.form == "mixedpic" || bf_contribute.form == "mixedpic_wide") ? true : false; if( ! image || (! text && ! isMixedPic) ) { this.setErrMessage(this.IMAGE_ERR); if ( $('contribute-post') )$('contribute-post').hide(); if ( image ) $('image-preview-div').show(); bf_contribute_toggleTabs('on'); } else { if($F('submit-mode')=='save') { this.postit( { caption: text, image: image, credit_url:credit, image_width: this.image_width, image_height: this.image_height, form: bf_contribute.form||'image', new_comments:$F('use_new_comments'), uri: $F('contribute-uri'), id:$F('contribute-id'), username: $F('contribute-username'), type: this.type }, registered); $('image-preview').hide(); } else { this.previewFromServer({form:'image', new_comments:$F('use_new_comments'), uri:$F('contribute-uri'), id:$F('contribute-id'), username:$F('contribute-username'), credit_url:credit, image_buzz:image, image_buzz_width:this.image_width, image_buzz_height:this.image_height, blurb:text },registered); } } } // video contribution this.videoContribution = function(registered) { var link = TT_Filters.link( $F('video-embed-url').strip() ); var text = TT_Filters.html_noentities( $F('video-text').strip() ); if ( typeof link == 'undefined' ) link = ''; if ( typeof text == 'undefined' ) text = ''; if (link && !link.match(/^https?:\/\//)) link = 'http://' + link; if (! text || ! link) { this.setErrMessage(this.VIDEO_ERR); bf_contribute_toggleTabs('on'); if ( $('contribute-post') ) $('contribute-post').hide(); } else { if($F('submit-mode')=='save') { this.postit( { caption: text, video_url: link, new_comments:$F('use_new_comments'), uri: $F('contribute-uri'), id:$F('contribute-id'), username: $F('contribute-username'), type: this.type }, registered); } else { this.previewFromServer({form:'video', new_comments:$F('use_new_comments'), uri:$F('contribute-uri'), id:$F('contribute-id'), username:$F('contribute-username'), video_url:link, blurb:text },registered); } } } // quote contribution this.quoteContribution = function(registered) { //console.dir({args: registered}); var author = TT_Filters.html_noentities( $F('quote-attribution').strip() ); var text = TT_Filters.html_noentities( $F('quote-text').strip() ); if(! text || ! author) { this.setErrMessage(this.QUOTE_ERR); if ( $('contribute-add-your-response-heading') ) $('contribute-add-your-response-heading').show(); bf_contribute_toggleTabs('on'); if ( $('contribute-post') ) { $('contribute-post').hide(); } } else { var user = new BF_User(); if($F('submit-mode')=='save') { this.previewFromServer({form:'quote', new_comments:$F('use_new_comments'), uri:$F('contribute-uri'), id:$F('contribute-id'), username:$F('contribute-username'), quote_author:author, blurb:text },registered); this.postit( { text: text, quote_author: author, new_comments:$F('use_new_comments'), uri: $F('contribute-uri'), id:$F('contribute-id'), username: $F('contribute-username'), type: this.type }, registered); } else { this.previewFromServer({form:'quote', new_comments:$F('use_new_comments'), uri:$F('contribute-uri'), id:$F('contribute-id'), username:$F('contribute-username'), quote_author:author, blurb:text },registered); } } } // link contribution this.linkContribution = function(registered) { //console.dir({args: registered}); var link = TT_Filters.link( $F('link-url').strip() ); var text = TT_Filters.html_noentities( $F('link-text').strip() ); if ( !text || ! link) { this.setErrMessage(this.LINK_ERR); bf_contribute_toggleTabs('on'); if ( $('contribute-post') ) $('contribute-post').hide(); } else { if ( !link.match(/^https?:\/\//)) link = 'http://' + link; link = this.url_entities(link); if ($F('submit-mode')=='save') { this.postit( { text: text, link: link, new_comments:$F('use_new_comments'), uri: $F('contribute-uri'), id:$F('contribute-id'), username: $F('contribute-username'), type: this.type }, registered); } else { this.previewFromServer({ form:'link', new_comments:$F('use_new_comments'), uri:$F('contribute-uri'), id:$F('contribute-id'), username:$F('contribute-username'), link_buzz:link, blurb:text },registered); } } } this.preview_contribution = function(preview,obj) { //console.log('preview_contribution') var user = new BF_User(); if ($('big-pink-arrow')) $('big-pink-arrow').style.display='none'; if ($('respond')){ $('respond').addClassName('previewing'); } if ( $('image-preview') ) $('image-preview').hide(); $('contribute-preview-content').update( preview.toString() ); bf_contribute_toggleTabs('off'); if( $('who-preview') ) { console.warn('who-form is obsolete?'); //var node = $('who-form').cloneNode(true); //var parent = $('who-preview').parentNode; //parent.removeChild($('who-preview')); //node.id = 'who-preview'; //parent.appendChild( node ); //node.show(); } if (user.isLoggedIn()) { if (((new BF_User()).getUserInfo()).f_ad == 'true') { $$('#contribute-preview-content .contrib')[0].addClassName('ad'); } } if (this.type == 'video') { // child comment var embedVal = $F('video-embed-url'); if (embedVal) { if ( bf_contribute.subContributeParent > 0 ) { var so = BF_initSwfObject( embedVal, {width:575,height:375} ); so.write("video_buzz_element_" + obj.video_preview_uri); } else { var so = BF_initSwfObject( embedVal, {width:605,height:505} ); so.write("video_buzz_element_" + obj.video_preview_uri); } } } // wide image disabled for now. // if (this.type == 'image') { // if (bf_contribute.image_width > 425 && !bf_contribute.subContributeParent) { // $$('#contribute-preview-content .contrib')[0].addClassName('wide'); // } // } bf_contribute.create_list_link($$('#contribute-preview-content .what .blurb')[0]) } this.cleanup_image_registration = function() { if($('contribute-submit-fieldset')) $('contribute-submit-fieldset').show(); $('contribute-submit-fieldset').show(); bf_contribute_toggleTabs('on'); if($('image-preview-div')) $('image-preview-div').show(); if($('video_preview') && $F('video-embed')) $('video_preview').show(); } // response this._response = function( resp ) { //console.log('_response') if ($('contribwhat_')) $('contribwhat_').show(); $('saving-status').hide(); this.goforit_default(); var obj = eval('(' + resp.responseText + ')'); if (obj.updated || (obj.success && obj.success == 1)) { BFW_Util.updateInfoCookie({last_active:obj.last_active}); var user = new BF_User(); var uri = obj.uri; var contrib_uri = 'http://' + BFWebPath() + '/' + user.getUserInfo().username + '/' + uri; var react_cam_comment = (window.bf_react_cam && objExists(bf_react_cam) && objExists(obj.uri) && obj.uri.match(/^reactcam-auto-title/) ? true : false); if( react_cam_comment && obj.commentid ) { this.goforit_reactcam(); contrib_uri = 'http://' + BFWebPath() + '/' + this.params.username + '/' + this.params.uri + '?comment=' + obj.commentid; } if( !this.params.text && this.params.caption ) this.params.text = this.params.caption; if( this.params.type == 'text' ) this.params.form_string = 'responded '; if( this.params.type == 'quote' ) this.params.form_string = ' added a quote '; if( this.params.type == 'link' ) this.params.form_string = ' added a link '; if( this.params.type == 'image') this.params.form_string = ' added an image '; if( this.params.type == 'video') this.params.form_string = ' added a video '; this.params.parent_uri = this.params.uri; this.params.parent_username = this.params.username; this.params.parent_title = $F('parent_name'); this.params.title_is_excerpt = $F('title_is_excerpt'); this.params.parent_blurb = $F('parent_blurb'); this.params.username = $F('current-username'); this.params.uri = obj.uri; //update to saved image for post submit view if (obj.image) { var imgs = $('contribute-preview-content').getElementsByTagName('img'); for (i = 0; i < imgs.length; i++) { if (imgs[i].src.match(/static\/tmp/)) { imgs[i].src = BF_STATIC.image_root + obj.image; break; } } } if (obj.thumb) {this.params.image_src = obj.thumb;} else {this.params.image_src = $('image-thumb').value;} var share_pic = BFWebPath() + this.params.image_src; if( react_cam_comment ) { share_pic = BF_STATIC.image_root + obj.image.replace(/\.gif$/m, '_preview.gif'); } social.contribute(this.params); if ( $('permalink-href') ) { $('permalink-href').setAttribute('href', contrib_uri); $('permalink-href').id += Math.random() * 100000; } if ( $('tools-bar') ) { $('tools-bar').show(); $('tools-bar').id += Math.random() * 100000; } var html = $('contribute-preview-content').cloneNode( true ); html.id += Math.random() * 100000; var element_id = 'highlight-' + Math.floor(Math.random()*100); var li = new Element( 'li', {id:element_id} ); //li.update(html.replace('video-preview-preview','video-preview-preview2')); li.appendChild(html); li.setOpacity(0); if (bf_contribute.subContributeParent != 0) { var respond = li.getElementsByClassName('respond'); if (respond[0]) respond[0].setAttribute('rel:parent_magic_id', this.params.parent_username + ":" + this.params.parent_uri) + ":" + html.id; $("contrib-form-container-" + bf_contribute.subContributeParent).insert({before: li}); } else { var anchors = li.getElementsByTagName('A'); for ( var i = 0; i < anchors.length; i++ ) { if (!anchors[i].className.match('scroll')) { anchors[i].setAttribute('href', contrib_uri); } } $('contribution-list').insert({top:li}); } setTimeout(function(){fadeIn(element_id,0);},100); var number_of_contribs = parseInt($('number_of_contribs').innerHTML) + 1; if (isNaN(number_of_contribs)) number_of_contribs = 1; $('number_of_contribs').update(number_of_contribs); if( number_of_contribs == 1 ) { if ($('number_of_contribs_responses')) $('number_of_contribs_responses').innerHTML = 'Response'; } if( number_of_contribs > 1 ) { if ($('number_of_contribs_responses')) $('number_of_contribs_responses').innerHTML = 'Responses'; } var user = new BF_User(); if( user.isLoggedIn() ) { // Success Box removeAllCssClasses('contribute-success'); $('contribute-success').addClassName(this.params.type); $('contribute-success-shares').childElements().each(function(el) {$(el).remove();}); var tw_desc = "", fb_desc = "", alt_desc = (objExists(obj.cleaned_text) ? obj.cleaned_text : ""); if (react_cam_comment) { if (objExists(BF_STATIC.username) && BF_STATIC.username == 'starbucksfrappuccino') { hashtags = "sipface"; } tw_desc = "I just left a reaction with the Frappuccino® Reaction Cam."; } else if (objExists(obj.cleaned_text)) { tw_desc = obj.cleaned_text; } fb_desc = tw_desc; // Replace registered symbol since it refuses to be encoded!! if (objExists(fb_desc) && fb_desc.indexOf("®")) { fb_desc = fb_desc.replace("®", "®"); } bf_shares.fb_share({ el: $('contribute-success-shares'), title: (objExists(BF_STATIC.buzz_name) ? BF_STATIC.buzz_name : document.title), uri: contrib_uri, size: 'big', picture: share_pic, description: (objExists(fb_desc) ? fb_desc : alt_desc), onclick: (react_cam_comment ? "bf_react_cam.track('contrib_fb_share');" : "") }); bf_shares.tw_tweet({ el: $('contribute-success-shares'), title: (objExists(BF_STATIC.buzz_name) ? BF_STATIC.buzz_name : document.title), uri: contrib_uri, size: 'big', picture: share_pic, description: tw_desc, hashtags: (typeof hashtags != 'undefined' ? hashtags : ""), onclick: (react_cam_comment ? "bf_react_cam.track('contrib_tw_share');" : "") }); bf_shares.email_link({ el: $('contribute-success-shares'), size: 'big', subject: (objExists(BF_STATIC.buzz_name) ? BF_STATIC.buzz_name : document.title), body: (objExists(fb_desc) ? fb_desc : alt_desc) + "%0D%0A" + contrib_uri, onclick: (react_cam_comment ? "bf_react_cam.track('contrib_email_share');" : "") }); $(element_id).insert($('contribute-success')); $('contribute-success').show(); } else { $('contribute-box').hide(); if( $('reg-success-message') ) $('reg-success-message').update(bf_register.SUCCESS1); $('registered-success').show(); } BF_Effect.ScrollIntoView(element_id); $('number_of_contribs_header').show(); $('contribute-post').hide(); $('contribute-preview').hide(); $('contribute-form').reset(); bf_contribute.reset_contribute_box(); $('contribute-preview-content').update(); bf_contribute_toggleTabs('on'); // if (window['FORMULA']) { FORMULA.submit('contribution'); } gtrack.trackShares(25, 'numComments'); // Push 2 GA gtrack.track_events(gtrack.tt_page + ":contribute", "contribute/submit", ""); } else if (obj.error == 'duplicate name') {this.setErrMessage(this.ERR_DUPE);} else if (obj.error == 'blacklist') {this.setErrMessage(this.ERR_BLIST);} else {this.setErrMessage(this.ERR);} } this.postit = function(params, registered) { //console.log('postit', params, registered) var user = new BF_User(); if( !user.isLoggedIn() && !registered ) { $('submit-mode').value='save'; signin.callbacks.onLogin.push(function(){ //post response this.submit(); //update anonymous template with user info var user_info = (new BF_User()).getUserInfo(); $$('#contribwhat_ .avatar img')[0].src = user_info.image; $$('#contribwhat_ .who-info .notranslate')[0].innerHTML = user_info.display_name }.bind(this)); signin.callbacks.onRegister.push(function(obj,json){ this[this.type + 'Contribution'](json); }.bind(this)); signin.open( { signin_type: 'initial', mode: 'contribution', location: 'contribution' } ); if (Prototype.Browser.IE8) $$('.signin_overlay')[0].scrollIntoView(); return false; } $('saving-status').show(); this.params = params; var success_handler = function(resp) { this._response(resp); document.fire("contribute:postitOk"); }.bindAsEventListener(this); var error_handler = function(resp) { this.server_error(resp) document.fire("contribute:postitError"); }.bindAsEventListener(this); // Hack for Florida OJ if ( params.form == 'mixedpic' && ( params.id == 1860073 || params.id == 1927310 || params.id == 1984234 ) ) { this.use_minisuper(params); } else { if(params.text) params.text = params.text; if(params.title) params.title = params.title; if(params.caption) params.caption = params.caption; // inject targetting pixel (new BF_Targetting_Pixel()).add('comment'); if(registered) params.session_key = registered.session_key; else params.session_key = BFW_Util.getCookie(BFW_COOKIE); if ( typeof this.delete_images != 'undefined' && this.delete_images=='no') params.delete_images = this.delete_images; var args = { method: 'post', parameters: params, onSuccess: success_handler, onFailure: error_handler } var user_info = (new BF_User()).getUserInfo(); // in case user register and contribute at the same time if ( user_info.username ) args.needsToken = true; var ajax = new BF_Request(); $('contribute-post' ).disabled = true; ajax.request('/buzzfeed/_contribute', args); $('contribute-submit').value = 'Preview'; } } this.use_minisuper = function(params) { var description = 'auto-title_' + (new Date()).getTime(); var name = 'auto-title_' + (new Date()).getTime(); if ( params.caption ) { description = params.caption; name = truncateStr(params.caption, 100); } var parameters = { action: 'save', name: name, description: description, image: params.image, width: params.image_width, height: params.image_height }; parameters['submit-to'] = 364333; parameters['auto-tag'] = params.id == 1927310 ? 'floridaoj2' : params.id == 1984234 ? 'floridaoj3' : 'floridaoj'; var success_handler = function(resp) { this._response(resp); }.bindAsEventListener(this); var error_handler = function(resp) { console.log(resp); this.server_error(resp); }.bindAsEventListener(this); new Ajax.Request('/buzzfeed/minisuper', { parameters: parameters, evalJSON: 'force', onFailure: error_handler, onSuccess: success_handler }); } this.setVideo = function() { var vd = new bf2_terminal_Video(); vd.detect_type( $F('video-embed') ); $$('#contribute-video-form .video_privacy_warning').each(function(el) {el.hide();}); if(vd.type) { var url = vd.src_link, so = BF_initSwfObject(url) so.write("video_preview"); if ( $('video_preview') ) $('video_preview').show(); $('video-embed-url').value = url; if (!!vd.possible_privacy_restrictions) $$('#contribute-video-form .video_privacy_warning').each(function(el) {el.show();}); } else { if ($('video_preview')) $('video_preview').update(''); if ($('video_preview')) $('video_preview').hide(); $('video-embed-url').value = ''; } } this.save_image = function(image, width, height, form) { $('user-image-edit').removeClassName('bf_wide_canvas'); BF_UI.closeDialog('user-image-edit',{loadDefaultDiv:'quickpost-spinner'}); $('image-image').value = image; bf_contribute.image_width = width; bf_contribute.image_height = height; if (form) bf_contribute.form = form; $('image-preview').show(); $('image-preview').src = BF_STATIC.image_root + image; if (width > 425) { $('image-preview').setStyle({width: '425px', height: 'auto'}); } else { if (height) $('image-preview').setStyle({height: height+'px'}); } $('image-preview-div').show(); $('photo-editor-button').value = 'Change Image...'; } // enable selected from this.enableForm = function(id) { if(! $(id)) return; $(id).show(); this.currentForm = id; this.type = id.match(/\-(\w+)/)[1]; this.login_enable_form = false; } // toggle offcurrent button this.buttonToggle = function(id) { if(! $(id)) return; $(id).addClassName('current'); this.currentToggle = id; if( id != 'image-contribute-activate' ) { this.cleanup_image_registration(); } } // hide current form this.disableCurrent = function() { $(this.currentForm).hide(); if(this.currentToggle != undefined) { $(this.currentToggle).removeClassName('current'); } } this.setErrMessage = function(err) { $('contribute-message').update(err); $('contribute-message').addClassName('error'); $('contribute-message').show(); $('contribute-submit').disabled = false; } this.server_error = function(resp) { $('saving-status').hide(); console.log(2); this.setErrMessage(this.ERR); } this.addLineBreaks = function(string) { string = string.replace(/(\r|\r\n|\n){2,}/gm, ' <\/span>'); string = string.replace(/(\r|\r\n|\n)/gm, '
'); return string; } this.url_entities = function(s) { if(s) { var newtext = ''; var chars = s.split(""); for(i = 0; i < chars.length; i++) { var chr = chars[i].charCodeAt(0); if( chr > 127 ) { newtext += encodeURIComponent(chars[i]); } else { newtext += chars[i]; } } return newtext; } } this.observeRespond = function(event) { event.stop(); bf_contribute.reset_contribute_box(); var parent_magic_id = this.getAttribute('rel:parent_magic_id'); var parent_id = $(parent_magic_id).getAttribute('rel:buzz_id'); var parent_data = eval('(' + $(parent_magic_id).getAttribute('track') + ')'); var new_comments_mode = $(parent_magic_id).getAttribute('rel:new_contribution') || 0; $('contribute-username').setValue(parent_data.user); $('contribute-uri').setValue(parent_data.buzz); $('contribute-id').setValue(parent_id); $('use_new_comments').setValue(new_comments_mode); $('contrib-form-container-' + parent_id).appendChild($('contribute-preview-content'));; $('contrib-form-container-' + parent_id).appendChild($('contribute-box'));; bf_contribute.subContributeParent = parent_id; } this.showMoreContribs = function(event) { event.stop(); var ajax = new BF_Request(); var show_more = this; var parent_magic_id = show_more.getAttribute('rel:parent_magic_id'); var parent_id = $(parent_magic_id).getAttribute('rel:buzz_id'); var spinner = document.createElement('DIV'); var spinner_img = document.createElement('IMG'); spinner.setAttribute('id', 'load_more_spinner'); spinner.setAttribute('style', 'text-align: center;'); spinner_img.setAttribute('src', '/static/images/public/spinners/loading.gif'); spinner.appendChild(spinner_img); show_more.parentNode.insert({before: spinner}); show_more.parentNode.style.visibility = 'hidden'; var success_handler = function(resp) { var obj = resp.responseText.evalJSON(); $('contrib-form-container-' + parent_id).insert({before: obj.html}); show_more.parentNode.remove(); spinner.remove(); bf_post_tools.init(); report_manager.init(); badge_vote_manager.init(); $$('.respond').invoke('observe', 'click', bf_contribute.observeRespond); } var error_handler = function(resp) { show_more.parentNode.style.visibility = 'visible'; spinner.remove(); console.log(resp); this.server_error(resp) }.bindAsEventListener(this); ajax.request( (BF_STATIC ? BF_STATIC.web_root : '') + '/_loadcomments/' + parent_id + '.js', { method: 'post', onSuccess: success_handler, onFailure: error_handler }); } this.goforit_default = function() { $('contribute-again-link').stopObserving('click'); $('contribute-again-link').observe('click', function(e){ e.stop(); if ($('contribution-types-tab')) $('contribution-types-tab').show(); if ($('add-something-interesting')) $('add-something-interesting').show(); if ($('respond')) $('respond').removeClassName('previewing'); $('contribute-preview').hide(); $('contribute-submit-fieldset').show(); bf_contribute_toggleTabs('on'); $('contribute-form').reset(); $('contribute-box').show(); $('contribute-success').hide(); $('contribute-cancel').hide(); $('image-button').value = 'Select Image...'; BF_Effect.ScrollIntoView('respond'); }); }; this.goforit_reactcam = function() { $('contribute-again-link').stopObserving('click'); $('contribute-again-link').observe('click', function(e){ e.stop(); $('contribute-success').hide(); BF_Effect.ScrollIntoView('react_cam_button'); document.fire("contribute:goforit_reactcam"); }); }; } fadeIn = function(id,opacity) { $(id).setOpacity(opacity/100); if(opacity < 100) { setTimeout("fadeIn('"+id+"',"+(opacity+2)+")",5); } }; bf_contribute_toggleTabs = function( on_or_off ) { if( on_or_off == 'on' ) { if ($('contribution-types-tab')) $('contribution-types-tab').show(); if ($('add-something-interesting')) $('add-something-interesting').show(); } else { if ($('contribution-types-tab')) $('contribution-types-tab').hide(); // if ($('add-something-interesting')) $('add-something-interesting').hide(); } } var bf_contribute = new BFContribute(); bf_contribute.init();