Skip to content
Browse files

Sorting mediaactivity updates for both normal media and groups

  • Loading branch information...
2 parents 29142d3 + 65193a6 commit 08d026c19fbe6c031fec5b9247c41f26f6987e62 Joshua Abenazer committed
View
149 app/assets/css/main.css
@@ -227,6 +227,155 @@ img.bp-media-donation-image{display:block;margin: 10px auto;}
height: 20px;
border-radius: 10px;
}
+.simplemodal-overlay{
+ background:#333 none;
+ z-index: 100000;
+}
+.simplemodal-container{
+ background:#fff none;
+}
+.bp-media-mod-title{
+ display:none;
+}
+
+.bp-media-ajax-single{
+ padding:0;
+}
+.simplemodal-container .simplemodal-close{
+ background: url("../img/bp-media-modal.png") right bottom no-repeat;
+ width:22px;
+ height:22px;
+ display:block;
+ position:absolute;
+ right:0px;
+ top:0px;
+ cursor: pointer;
+}
+.simplemodal-container .simplemodal-close:hover{
+ background-position: right top;
+}
+.simplemodal-container a.modal-ctrl{
+ position:absolute;
+ height:100%;
+ height:100px;
+ width:100px;
+ top:50%;
+ margin-top:-50px;
+ cursor: pointer;
+}
+.simplemodal-container a.modal-ctrl:hover{
+ background: #232323 none;
+}
+.simplemodal-container a.modal-ctrl span.img-icon{
+ display: block;
+ height:22px;
+ width:22px;
+ margin:39px auto 39px 10px;
+
+ background: url("../img/bp-media-modal.png") left bottom no-repeat;
+}
+.simplemodal-container a.modal-next span.img-icon{
+ background-position-x: center;
+ margin:39px 10px 39px auto;
+}
+.simplemodal-container a.modal-ctrl:hover span.img-icon{
+ background-position-y: top;
+}
+.simplemodal-container a.modal-next:hover span.img-icon{
+
+}
+.simplemodal-container a.modal-prev:hover,
+.simplemodal-container a.modal-next:hover{
+ background:url("../img/") no-repeat;
+}
+.simplemodal-container a.modal-prev{
+ left: 0px;
+}
+.simplemodal-container a.modal-next{
+ right: 0px;
+}
+
+.bp-media-ajax-single .bp-media-mod-title{
+ display:block;
+ margin-top:22px;
+}
+.bp-media-ajax-single .bp-media-mod-title h2{
+ margin: 5px 0;
+ padding:0;
+}
+.bp-media-ajax-single .bp-media-mod-title p{
+ line-height:1.4em;
+}
+.bp-media-ajax-single .bp_media_content img,
+.bp-media-ajax-single .bp_media_content video,
+.bp-media-ajax-single .bp_media_content audio{
+ max-width: 100%;
+ display:inline-block;
+ margin:0 auto;
+ vertical-align: middle;
+ background:#fff none;
+}
+.bp-media-ajax-single .bp_media_author{
+ position:absolute;
+ top:0;
+ left:0;
+}
+.bp-media-ajax-single .bp-media-content-wrap,
+.bp-media-ajax-single .bp_media_content{
+ float:left;
+ width:auto;
+ margin:0;
+ position:relative;
+ overflow:hidden;
+ min-height:480px;
+ min-width:640px;
+ background: #333 none;
+ display:table;
+
+}
+.bp-media-ajax-single .bp_media_content{
+ display:table-cell;
+ vertical-align: middle;
+ float:none;
+}
+.bp-media-ajax-single .bp-media-content-wrap .bp_media_description{
+ display:block;
+ position:absolute;
+ bottom:0;
+ left:0;
+}
+.bp-media-ajax-single .bp-media-meta-content-wrap{
+ float:left;
+ width:250px;
+ margin:0;
+ min-height:480px;
+ margin-left:10px;
+ overflow:auto;
+}
+.bp-media-ajax-single .bp-media-meta-content-wrap .activity-meta{
+ margin:0;
+}
+.bp-media-ajax-single .bp-media-meta-content-wrap .activity-meta a{
+ padding: 2px 8px;
+ margin: 5px 5px 0 0;
+ display:inline-block;
+}
+.bp-media-ajax-single .bp-media-meta-content-wrap div.activity-comments ul li > ul{
+ margin-left:0;
+ padding-left:0;
+}
+.bp-media-ajax-single .bp-media-meta-content-wrap div.activity-comments form div.ac-reply-content{
+ margin-left:0;
+ padding-left:0;
+}
+/*.bp-media-ajax-single .bp-media-meta-content-wrap div.activity-meta a {
+padding: 0;
+float:left;
+}*/
+.bp-media-ajax-preloader{
+ display:none;
+}
+
@media (min-width: 981px) and (max-width: 1096px) {
li #bp-media-upload-ui #drag-drop-area{padding: 10px 0;}
View
BIN app/assets/img/bp-media-modal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN app/assets/img/close.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
577 app/assets/js/main.js
@@ -3,83 +3,510 @@
*/
function bp_media_create_element(id){
- jQuery('#'+id).mediaelementplayer({
- enableKeyboard: false,
- startVolume: 1,
- success: function(mediaElement,domElement){
- var $thisMediaElement = (mediaElement.id) ? jQuery("#"+mediaElement.id) : jQuery(mediaElement);
- $thisMediaElement.parents('.mejs-container').find(".mejs-volume-current").css("top","8px");
- $thisMediaElement.parents('.mejs-container').find(".mejs-volume-handle").css("top","5px");
- }
- });
+ jQuery('#'+id).mediaelementplayer({
+ enableKeyboard: false,
+ startVolume: 1,
+ success: function(mediaElement,domElement){
+ var $thisMediaElement = (mediaElement.id) ? jQuery("#"+mediaElement.id) : jQuery(mediaElement);
+ $thisMediaElement.parents('.mejs-container').find(".mejs-volume-current").css("top","8px");
+ $thisMediaElement.parents('.mejs-container').find(".mejs-volume-handle").css("top","5px");
+ }
+ });
}
-
+var $current;
jQuery(document).ready(function(){
- var bp_media_recent_tabs = jQuery('.media-tabs-container-tabs');
- if(bp_media_recent_tabs.length>0){
- jQuery(bp_media_recent_tabs).tabs();
- }
-
- var tallest = 0;
- jQuery('#recent-media-tabs .bp-media-tab-panel').each(function() {
-
- var thisHeight = jQuery(this).height();
- if(thisHeight > tallest) {
- tallest = thisHeight;
- }
- }).height(tallest);
-
-
- jQuery('#bp-media-show-more').click(function(e){
- e.preventDefault();
- var data = {
- action: 'bp_media_load_more',
- page:++bp_media_vars.page,
- current_action : bp_media_vars.current_action,
- action_variables : bp_media_vars.action_variables,
- displayed_user : bp_media_vars.displayed_user,
- loggedin_user : bp_media_vars.loggedin_user,
- current_group : bp_media_vars.current_group
- };
-
- // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
- jQuery.post(bp_media_vars.ajaxurl, data, function(response) {
- if(response.length==0)
- jQuery('#bp-media-show-more').parent().remove();
- else
- jQuery('#bp-media-list').append(response);
- });
- });
- setTimeout(function(){
- jQuery('.media album_updated .delete-activity,.media_upload .delete-activity').unbind('click').click(function(e){
- if(confirm('Are you sure you want to delete this activity and associated media?')){
- return true;
- }
- else{
- return false;
- }
- });
-
- },1000);
-
- /* Add Featured Image */
- jQuery('.activity-meta').on('click','.bp-media-featured',function(e){
- e.preventDefault();
- var post_id = jQuery(this).attr('data-post-id');
- var album_id = jQuery(this).attr('data-album-id');
- var curr_obj = jQuery(this);
- var data = {
- action: 'bp_media_set_album_cover',
- post_id:post_id,
- album_id:album_id
- };
- jQuery.post(bp_media_vars.ajaxurl,data,function( response )
- {
- curr_obj.text(response);
- curr_obj.attr('title',response);
- }
- );
- });
+ var bp_media_recent_tabs = jQuery('.media-tabs-container-tabs');
+ if(bp_media_recent_tabs.length>0){
+ jQuery(bp_media_recent_tabs).tabs();
+ }
+
+ var tallest = 0;
+ jQuery('#recent-media-tabs .bp-media-tab-panel').each(function() {
+
+ var thisHeight = jQuery(this).height();
+ if(thisHeight > tallest) {
+ tallest = thisHeight;
+ }
+ }).height(tallest);
+
+
+ jQuery('#bp-media-show-more').click(function(e){
+ e.preventDefault();
+ var data = load_more_data();
+ jQuery.get(bp_media_vars.ajaxurl, data, function(response) {
+ if(response.length==0)
+ jQuery('#bp-media-show-more').parent().remove();
+ else
+ jQuery('#bp-media-list').append(response);
+ });
+ });
+ setTimeout(function(){
+ jQuery('.media album_updated .delete-activity,.media_upload .delete-activity').unbind('click').click(function(e){
+ if(confirm('Are you sure you want to delete this activity and associated media?')){
+ return true;
+ }
+ else{
+ return false;
+ }
+ });
+
+ },1000);
+
+ /* Add Featured Image */
+ jQuery('.activity-meta').on('click','.bp-media-featured',function(e){
+ e.preventDefault();
+ var post_id = jQuery(this).attr('data-post-id');
+ var album_id = jQuery(this).attr('data-album-id');
+ var curr_obj = jQuery(this);
+ var data = {
+ action: 'bp_media_set_album_cover',
+ post_id:post_id,
+ album_id:album_id
+ };
+ jQuery.get(bp_media_vars.ajaxurl,data,function( response )
+ {
+ curr_obj.text(response);
+ curr_obj.attr('title',response);
+ }
+ );
+ });
+
+
+ jQuery('#bp-media-list').on('click','li a',function(e){
+ e.preventDefault();
+ $current = jQuery(this);
+ load_media($current);
+ });
+ jQuery('body').on('click','a.modal-next', function(e){
+ e.preventDefault();
+ $next_current = $current.closest('li').next().find('a');
+ if($next_current.length<1){
+ var args = load_more_data();
+ var request = jQuery.get(bp_media_vars.ajaxurl, args);
+ chained = request.then(function( data ) {
+ if(data.length==0){
+ jQuery('#bp-media-show-more').parent().remove();
+ return false;
+ }else{
+ jQuery('#bp-media-list').append(data);
+ return true;
+ }
+ });
+
+ chained.done(function( truth ) {
+ if(truth!=false){
+ $next_current = $current.closest('li').next().find('a');
+ $current = $next_current;
+ transit_media($current);
+ }
+ });
+ }else{
+ $current = $next_current;
+ transit_media($next_current);
+ }
+
+
+ });
+ jQuery('body').on('click','a.modal-prev', function(e){
+ e.preventDefault();
+ if($current.closest('li').prev().find('#bp-media-upload-ui').length<1){
+ $current = $current.closest('li').prev().find('a');
+
+ transit_media($current);
+ }
+ });
+ jQuery(document.documentElement).keyup(function (event) {
+ if (event.keyCode == 37) {
+ jQuery('a.modal-prev').trigger('click');
+ } else if (event.keyCode == 39) {
+ jQuery('a.modal-next').trigger('click');
+ }
+ });
+
+ function load_media($current){
+ jQuery.get($current.attr('href'),function(response){
+ $mediacontent = jQuery(response).find('.bp-media-single');
+ $medialoaded = jQuery('<div class="bp-media-ajax-single"></div>');
+ $medialoaded.append($mediacontent);
+ jQuery.modal($medialoaded,{
+ 'zIndex':99999,
+ 'autoResize':true,
+ 'opacity': 90
+ });
+ do_fixes($medialoaded);
+ });
+ }
+ function transit_media($current){
+ jQuery.get($current.attr('href'),function(response){
+ $mediacontent = jQuery(response).find('.bp-media-single');
+ $medialoaded = jQuery('.bp-media-ajax-single');
+ $medialoaded.empty();
+ $medialoaded.append($mediacontent);
+ do_fixes($medialoaded);
+
+ });
+ }
+
+ function do_fixes($medialoaded){
+ $medialoaded.find('.bp-media-content-wrap').append('<a class="modal-prev modal-ctrl"><span class="img-icon"></span></a><a class="modal-next modal-ctrl"><span class="img-icon"></span></a>');
+ $medialoaded.find('.bp_media_description').remove();
+ $image = $medialoaded.find('.bp-media-content-wrap .bp_media_content img');
+ if($image.length<1){
+ $image = $medialoaded.find('.bp-media-content-wrap .bp_media_content video');
+ $dimensions = adjust_dimensions($image);
+ adjust_comment_div($dimensions[0]);
+ jQuery.modal.update($dimensions[0],$dimensions[1]);
+ }
+ $form = $medialoaded.find('form.ac-form');
+ $form.find('.ac-reply-avatar').remove();
+ $form.html($form.html().replace('&nbsp; or press esc to cancel.',''));
+ $image.load(function(){
+ $dimensions = adjust_dimensions($image);
+ adjust_comment_div($dimensions[0]);
+ jQuery.modal.update($dimensions[0],$dimensions[1]);
+ })
+ }
+
+ function adjust_dimensions($image){
+
+ $height = ($image.height()>480)?$image.height():480;
+ $width = ($image.width()>640)?$image.width():640;
+ $width = $width +280;
+ return [$height,$width];
+ }
+
+ function adjust_comment_div($height){
+ $medialoaded.find('.bp-media-meta-content-wrap').css({
+ 'height': $height,
+ 'overflow':'auto'
+ });
+ }
+ function load_more_data(){
+ var data = {
+ action: 'bp_media_load_more',
+ page:++bp_media_vars.page,
+ current_action : bp_media_vars.current_action,
+ action_variables : bp_media_vars.action_variables,
+ displayed_user : bp_media_vars.displayed_user,
+ loggedin_user : bp_media_vars.loggedin_user,
+ current_group : bp_media_vars.current_group
+ };
+ return data;
+ }
+
+ /**** Activity Comments *******************************************************/
+
+ /* Hide all activity comment forms */
+ jQuery('form.ac-form').show();
+
+ /* Hide excess comments */
+ if ( jQuery('.activity-comments').length )
+ bp_legacy_theme_hide_comments();
+
+ /* Activity list event delegation */
+ jQuery('body').on( 'click', '.bp-media-ajax-single div.activity',function(event) {
+ var target = jQuery(event.target);
+ if ( target.hasClass('bp-media-featured') ) {
+ var post_id = target.attr('data-post-id');
+ var album_id = target.attr('data-album-id');
+ var data = {
+ action: 'bp_media_set_album_cover',
+ post_id:post_id,
+ album_id:album_id
+ };
+ target.addClass('loading');
+ jQuery.get(bp_media_vars.ajaxurl,data,function( response )
+ {
+ target.removeClass('loading');
+ target.fadeOut( 200, function() {
+ jQuery(this).html(response);
+ jQuery(this).attr('title',response);
+ jQuery(this).fadeIn(200);
+ });
+
+ }
+ );
+ }
+
+ /* Favoriting activity stream items */
+ if ( target.hasClass('fav') || target.hasClass('unfav') ) {
+ console.log('hua');
+ event.preventDefault();
+ var type = target.hasClass('fav') ? 'fav' : 'unfav';
+ var parent = target.closest('.activity_update');
+ var parent_id = parent.attr('id').substr( 9, parent.attr('id').length );
+
+ target.addClass('loading');
+
+ jQuery.post( ajaxurl, {
+ action: 'activity_mark_' + type,
+ 'cookie': encodeURIComponent(document.cookie),
+ 'id': parent_id
+ },
+ function(response) {
+ target.removeClass('loading');
+
+ target.fadeOut( 200, function() {
+ jQuery(this).html(response);
+ jQuery(this).attr('title', 'fav' == type ? BP_DTheme.remove_fav : BP_DTheme.mark_as_fav);
+ jQuery(this).fadeIn(200);
+ });
+
+ if ( 'fav' == type ) {
+ if ( !jQuery('.item-list-tabs #activity-favorites').length )
+ jQuery('.item-list-tabs ul #activity-mentions').before( '<li id="activity-favorites"><a href="#">' + BP_DTheme.my_favs + ' <span>0</span></a></li>');
+
+ target.removeClass('fav');
+ target.addClass('unfav');
+
+ jQuery('.item-list-tabs ul #activity-favorites span').html( Number( jQuery('.item-list-tabs ul #activity-favorites span').html() ) + 1 );
+ } else {
+ target.removeClass('unfav');
+ target.addClass('fav');
+
+ jQuery('.item-list-tabs ul #activity-favorites span').html( Number( jQuery('.item-list-tabs ul #activity-favorites span').html() ) - 1 );
+
+ if ( !Number( jQuery('.item-list-tabs ul #activity-favorites span').html() ) ) {
+ if ( jQuery('.item-list-tabs ul #activity-favorites').hasClass('selected') )
+ bp_activity_request( null, null );
+
+ jQuery('.item-list-tabs ul #activity-favorites').remove();
+ }
+ }
+
+ if ( 'activity-favorites' == jQuery( '.item-list-tabs li.selected').attr('id') )
+ target.parent().parent().parent().slideUp(100);
+ });
+
+ return false;
+ }
+ /* Comment / comment reply links */
+ if ( target.hasClass('acomment-reply') || target.parent().hasClass('acomment-reply') ) {
+ if ( target.parent().hasClass('acomment-reply') )
+ target = target.parent();
+
+ var id = target.attr('id');
+ ids = id.split('-');
+
+ var a_id = ids[2]
+ var c_id = target.attr('href').substr( 10, target.attr('href').length );
+ var form = jQuery( '#ac-form-' + a_id );
+
+ form.css( 'display', 'none' );
+ form.removeClass('root');
+ jQuery('.ac-form').hide();
+
+ /* Hide any error messages */
+ form.children('div').each( function() {
+ if ( jQuery(this).hasClass( 'error' ) )
+ jQuery(this).hide();
+ });
+
+ if ( ids[1] != 'comment' ) {
+ jQuery('#acomment-' + c_id).append( form );
+ } else {
+ jQuery('#activity-' + a_id + ' .activity-comments').append( form );
+ }
+
+ if ( form.parent().hasClass( 'activity-comments' ) )
+ form.addClass('root');
+
+ form.slideDown( 200 );
+ jQuery.scrollTo( form, 500, {
+ offset:-100,
+ easing:'easeOutQuad'
+ } );
+ jQuery('#ac-form-' + ids[2] + ' textarea').focus();
+
+ return false;
+ }
+
+ /* Activity comment posting */
+ if ( target.attr('name') == 'ac_form_submit' ) {
+ var form = target.parents( 'form' );
+ var form_parent = form.parent();
+ var form_id = form.attr('id').split('-');
+
+ if ( !form_parent.hasClass('activity-comments') ) {
+ var tmp_id = form_parent.attr('id').split('-');
+ var comment_id = tmp_id[1];
+ } else {
+ var comment_id = form_id[2];
+ }
+
+ var content = jQuery( '#' + form.attr('id') + ' textarea' );
+
+ /* Hide any error messages */
+ jQuery( '#' + form.attr('id') + ' div.error').hide();
+ target.addClass('loading').prop('disabled', true);
+ content.addClass('loading').prop('disabled', true);
+
+ var ajaxdata = {
+ action: 'new_activity_comment',
+ 'cookie': encodeURIComponent(document.cookie),
+ '_wpnonce_new_activity_comment': jQuery("#_wpnonce_new_activity_comment").val(),
+ 'comment_id': comment_id,
+ 'form_id': form_id[2],
+ 'content': content.val()
+ };
+
+ // Akismet
+ var ak_nonce = jQuery('#_bp_as_nonce_' + comment_id).val();
+ if ( ak_nonce ) {
+ ajaxdata['_bp_as_nonce_' + comment_id] = ak_nonce;
+ }
+
+ jQuery.post( ajaxurl, ajaxdata, function(response) {
+ target.removeClass('loading');
+ content.removeClass('loading');
+
+ /* Check for errors and append if found. */
+ if ( response[0] + response[1] == '-1' ) {
+ form.append( jQuery( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
+ } else {
+ form.fadeOut( 200, function() {
+ if ( 0 == form.parent().children('ul').length ) {
+ if ( form.parent().hasClass('activity-comments') ) {
+ form.parent().prepend('<ul></ul>');
+ } else {
+ form.parent().append('<ul></ul>');
+ }
+ }
+
+ /* Preceeding whitespace breaks output with jQuery 1.9.0 */
+ var the_comment = jQuery.trim( response );
+
+ form.parent().children('ul').append( jQuery( the_comment ).hide().fadeIn( 200 ) );
+ form.children('textarea').val('');
+ form.parent().parent().addClass('has-comments');
+ } );
+ jQuery( '#' + form.attr('id') + ' textarea').val('');
+
+ /* Increase the "Reply (X)" button count */
+ jQuery('#activity-' + form_id[2] + ' a.acomment-reply span').html( Number( jQuery('#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1 );
+ }
+
+ jQuery(target).prop("disabled", false);
+ jQuery(content).prop("disabled", false);
+ });
+
+ return false;
+ }
+
+ /* Deleting an activity comment */
+ if ( target.hasClass('acomment-delete') ) {
+ var link_href = target.attr('href');
+ var comment_li = target.parent().parent();
+ var form = comment_li.parents('div.activity-comments').children('form');
+
+ var nonce = link_href.split('_wpnonce=');
+ nonce = nonce[1];
+
+ var comment_id = link_href.split('cid=');
+ comment_id = comment_id[1].split('&');
+ comment_id = comment_id[0];
+
+ target.addClass('loading');
+
+ /* Remove any error messages */
+ jQuery('.activity-comments ul .error').remove();
+
+ /* Reset the form position */
+ comment_li.parents('.activity-comments').append(form);
+
+ jQuery.post( ajaxurl, {
+ action: 'delete_activity_comment',
+ 'cookie': encodeURIComponent(document.cookie),
+ '_wpnonce': nonce,
+ 'id': comment_id
+ },
+ function(response) {
+ /* Check for errors and append if found. */
+ if ( response[0] + response[1] == '-1' ) {
+ comment_li.prepend( jQuery( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
+ } else {
+ var children = jQuery( '#' + comment_li.attr('id') + ' ul' ).children('li');
+ var child_count = 0;
+ jQuery(children).each( function() {
+ if ( !jQuery(this).is(':hidden') )
+ child_count++;
+ });
+ comment_li.fadeOut(200);
+
+ /* Decrease the "Reply (X)" button count */
+ var count_span = jQuery('#' + comment_li.parents('#activity-stream > li').attr('id') + ' a.acomment-reply span');
+ var new_count = count_span.html() - ( 1 + child_count );
+ count_span.html(new_count);
+
+ /* If that was the last comment for the item, remove the has-comments class to clean up the styling */
+ if ( 0 == new_count ) {
+ jQuery(comment_li.parents('#activity-stream > li')).removeClass('has-comments');
+ }
+ }
+ });
+
+ return false;
+ }
+
+ // Spam an activity stream comment
+ if ( target.hasClass( 'spam-activity-comment' ) ) {
+ var link_href = target.attr( 'href' );
+ var comment_li = target.parent().parent();
+
+ target.addClass('loading');
+
+ // Remove any error messages
+ jQuery( '.activity-comments ul div.error' ).remove();
+
+ // Reset the form position
+ comment_li.parents( '.activity-comments' ).append( comment_li.parents( '.activity-comments' ).children( 'form' ) );
+
+ jQuery.post( ajaxurl, {
+ action: 'bp_spam_activity_comment',
+ 'cookie': encodeURIComponent( document.cookie ),
+ '_wpnonce': link_href.split( '_wpnonce=' )[1],
+ 'id': link_href.split( 'cid=' )[1].split( '&' )[0]
+ },
+
+ function ( response ) {
+ // Check for errors and append if found.
+ if ( response[0] + response[1] == '-1' ) {
+ comment_li.prepend( jQuery( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
+
+ } else {
+ var children = jQuery( '#' + comment_li.attr( 'id' ) + ' ul' ).children( 'li' );
+ var child_count = 0;
+ jQuery(children).each( function() {
+ if ( !jQuery( this ).is( ':hidden' ) ) {
+ child_count++;
+ }
+ });
+ comment_li.fadeOut( 200 );
+
+ // Decrease the "Reply (X)" button count
+ var parent_li = comment_li.parents( '#activity-stream > li' );
+ jQuery( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html( jQuery( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html() - ( 1 + child_count ) );
+ }
+ });
+
+ return false;
+ }
+
+ /* Showing hidden comments - pause for half a second */
+ if ( target.parent().hasClass('show-all') ) {
+ target.parent().addClass('loading');
+
+ setTimeout( function() {
+ target.parent().parent().children('li').fadeIn(200, function() {
+ target.parent().remove();
+ });
+ }, 600 );
+
+ return false;
+ }
+ });
+
+
});
View
39 app/main/includes/BPMediaActions.php
@@ -32,6 +32,7 @@ function __construct() {
add_action('wp_ajax_bp_media_load_more', array($this, 'load_more'));
add_action('wp_ajax_nopriv_bp_media_load_more', array($this, 'load_more'));
add_action('wp_ajax_bp_media_set_album_cover', array($this, 'set_album_cover'));
+ add_action( 'wp_ajax_bp-media-load-single', array( $this, 'load_single' ) );
add_action('delete_attachment', array($this, 'delete_attachment_handler'));
add_action('wp_ajax_bp_media_add_album', array($this, 'add_album'));
add_action('wp_ajax_bp_media_get_thumbnail', array($this, 'get_thumbnail'));
@@ -156,13 +157,18 @@ function enqueue_scripts_styles() {
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_script('bp-media-mejs', BP_MEDIA_URL . 'lib/media-element/mediaelement-and-player.min.js', '', BP_MEDIA_VERSION);
wp_enqueue_script('bp-media-default', BP_MEDIA_URL . 'app/assets/js/main.js', '', BP_MEDIA_VERSION);
-
- global $bp;
+ wp_enqueue_script('bp-media-modal', BP_MEDIA_URL . 'lib/simplemodal/jquery.simplemodal-1.4.4.js', '', BP_MEDIA_VERSION);
+ global $bp;
$cur_group_id = NULL;
if (bp_is_active("groups"))
$cur_group_id = bp_get_current_group_id();
+ if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
+ $schema = 'https';
+ } else {
+ $schema = 'http';
+ }
$bp_media_vars = array(
- 'ajaxurl' => admin_url('admin-ajax.php'),
+ 'ajaxurl' => admin_url('admin-ajax.php',$schema),
'page' => 1,
'current_action' => $cur_group_id ? (empty($bp->action_variables) ? BP_MEDIA_IMAGES_SLUG : $bp->action_variables[0]) : (isset($bp->current_action) ? $bp->current_action : false),
'action_variables' => isset($bp->action_variables) ? (empty($bp->action_variables) ? array(BP_MEDIA_IMAGES_SLUG) : $bp->action_variables) : array(BP_MEDIA_IMAGES_SLUG),
@@ -324,7 +330,7 @@ function action_buttons() {
if (isset($bp_media->options['download_enabled']))
echo '<a href="' . $bp_media_current_entry->get_attachment_url()
- . '" class="button item-button bp-secondary-action bp-media-download" title="'
+ . '" target="_blank" class="button item-button bp-secondary-action bp-media-download" title="'
. __('Download', BP_MEDIA_TXT_DOMAIN) . '">' . __('Download', BP_MEDIA_TXT_DOMAIN) . '</a>';
}
}
@@ -647,6 +653,27 @@ function load_more() {
die();
}
+ function load_single($current_id=false, $nav_action='now'){
+ if($_GET['action']== 'bp-media-load-single'){
+
+ if(!$current_id){
+ $current_id = $_GET['media_id'];
+ }
+
+ if(!$current_id) return false;
+
+ if(!$nav_action){
+ $nav_action = $_GET('nav_action');
+ }
+
+ $bp_media_current_entry = new BPMediaHostWordpress($current_id);
+ echo '<div class="bp-media-single-ajax">';
+ echo $bp_media_current_entry->get_media_single_content();
+ echo '</div>';
+ die();
+ }
+ }
+
/**
*
* @global type $bp_media_count
@@ -828,8 +855,8 @@ static function activity_create_after_add_media($media, $hidden = false, $activi
}
public function set_album_cover() {
- $id = $_POST['post_id'];
- $album_id = $_POST['album_id'];
+ $id = $_GET['post_id'];
+ $album_id = $_GET['album_id'];
$album_cover = get_post_thumbnail_id($album_id);
$text = NULL;
if ($album_cover && ($album_cover == $id)) {
View
13 app/main/includes/BPMediaHostWordpress.php
@@ -416,11 +416,12 @@ function get_media_gallery_content() {
$thumb_url = BP_MEDIA_URL . 'app/assets/img/video_thumb.png';
}
?>
- <li>
+ <li id="bp-media-item-<?php echo $this->id?>">
<a href="<?php echo $this->url ?>" title="<?php _e( $this->description, BP_MEDIA_TXT_DOMAIN ); ?>">
<img src="<?php echo apply_filters( 'bp_media_video_thumb', $thumb_url, $attachment, $this->type ); ?>" />
</a>
<h3 title="<?php echo $this->name; ?>"><a href="<?php echo $this->url ?>" title="<?php _e( $this->description, BP_MEDIA_TXT_DOMAIN ); ?>"><?php echo $this->name; ?></a></h3>
+ <div class="bp-media-ajax-preloader"></div>
</li>
<?php
break;
@@ -432,11 +433,12 @@ function get_media_gallery_content() {
$thumb_url = BP_MEDIA_URL . 'app/assets/img/audio_thumb.png';
}
?>
- <li>
+ <li id="bp-media-item-<?php echo $this->id?>">
<a href="<?php echo $this->url ?>" title="<?php _e( $this->description, BP_MEDIA_TXT_DOMAIN ); ?>">
<img src="<?php echo $thumb_url ?>" />
</a>
<h3 title="<?php echo $this->name; ?>"><a href="<?php echo $this->url ?>" title="<?php _e( $this->description, BP_MEDIA_TXT_DOMAIN ); ?>"><?php echo $this->name ?></a></h3>
+ <div class="bp-media-ajax-preloader"></div>
</li>
<?php
break;
@@ -444,11 +446,12 @@ function get_media_gallery_content() {
$medium_array = image_downsize( $attachment, 'thumbnail' );
$medium_path = $medium_array[ 0 ];
?>
- <li>
+ <li id="bp-media-item-<?php echo $this->id?>">
<a href="<?php echo $this->url ?>" title="<?php echo $this->description ?>">
<img src="<?php echo $medium_path ?>" />
</a>
<h3 title="<?php echo $this->name ?>"><a href="<?php echo $this->url ?>" title="<?php _e( $this->description, BP_MEDIA_TXT_DOMAIN ); ?>"><?php echo $this->name ?></a></h3>
+ <div class="bp-media-ajax-preloader"></div>
</li>
<?php
break;
@@ -955,5 +958,9 @@ function check_and_create_album( $album_id, $group ) {
return $post_id;
}
+ function get_description(){
+ return $this->description;
+ }
+
}
?>
View
2 app/main/profile/BPMediaAlbumScreen.php
@@ -70,7 +70,7 @@ function screen_content() {
$this->hook_before();
if ($bp_media_albums_query && $bp_media_albums_query->have_posts()):
- echo '<ul id="bp-media-list" class="bp-media-gallery item-list">';
+ echo '<ul id="bp-album-list" class="bp-media-gallery item-list">';
while ($bp_media_albums_query->have_posts()) : $bp_media_albums_query->the_post();
$this->template->the_album_content();
endwhile;
View
10 app/main/profile/BPMediaScreen.php
@@ -252,8 +252,18 @@ function entry_screen_content() {
if (!$bp->action_variables[0] == constant($entryslug))
return false;
echo '<div class="bp-media-single bp-media-image">';
+ echo '<div class="bp-media-content-wrap">';
echo $bp_media_current_entry->get_media_single_content();
+ echo '</div>';
+ echo '<div class="bp-media-meta-content-wrap">';
+ echo '<div class="bp-media-mod-title">';
+ echo '<h2>';
+ $this->entry_screen_title();
+ echo '</h2>';
+ echo '<p>'.nl2br($bp_media_current_entry->get_description()).'</p>';
+ echo '</div>';
echo $bp_media_current_entry->show_comment_form();
+ echo '</div>';
echo '</div>';
$this->hook_after();
}
View
758 lib/simplemodal/jquery.simplemodal-1.4.4.js
@@ -0,0 +1,758 @@
+/*
+ * SimpleModal 1.4.4 - jQuery Plugin
+ * http://simplemodal.com/
+ * Copyright (c) 2013 Eric Martin
+ * Licensed under MIT and GPL
+ * Date: Sun, Jan 20 2013 15:58:56 -0800
+ */
+
+/**
+ * SimpleModal is a lightweight jQuery plugin that provides a simple
+ * interface to create a modal dialog.
+ *
+ * The goal of SimpleModal is to provide developers with a cross-browser
+ * overlay and container that will be populated with data provided to
+ * SimpleModal.
+ *
+ * There are two ways to call SimpleModal:
+ * 1) As a chained function on a jQuery object, like $('#myDiv').modal();.
+ * This call would place the DOM object, #myDiv, inside a modal dialog.
+ * Chaining requires a jQuery object. An optional options object can be
+ * passed as a parameter.
+ *
+ * @example $('<div>my data</div>').modal({options});
+ * @example $('#myDiv').modal({options});
+ * @example jQueryObject.modal({options});
+ *
+ * 2) As a stand-alone function, like $.modal(data). The data parameter
+ * is required and an optional options object can be passed as a second
+ * parameter. This method provides more flexibility in the types of data
+ * that are allowed. The data could be a DOM object, a jQuery object, HTML
+ * or a string.
+ *
+ * @example $.modal('<div>my data</div>', {options});
+ * @example $.modal('my data', {options});
+ * @example $.modal($('#myDiv'), {options});
+ * @example $.modal(jQueryObject, {options});
+ * @example $.modal(document.getElementById('myDiv'), {options});
+ *
+ * A SimpleModal call can contain multiple elements, but only one modal
+ * dialog can be created at a time. Which means that all of the matched
+ * elements will be displayed within the modal container.
+ *
+ * SimpleModal internally sets the CSS needed to display the modal dialog
+ * properly in all browsers, yet provides the developer with the flexibility
+ * to easily control the look and feel. The styling for SimpleModal can be
+ * done through external stylesheets, or through SimpleModal, using the
+ * overlayCss, containerCss, and dataCss options.
+ *
+ * SimpleModal has been tested in the following browsers:
+ * - IE 6+
+ * - Firefox 2+
+ * - Opera 9+
+ * - Safari 3+
+ * - Chrome 1+
+ *
+ * @name SimpleModal
+ * @type jQuery
+ * @requires jQuery v1.3
+ * @cat Plugins/Windows and Overlays
+ * @author Eric Martin (http://ericmmartin.com)
+ * @version 1.4.4
+ */
+
+;
+(function (factory) {
+ if (typeof define === 'function' && define.amd) {
+ // AMD. Register as an anonymous module.
+ define(['jquery'], factory);
+ } else {
+ // Browser globals
+ factory(jQuery);
+ }
+}
+(function ($) {
+ var d = [],
+ doc = $(document),
+ ua = navigator.userAgent.toLowerCase(),
+ wndw = $(window),
+ w = [];
+
+ var browser = {
+ ieQuirks: null,
+ msie: /msie/.test(ua) && !/opera/.test(ua),
+ opera: /opera/.test(ua)
+ };
+ browser.ie6 = browser.msie && /msie 6./.test(ua) && typeof window['XMLHttpRequest'] !== 'object';
+ browser.ie7 = browser.msie && /msie 7.0/.test(ua);
+
+ /*
+ * Create and display a modal dialog.
+ *
+ * @param {string, object} data A string, jQuery object or DOM object
+ * @param {object} [options] An optional object containing options overrides
+ */
+ $.modal = function (data, options) {
+ return $.modal.impl.init(data, options);
+ };
+
+ /*
+ * Close the modal dialog.
+ */
+ $.modal.close = function () {
+ $.modal.impl.close();
+ };
+
+ /*
+ * Set focus on first or last visible input in the modal dialog. To focus on the last
+ * element, call $.modal.focus('last'). If no input elements are found, focus is placed
+ * on the data wrapper element.
+ */
+ $.modal.focus = function (pos) {
+ $.modal.impl.focus(pos);
+ };
+
+ /*
+ * Determine and set the dimensions of the modal dialog container.
+ * setPosition() is called if the autoPosition option is true.
+ */
+ $.modal.setContainerDimensions = function () {
+ $.modal.impl.setContainerDimensions();
+ };
+
+ /*
+ * Re-position the modal dialog.
+ */
+ $.modal.setPosition = function () {
+ $.modal.impl.setPosition();
+ };
+
+ /*
+ * Update the modal dialog. If new dimensions are passed, they will be used to determine
+ * the dimensions of the container.
+ *
+ * setContainerDimensions() is called, which in turn calls setPosition(), if enabled.
+ * Lastly, focus() is called is the focus option is true.
+ */
+ $.modal.update = function (height, width) {
+ $.modal.impl.update(height, width);
+ };
+
+ /*
+ * Chained function to create a modal dialog.
+ *
+ * @param {object} [options] An optional object containing options overrides
+ */
+ $.fn.modal = function (options) {
+ return $.modal.impl.init(this, options);
+ };
+
+ /*
+ * SimpleModal default options
+ *
+ * appendTo: (String:'body') The jQuery selector to append the elements to. For .NET, use 'form'.
+ * focus: (Boolean:true) Focus in the first visible, enabled element?
+ * opacity: (Number:50) The opacity value for the overlay div, from 0 - 100
+ * overlayId: (String:'simplemodal-overlay') The DOM element id for the overlay div
+ * overlayCss: (Object:{}) The CSS styling for the overlay div
+ * containerId: (String:'simplemodal-container') The DOM element id for the container div
+ * containerCss: (Object:{}) The CSS styling for the container div
+ * dataId: (String:'simplemodal-data') The DOM element id for the data div
+ * dataCss: (Object:{}) The CSS styling for the data div
+ * minHeight: (Number:null) The minimum height for the container
+ * minWidth: (Number:null) The minimum width for the container
+ * maxHeight: (Number:null) The maximum height for the container. If not specified, the window height is used.
+ * maxWidth: (Number:null) The maximum width for the container. If not specified, the window width is used.
+ * autoResize: (Boolean:false) Automatically resize the container if it exceeds the browser window dimensions?
+ * autoPosition: (Boolean:true) Automatically position the container upon creation and on window resize?
+ * zIndex: (Number: 1000) Starting z-index value
+ * close: (Boolean:true) If true, closeHTML, escClose and overClose will be used if set.
+ If false, none of them will be used.
+ * closeHTML: (String:'<a class="modalCloseImg" title="Close"></a>') The HTML for the default close link.
+ SimpleModal will automatically add the closeClass to this element.
+ * closeClass: (String:'simplemodal-close') The CSS class used to bind to the close event
+ * escClose: (Boolean:true) Allow Esc keypress to close the dialog?
+ * overlayClose: (Boolean:false) Allow click on overlay to close the dialog?
+ * fixed: (Boolean:true) If true, the container will use a fixed position. If false, it will use a
+ absolute position (the dialog will scroll with the page)
+ * position: (Array:null) Position of container [top, left]. Can be number of pixels or percentage
+ * persist: (Boolean:false) Persist the data across modal calls? Only used for existing
+ DOM elements. If true, the data will be maintained across modal calls, if false,
+ the data will be reverted to its original state.
+ * modal: (Boolean:true) User will be unable to interact with the page below the modal or tab away from the dialog.
+ If false, the overlay, iframe, and certain events will be disabled allowing the user to interact
+ with the page below the dialog.
+ * onOpen: (Function:null) The callback function used in place of SimpleModal's open
+ * onShow: (Function:null) The callback function used after the modal dialog has opened
+ * onClose: (Function:null) The callback function used in place of SimpleModal's close
+ */
+ $.modal.defaults = {
+ appendTo: 'body',
+ focus: true,
+ opacity: 50,
+ overlayId: 'simplemodal-overlay',
+ overlayCss: {},
+ containerId: 'simplemodal-container',
+ containerCss: {},
+ dataId: 'simplemodal-data',
+ dataCss: {},
+ minHeight: null,
+ minWidth: null,
+ maxHeight: null,
+ maxWidth: null,
+ autoResize: false,
+ autoPosition: true,
+ zIndex: 1000,
+ close: true,
+ closeHTML: '<a class="modalCloseImg" title="Close"></a>',
+ closeClass: 'simplemodal-close',
+ escClose: true,
+ overlayClose: false,
+ fixed: true,
+ position: null,
+ persist: false,
+ modal: true,
+ onOpen: null,
+ onShow: null,
+ onClose: null
+ };
+
+ /*
+ * Main modal object
+ * o = options
+ */
+ $.modal.impl = {
+ /*
+ * Contains the modal dialog elements and is the object passed
+ * back to the callback (onOpen, onShow, onClose) functions
+ */
+ d: {},
+ /*
+ * Initialize the modal dialog
+ */
+ init: function (data, options) {
+ var s = this;
+
+ // don't allow multiple calls
+ if (s.d.data) {
+ return false;
+ }
+
+ // $.support.boxModel is undefined if checked earlier
+ browser.ieQuirks = browser.msie && !$.support.boxModel;
+
+ // merge defaults and user options
+ s.o = $.extend({}, $.modal.defaults, options);
+
+ // keep track of z-index
+ s.zIndex = s.o.zIndex;
+
+ // set the onClose callback flag
+ s.occb = false;
+
+ // determine how to handle the data based on its type
+ if (typeof data === 'object') {
+ // convert DOM object to a jQuery object
+ data = data instanceof $ ? data : $(data);
+ s.d.placeholder = false;
+
+ // if the object came from the DOM, keep track of its parent
+ if (data.parent().parent().size() > 0) {
+ data.before($('<span></span>')
+ .attr('id', 'simplemodal-placeholder')
+ .css({
+ display: 'none'
+ }));
+
+ s.d.placeholder = true;
+ s.display = data.css('display');
+
+ // persist changes? if not, make a clone of the element
+ if (!s.o.persist) {
+ s.d.orig = data.clone(true);
+ }
+ }
+ }
+ else if (typeof data === 'string' || typeof data === 'number') {
+ // just insert the data as innerHTML
+ data = $('<div></div>').html(data);
+ }
+ else {
+ // unsupported data type!
+ alert('SimpleModal Error: Unsupported data type: ' + typeof data);
+ return s;
+ }
+
+ // create the modal overlay, container and, if necessary, iframe
+ s.create(data);
+ data = null;
+
+ // display the modal dialog
+ s.open();
+
+ // useful for adding events/manipulating data in the modal dialog
+ if ($.isFunction(s.o.onShow)) {
+ s.o.onShow.apply(s, [s.d]);
+ }
+
+ // don't break the chain =)
+ return s;
+ },
+ /*
+ * Create and add the modal overlay and container to the page
+ */
+ create: function (data) {
+ var s = this;
+
+ // get the window properties
+ s.getDimensions();
+
+ // add an iframe to prevent select options from bleeding through
+ if (s.o.modal && browser.ie6) {
+ s.d.iframe = $('<iframe src="javascript:false;"></iframe>')
+ .css($.extend(s.o.iframeCss, {
+ display: 'none',
+ opacity: 0,
+ position: 'fixed',
+ height: w[0],
+ width: w[1],
+ zIndex: s.o.zIndex,
+ top: 0,
+ left: 0
+ }))
+ .appendTo(s.o.appendTo);
+ }
+
+ // create the overlay
+ s.d.overlay = $('<div></div>')
+ .attr('id', s.o.overlayId)
+ .addClass('simplemodal-overlay')
+ .css($.extend(s.o.overlayCss, {
+ display: 'none',
+ opacity: s.o.opacity / 100,
+ height: s.o.modal ? d[0] : 0,
+ width: s.o.modal ? d[1] : 0,
+ position: 'fixed',
+ left: 0,
+ top: 0,
+ zIndex: s.o.zIndex + 1
+ }))
+ .appendTo(s.o.appendTo);
+
+ // create the container
+ s.d.container = $('<div></div>')
+ .attr('id', s.o.containerId)
+ .addClass('simplemodal-container')
+ .css($.extend(
+ {
+ position: s.o.fixed ? 'fixed' : 'absolute'
+ },
+ s.o.containerCss,
+ {
+ display: 'none',
+ zIndex: s.o.zIndex + 2
+ }
+ ))
+ .append(s.o.close && s.o.closeHTML
+ ? $(s.o.closeHTML).addClass(s.o.closeClass)
+ : '')
+ .appendTo(s.o.appendTo);
+
+ s.d.wrap = $('<div></div>')
+ .attr('tabIndex', -1)
+ .addClass('simplemodal-wrap')
+ .css({
+ height: '100%',
+ outline: 0,
+ width: '100%'
+ })
+ .appendTo(s.d.container);
+
+ // add styling and attributes to the data
+ // append to body to get correct dimensions, then move to wrap
+ s.d.data = data
+ .attr('id', data.attr('id') || s.o.dataId)
+ .addClass('simplemodal-data')
+ .css($.extend(s.o.dataCss, {
+ display: 'none'
+ }))
+ .appendTo('body');
+ data = null;
+
+ s.setContainerDimensions();
+ s.d.data.appendTo(s.d.wrap);
+
+ // fix issues with IE
+ if (browser.ie6 || browser.ieQuirks) {
+ s.fixIE();
+ }
+ },
+ /*
+ * Bind events
+ */
+ bindEvents: function () {
+ var s = this;
+
+ // bind the close event to any element with the closeClass class
+ $('.' + s.o.closeClass).bind('click.simplemodal', function (e) {
+ e.preventDefault();
+ s.close();
+ });
+
+ // bind the overlay click to the close function, if enabled
+ if (s.o.modal && s.o.close && s.o.overlayClose) {
+ s.d.overlay.bind('click.simplemodal', function (e) {
+ e.preventDefault();
+ s.close();
+ });
+ }
+
+ // bind keydown events
+ doc.bind('keydown.simplemodal', function (e) {
+ if (s.o.modal && e.keyCode === 9) { // TAB
+ s.watchTab(e);
+ }
+ else if ((s.o.close && s.o.escClose) && e.keyCode === 27) { // ESC
+ e.preventDefault();
+ s.close();
+ }
+ });
+
+ // update window size
+ wndw.bind('resize.simplemodal orientationchange.simplemodal', function () {
+ // redetermine the window width/height
+ s.getDimensions();
+
+ // reposition the dialog
+ s.o.autoResize ? s.setContainerDimensions() : s.o.autoPosition && s.setPosition();
+
+ if (browser.ie6 || browser.ieQuirks) {
+ s.fixIE();
+ }
+ else if (s.o.modal) {
+ // update the iframe & overlay
+ s.d.iframe && s.d.iframe.css({
+ height: w[0],
+ width: w[1]
+ });
+ s.d.overlay.css({
+ height: d[0],
+ width: d[1]
+ });
+ }
+ });
+ },
+ /*
+ * Unbind events
+ */
+ unbindEvents: function () {
+ $('.' + this.o.closeClass).unbind('click.simplemodal');
+ doc.unbind('keydown.simplemodal');
+ wndw.unbind('.simplemodal');
+ this.d.overlay.unbind('click.simplemodal');
+ },
+ /*
+ * Fix issues in IE6 and IE7 in quirks mode
+ */
+ fixIE: function () {
+ var s = this, p = s.o.position;
+
+ // simulate fixed position - adapted from BlockUI
+ $.each([s.d.iframe || null, !s.o.modal ? null : s.d.overlay, s.d.container.css('position') === 'fixed' ? s.d.container : null], function (i, el) {
+ if (el) {
+ var bch = 'document.body.clientHeight', bcw = 'document.body.clientWidth',
+ bsh = 'document.body.scrollHeight', bsl = 'document.body.scrollLeft',
+ bst = 'document.body.scrollTop', bsw = 'document.body.scrollWidth',
+ ch = 'document.documentElement.clientHeight', cw = 'document.documentElement.clientWidth',
+ sl = 'document.documentElement.scrollLeft', st = 'document.documentElement.scrollTop',
+ s = el[0].style;
+
+ s.position = 'absolute';
+ if (i < 2) {
+ s.removeExpression('height');
+ s.removeExpression('width');
+ s.setExpression('height','' + bsh + ' > ' + bch + ' ? ' + bsh + ' : ' + bch + ' + "px"');
+ s.setExpression('width','' + bsw + ' > ' + bcw + ' ? ' + bsw + ' : ' + bcw + ' + "px"');
+ }
+ else {
+ var te, le;
+ if (p && p.constructor === Array) {
+ var top = p[0]
+ ? typeof p[0] === 'number' ? p[0].toString() : p[0].replace(/px/, '')
+ : el.css('top').replace(/px/, '');
+ te = top.indexOf('%') === -1
+ ? top + ' + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"'
+ : parseInt(top.replace(/%/, '')) + ' * ((' + ch + ' || ' + bch + ') / 100) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"';
+
+ if (p[1]) {
+ var left = typeof p[1] === 'number' ? p[1].toString() : p[1].replace(/px/, '');
+ le = left.indexOf('%') === -1
+ ? left + ' + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"'
+ : parseInt(left.replace(/%/, '')) + ' * ((' + cw + ' || ' + bcw + ') / 100) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"';
+ }
+ }
+ else {
+ te = '(' + ch + ' || ' + bch + ') / 2 - (this.offsetHeight / 2) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"';
+ le = '(' + cw + ' || ' + bcw + ') / 2 - (this.offsetWidth / 2) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"';
+ }
+ s.removeExpression('top');
+ s.removeExpression('left');
+ s.setExpression('top', te);
+ s.setExpression('left', le);
+ }
+ }
+ });
+ },
+ /*
+ * Place focus on the first or last visible input
+ */
+ focus: function (pos) {
+ var s = this, p = pos && $.inArray(pos, ['first', 'last']) !== -1 ? pos : 'first';
+
+ // focus on dialog or the first visible/enabled input element
+ var input = $(':input:enabled:visible:' + p, s.d.wrap);
+ setTimeout(function () {
+ input.length > 0 ? input.focus() : s.d.wrap.focus();
+ }, 10);
+ },
+ getDimensions: function () {
+ // fix a jQuery bug with determining the window height - use innerHeight if available
+ var s = this,
+ h = typeof window.innerHeight === 'undefined' ? wndw.height() : window.innerHeight;
+
+ d = [doc.height(), doc.width()];
+ w = [h, wndw.width()];
+ },
+ getVal: function (v, d) {
+ return v ? (typeof v === 'number' ? v
+ : v === 'auto' ? 0
+ : v.indexOf('%') > 0 ? ((parseInt(v.replace(/%/, '')) / 100) * (d === 'h' ? w[0] : w[1]))
+ : parseInt(v.replace(/px/, '')))
+ : null;
+ },
+ /*
+ * Update the container. Set new dimensions, if provided.
+ * Focus, if enabled. Re-bind events.
+ */
+ update: function (height, width) {
+ var s = this;
+
+ // prevent update if dialog does not exist
+ if (!s.d.data) {
+ return false;
+ }
+
+ // reset orig values
+ s.d.origHeight = s.getVal(height, 'h');
+ s.d.origWidth = s.getVal(width, 'w');
+
+ // hide data to prevent screen flicker
+ s.d.data.hide();
+ height && s.d.container.css('height', height);
+ width && s.d.container.css('width', width);
+ s.setContainerDimensions();
+ s.d.data.show();
+ s.o.focus && s.focus();
+
+ // rebind events
+ s.unbindEvents();
+ s.bindEvents();
+ },
+ setContainerDimensions: function () {
+ var s = this,
+ badIE = browser.ie6 || browser.ie7;
+
+ // get the dimensions for the container and data
+ var ch = s.d.origHeight ? s.d.origHeight : browser.opera ? s.d.container.height() : s.getVal(badIE ? s.d.container[0].currentStyle['height'] : s.d.container.css('height'), 'h'),
+ cw = s.d.origWidth ? s.d.origWidth : browser.opera ? s.d.container.width() : s.getVal(badIE ? s.d.container[0].currentStyle['width'] : s.d.container.css('width'), 'w'),
+ dh = s.d.data.outerHeight(true), dw = s.d.data.outerWidth(true);
+
+ s.d.origHeight = s.d.origHeight || ch;
+ s.d.origWidth = s.d.origWidth || cw;
+
+ // mxoh = max option height, mxow = max option width
+ var mxoh = s.o.maxHeight ? s.getVal(s.o.maxHeight, 'h') : null,
+ mxow = s.o.maxWidth ? s.getVal(s.o.maxWidth, 'w') : null,
+ mh = mxoh && mxoh < w[0] ? mxoh : w[0],
+ mw = mxow && mxow < w[1] ? mxow : w[1];
+
+ // moh = min option height
+ var moh = s.o.minHeight ? s.getVal(s.o.minHeight, 'h') : 'auto';
+ if (!ch) {
+ if (!dh) {
+ ch = moh;
+ }
+ else {
+ if (dh > mh) {
+ ch = mh;
+ }
+ else if (s.o.minHeight && moh !== 'auto' && dh < moh) {
+ ch = moh;
+ }
+ else {
+ ch = dh;
+ }
+ }
+ }
+ else {
+ ch = s.o.autoResize && ch > mh ? mh : ch < moh ? moh : ch;
+ }
+
+ // mow = min option width
+ var mow = s.o.minWidth ? s.getVal(s.o.minWidth, 'w') : 'auto';
+ if (!cw) {
+ if (!dw) {
+ cw = mow;
+ }
+ else {
+ if (dw > mw) {
+ cw = mw;
+ }
+ else if (s.o.minWidth && mow !== 'auto' && dw < mow) {
+ cw = mow;
+ }
+ else {
+ cw = dw;
+ }
+ }
+ }
+ else {
+ cw = s.o.autoResize && cw > mw ? mw : cw < mow ? mow : cw;
+ }
+
+ s.d.container.css({
+ height: ch,
+ width: cw
+ });
+ s.d.wrap.css({
+ overflow: (dh > ch || dw > cw) ? 'auto' : 'visible'
+ });
+ s.o.autoPosition && s.setPosition();
+ },
+ setPosition: function () {
+ var s = this, top, left,
+ hc = (w[0]/2) - (s.d.container.outerHeight(true)/2),
+ vc = (w[1]/2) - (s.d.container.outerWidth(true)/2),
+ st = s.d.container.css('position') !== 'fixed' ? wndw.scrollTop() : 0;
+
+ if (s.o.position && Object.prototype.toString.call(s.o.position) === '[object Array]') {
+ top = st + (s.o.position[0] || hc);
+ left = s.o.position[1] || vc;
+ } else {
+ top = st + hc;
+ left = vc;
+ }
+ s.d.container.css({
+ left: left,
+ top: top
+ });
+ },
+ watchTab: function (e) {
+ var s = this;
+
+ if ($(e.target).parents('.simplemodal-container').length > 0) {
+ // save the list of inputs
+ s.inputs = $(':input:enabled:visible:first, :input:enabled:visible:last', s.d.data[0]);
+
+ // if it's the first or last tabbable element, refocus
+ if ((!e.shiftKey && e.target === s.inputs[s.inputs.length -1]) ||
+ (e.shiftKey && e.target === s.inputs[0]) ||
+ s.inputs.length === 0) {
+ e.preventDefault();
+ var pos = e.shiftKey ? 'last' : 'first';
+ s.focus(pos);
+ }
+ }
+ else {
+ // might be necessary when custom onShow callback is used
+ e.preventDefault();
+ s.focus();
+ }
+ },
+ /*
+ * Open the modal dialog elements
+ * - Note: If you use the onOpen callback, you must "show" the
+ * overlay and container elements manually
+ * (the iframe will be handled by SimpleModal)
+ */
+ open: function () {
+ var s = this;
+ // display the iframe
+ s.d.iframe && s.d.iframe.show();
+
+ if ($.isFunction(s.o.onOpen)) {
+ // execute the onOpen callback
+ s.o.onOpen.apply(s, [s.d]);
+ }
+ else {
+ // display the remaining elements
+ s.d.overlay.show();
+ s.d.container.show();
+ s.d.data.show();
+ }
+
+ s.o.focus && s.focus();
+
+ // bind default events
+ s.bindEvents();
+ },
+ /*
+ * Close the modal dialog
+ * - Note: If you use an onClose callback, you must remove the
+ * overlay, container and iframe elements manually
+ *
+ * @param {boolean} external Indicates whether the call to this
+ * function was internal or external. If it was external, the
+ * onClose callback will be ignored
+ */
+ close: function () {
+ var s = this;
+
+ // prevent close when dialog does not exist
+ if (!s.d.data) {
+ return false;
+ }
+
+ // remove the default events
+ s.unbindEvents();
+
+ if ($.isFunction(s.o.onClose) && !s.occb) {
+ // set the onClose callback flag
+ s.occb = true;
+
+ // execute the onClose callback
+ s.o.onClose.apply(s, [s.d]);
+ }
+ else {
+ // if the data came from the DOM, put it back
+ if (s.d.placeholder) {
+ var ph = $('#simplemodal-placeholder');
+ // save changes to the data?
+ if (s.o.persist) {
+ // insert the (possibly) modified data back into the DOM
+ ph.replaceWith(s.d.data.removeClass('simplemodal-data').css('display', s.display));
+ }
+ else {
+ // remove the current and insert the original,
+ // unmodified data back into the DOM
+ s.d.data.hide().remove();
+ ph.replaceWith(s.d.orig);
+ }
+ }
+ else {
+ // otherwise, remove it
+ s.d.data.hide().remove();
+ }
+
+ // remove the remaining elements
+ s.d.container.hide().remove();
+ s.d.overlay.hide();
+ s.d.iframe && s.d.iframe.hide().remove();
+ s.d.overlay.remove();
+
+ // reset the dialog object
+ s.d = {};
+ }
+ }
+ };
+}));

0 comments on commit 08d026c

Please sign in to comment.
Something went wrong with that request. Please try again.