Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Last active August 29, 2015 14:14
Show Gist options
  • Save JudeRosario/dca19241b585a3fde676 to your computer and use it in GitHub Desktop.
Save JudeRosario/dca19241b585a3fde676 to your computer and use it in GitHub Desktop.
BP & Activity+ NoConflict
<script>
$.noConflict();
// Explicitly put code in noConflict mode and wrap around with ready.fn.()
jQuery( document ).ready(function( $ ) {
var _bpfbActiveHandler=false;(function(e){e(function(){function u(){var e='<div class="bpfb_actions_container bpfb-theme-'+_bpfb_data.theme.replace(/[^-_a-z0-9]/ig,"")+" bpfb-alignment-"+_bpfb_data.alignment.replace(/[^-_a-z0-9]/ig,"")+'">'+'<div class="bpfb_toolbar_container">'+'<a href="#photos" class="bpfb_toolbarItem" title="'+l10nBpfb.add_photos+'" id="bpfb_addPhotos"><span>'+l10nBpfb.add_photos+"</span></a>"+"&nbsp;"+'<a href="#videos" class="bpfb_toolbarItem" title="'+l10nBpfb.add_videos+'" id="bpfb_addVideos"><span>'+l10nBpfb.add_videos+"</span></a>"+"&nbsp;"+'<a href="#links" class="bpfb_toolbarItem" title="'+l10nBpfb.add_links+'" id="bpfb_addLinks"><span>'+l10nBpfb.add_links+"</span></a>"+"</div>"+'<div class="bpfb_controls_container">'+"</div>"+'<div class="bpfb_preview_container">'+"</div>"+'<div class="bpfb_action_container">'+"</div>"+'<input type="button" id="bpfb_cancel_action" value="'+l10nBpfb.cancel+'" style="display:none" />'+"</div>";t.wrap('<div class="bpfb_form_container" />');r.after(e)}function a(){t=e("#whats-new-form");n=t.find('textarea[name="whats-new"]');r=t.find("#whats-new-textarea");u();e("#bpfb_addPhotos").click(function(){if(_bpfbActiveHandler)_bpfbActiveHandler.destroy();_bpfbActiveHandler=new o;e("#bpfb_cancel_action").show();return false});e("#bpfb_addLinks").click(function(){if(_bpfbActiveHandler)_bpfbActiveHandler.destroy();_bpfbActiveHandler=new s;e("#bpfb_cancel_action").show();return false});e("#bpfb_addVideos").click(function(){if(_bpfbActiveHandler)_bpfbActiveHandler.destroy();_bpfbActiveHandler=new i;e("#bpfb_cancel_action").show();return false});e("#bpfb_cancel_action").click(function(){e(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active");_bpfbActiveHandler.destroy();e("#bpfb_cancel_action").hide();return false});e(".bpfb_toolbarItem").click(function(){e(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active");e(this).addClass("bpfb_active")});e(document).on("click","#bpfb_submit",function(){var t=_bpfbActiveHandler.get();var r=e("#whats-new-post-in").length?e("#whats-new-post-in").val():0;e.post(ajaxurl,{action:"bpfb_update_activity_contents",data:t,content:n.val(),group_id:r},function(t){_bpfbActiveHandler.destroy();n.val("");e("#activity-stream").prepend(t.activity);e(".bpfb_final_link img").each(function(){e(this).width(e(this).parents("div").width())})})});e(document).on("click","#bpfb_cancel",function(){e(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active");_bpfbActiveHandler.destroy()})}var t;var n;var r;var i=function(){$container=e(".bpfb_controls_container");var t=function(){e("#bpfb_video_url").width($container.width())};var n=function(){var n='<input type="text" id="bpfb_video_url" name="bpfb_video_url" placeholder="'+l10nBpfb.paste_video_url+'" value="" />'+'<input type="button" id="bpfb_video_url_preview" value="'+l10nBpfb.preview+'" />';$container.empty().append(n);e(window).off("resize.bpfb").on("resize.bpfb",t);t();e("#bpfb_video_url").focus(function(){e(this).select().addClass("changed")});e("#bpfb_video_url").keypress(function(e){if(13!=e.which)return true;r();return false});e("#bpfb_video_url").change(r);e("#bpfb_video_url_preview").click(r)};var r=function(){var t=e("#bpfb_video_url").val();if(!t)return false;e(".bpfb_preview_container").html('<div class="bpfb_waiting"></div>');e.post(ajaxurl,{action:"bpfb_preview_video",data:t},function(t){e(".bpfb_preview_container").empty().html(t);e(".bpfb_action_container").html('<p><input type="button" class="button-primary bpfb_primary_button" id="bpfb_submit" value="'+l10nBpfb.add_video+'" /> '+'<input type="button" class="button" id="bpfb_cancel" value="'+l10nBpfb.cancel+'" /></p>');e("#bpfb_cancel_action").hide()})};var i=function(){return{bpfb_video_url:e("#bpfb_video_url").val()}};var s=function(){e("#aw-whats-new-submit").hide();n()};var o=function(){$container.empty();e(".bpfb_preview_container").empty();e(".bpfb_action_container").empty();e("#aw-whats-new-submit").show();e(window).off("resize.bpfb")};s();return{destroy:o,get:i}};var s=function(){$container=e(".bpfb_controls_container");var t=function(){e("#bpfb_link_preview_url").width($container.width())};var n=function(){var n='<input type="text" id="bpfb_link_preview_url" name="bpfb_link_preview_url" placeholder="'+l10nBpfb.paste_link_url+'" value="" />'+'<input type="button" id="bpfb_link_url_preview" value="'+l10nBpfb.preview+'" />';$container.empty().append(n);e(window).off("resize.bpfb").on("resize.bpfb",t);t();e("#bpfb_link_preview_url").focus(function(){e(this).select().addClass("changed")});e("#bpfb_link_preview_url").keypress(function(e){if(13!=e.which)return true;i();return false});e("#bpfb_link_preview_url").change(i);e("#bpfb_link_url_preview").click(i)};var r=function(t){if(!t.url){e(".bpfb_preview_container").empty().html(t.title);return false}var n="";e.each(t.images,function(e,r){if(!r)return true;var i=r.match(/^http/)?r:t.url+"/"+r;n+='<img class="bpfb_link_preview_image" src="'+i+'" />'});var r='<table border="0">'+"<tr>"+"<td>"+'<div class="bpfb_link_preview_container">'+n+'<input type="hidden" name="bpfb_link_img" value="" />'+"</div>"+"</td>"+"<td>"+'<div class="bpfb_link_preview_title">'+t.title+"</div>"+'<input type="hidden" name="bpfb_link_title" value="'+t.title+'" />'+'<div class="bpfb_link_preview_url">'+t.url+"</div>"+'<input type="hidden" name="bpfb_link_url" value="'+t.url+'" />'+'<div class="bpfb_link_preview_body">'+t.text+"</div>"+'<input type="hidden" name="bpfb_link_body" value="'+t.text+'" />'+'<div class="bpfb_thumbnail_chooser">'+'<span class="bpfb_left"><img class="bpfb_thumbnail_chooser_left" src="'+_bpfb_data.root_url+'/img/system/left.gif" />&nbsp;</span>'+'<span class="bpfb_thumbnail_chooser_label">'+l10nBpfb.choose_thumbnail+"</span>"+'<span class="bpfb_right">&nbsp;<img class="bpfb_thumbnail_chooser_right" src="'+_bpfb_data.root_url+'/img/system/right.gif" /></span>'+'<br /><input type="checkbox" id="bpfb_link_no_thumbnail" /> <label for="bpfb_link_no_thumbnail">'+l10nBpfb.no_thumbnail+"</label>"+"</div>"+"</td>"+"</tr>"+"</table>";e(".bpfb_preview_container").empty().html(r);e(".bpfb_action_container").html('<p><input type="button" class="button-primary bpfb_primary_button" id="bpfb_submit" value="'+l10nBpfb.add_link+'" /> '+'<input type="button" class="button" id="bpfb_cancel" value="'+l10nBpfb.cancel+'" /></p>');e("#bpfb_cancel_action").hide();e("img.bpfb_link_preview_image").hide();e("img.bpfb_link_preview_image").first().show();e('input[name="bpfb_link_img"]').val(e("img.bpfb_link_preview_image").first().attr("src"));e(".bpfb_thumbnail_chooser .bpfb_left").click(function(){var t=e("img.bpfb_link_preview_image:visible");var n=t.prev(".bpfb_link_preview_image");if(n.length){t.hide();n.width(e(".bpfb_link_preview_container").width()).show();e('input[name="bpfb_link_img"]').val(n.attr("src"))}return false});e(".bpfb_thumbnail_chooser .bpfb_right").click(function(){var t=e("img.bpfb_link_preview_image:visible");var n=t.next(".bpfb_link_preview_image");if(n.length){t.hide();n.width(e(".bpfb_link_preview_container").width()).show();e('input[name="bpfb_link_img"]').val(n.attr("src"))}return false});e("#bpfb_link_no_thumbnail").click(function(){if(e("#bpfb_link_no_thumbnail").is(":checked")){e("img.bpfb_link_preview_image:visible").hide();e('input[name="bpfb_link_img"]').val("");e(".bpfb_left, .bpfb_right, .bpfb_thumbnail_chooser_label").hide()}else{var t=e("img.bpfb_link_preview_image:first");t.show();e(".bpfb_left, .bpfb_right, .bpfb_thumbnail_chooser_label").show();e('input[name="bpfb_link_img"]').val(t.attr("src"))}})};var i=function(){var t=e("#bpfb_link_preview_url").val();if(!t)return false;e(".bpfb_preview_container").html('<div class="bpfb_waiting"></div>');e.post(ajaxurl,{action:"bpfb_preview_link",data:t},function(e){r(e)})};var s=function(){return{bpfb_link_url:e('input[name="bpfb_link_url"]').val(),bpfb_link_image:e('input[name="bpfb_link_img"]').val(),bpfb_link_title:e('input[name="bpfb_link_title"]').val(),bpfb_link_body:e('input[name="bpfb_link_body"]').val()}};var o=function(){e("#aw-whats-new-submit").hide();n()};var u=function(){$container.empty();e(".bpfb_preview_container").empty();e(".bpfb_action_container").empty();e("#aw-whats-new-submit").show();e(window).off("resize.bpfb")};o();return{destroy:u,get:s}};var o=function(){$container=e(".bpfb_controls_container");var t=function(){var t='<div id="bpfb_tmp_photo"> </div>'+'<ul id="bpfb_tmp_photo_list"></ul>'+'<input type="button" id="bpfb_add_remote_image" value="'+l10nBpfb.add_remote_image+'" /><div id="bpfb_remote_image_container"></div>'+'<input type="button" id="bpfb_remote_image_preview" value="'+l10nBpfb.preview+'" />';$container.append(t);var i=new qq.FileUploader({element:e("#bpfb_tmp_photo")[0],listElement:e("#bpfb_tmp_photo_list")[0],allowedExtensions:["jpg","jpeg","png","gif"],action:ajaxurl,params:{action:"bpfb_preview_photo"},onSubmit:function(t){if(!parseInt(l10nBpfb._max_images,10))return true;t=parseInt(t,10);if(!t)t=e("img.bpfb_preview_photo_item").length;if(!t)return true;if(t<parseInt(l10nBpfb._max_images,10))return true;if(!e("#bpfb-too_many_photos").length)e("#bpfb_tmp_photo").append('<p id="bpfb-too_many_photos">'+l10nBpfb.images_limit_exceeded+"</p>");return false},onComplete:r,template:'<div class="qq-uploader">'+'<div class="qq-upload-drop-area"><span>'+l10nBpfb.drop_files+"</span></div>"+'<div class="qq-upload-button">'+l10nBpfb.upload_file+"</div>"+'<ul class="qq-upload-list"></ul>'+"</div>"});e("#bpfb_remote_image_preview").hide();e("#bpfb_tmp_photo").click(function(){if(e("#bpfb_add_remote_image").is(":visible"))e("#bpfb_add_remote_image").hide()});e("#bpfb_add_remote_image").click(function(){if(!e("#bpfb_remote_image_preview").is(":visible"))e("#bpfb_remote_image_preview").show();if(e("#bpfb_tmp_photo").is(":visible"))e("#bpfb_tmp_photo").hide();e("#bpfb_add_remote_image").val(l10nBpfb.add_another_remote_image);e("#bpfb_remote_image_container").append('<input type="text" class="bpfb_remote_image" size="64" value="" /><br />');e("#bpfb_remote_image_container .bpfb_remote_image").width($container.width())});e(document).on("change","#bpfb_remote_image_container .bpfb_remote_image",n);e("#bpfb_remote_image_preview").click(n)};var n=function(){var t=[];e("#bpfb_remote_image_container .bpfb_remote_image").each(function(){t[t.length]=e(this).val()});e.post(ajaxurl,{action:"bpfb_preview_remote_image",data:t},function(t){var n="";e.each(t,function(){n+='<img class="bpfb_preview_photo_item" src="'+this+'" width="80px" />'+'<input type="hidden" class="bpfb_photos_to_add" name="bpfb_photos[]" value="'+this+'" />'});e(".bpfb_preview_container").html(n)});e(".bpfb_action_container").html('<p><input type="button" class="button-primary bpfb_primary_button" id="bpfb_submit" value="'+l10nBpfb.add_photos+'" /> '+'<input type="button" class="button" id="bpfb_cancel" value="'+l10nBpfb.cancel+'" /></p>');e("#bpfb_cancel_action").hide()};var r=function(t,n,r){if("error"in r)return false;var i='<img class="bpfb_preview_photo_item" src="'+_bpfb_data.temp_img_url+r.file+'" width="80px" />'+'<input type="hidden" class="bpfb_photos_to_add" name="bpfb_photos[]" value="'+r.file+'" />';e(".bpfb_preview_container").append(i);e(".bpfb_action_container").html('<p><input type="button" class="button-primary bpfb_primary_button" id="bpfb_submit" value="'+l10nBpfb.add_photos+'" /> '+'<input type="button" class="button" id="bpfb_cancel" value="'+l10nBpfb.cancel+'" /></p>');e("#bpfb_cancel_action").hide()};var i=function(t){var n=e("input.bpfb_photos_to_add");if(!n.length)return t();e.post(ajaxurl,{action:"bpfb_remove_temp_images",data:n.serialize().replace(/%5B%5D/g,"[]")},function(e){t()})};var s=function(){var t=e("input.bpfb_photos_to_add");var n=[];t.each(function(){n[n.length]=e(this).val()});return{bpfb_photos:n}};var o=function(){$container.empty();e(".bpfb_preview_container").empty();e(".bpfb_action_container").empty();e("#aw-whats-new-submit").hide();t()};var u=function(){i(function(){$container.empty();e(".bpfb_preview_container").empty();e(".bpfb_action_container").empty();e("#aw-whats-new-submit").show()})};i(o);return{destroy:u,get:s}};if(e("#whats-new-form").is(":visible"))a();e(".bpfb_final_link img").each(function(){e(this).width(e(this).parents("div").width())})})})(jQuery)
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment