1/* global jQuery, ajaxurl, mpp, _mppData, WPPlaylistView, mpp_add_attached_media, mpp_reset_attached_media */ 2jQuery(document).ready(function () { 3 4 var jq = jQuery; 5 /** 6 * Bulk Actions checkbox on Gallery-> Edit Media page 7 * Check/uncheck based on user action 8 */ 9 jq(document).on('click', '#mpp-check-all', function () { 10 11 if (jq(this).is(':checked')) { 12 // check all others 13 jq('input.mpp-delete-media-check').prop('checked', true); 14 15 } else { 16 // uncheck all 17 jq('input.mpp-delete-media-check').prop('checked', false); 18 } 19 }); 20 21 /** 22 * Single Gallery -> Edit Media page 23 * Handle publish to activity action 24 */ 25 jq(document).on('click', '.mpp-publish-to-activity-button', function () { 26 27 var $this = jq(this); 28 var url = $this.attr('href'); 29 var gallery_id = get_var_in_url('gallery_id', url); 30 var nonce = get_var_in_url('_wpnonce', url); 31 32 jq.post(ajaxurl, { 33 action: 'mpp_publish_gallery_media', 34 gallery_id: gallery_id, 35 _wpnonce: nonce, 36 cookie: encodeURIComponent(document.cookie) 37 }, function (response) { 38 var error; 39 if (response.error !== undefined) { 40 error = 1; 41 } 42 //hide the button 43 jq('#mpp-unpublished-media-info').hide(); 44 45 mpp.notify(response.message, error); 46 47 }, 48 49 'json'); 50 51 return false; 52 53 }); 54 /** 55 * Single Gallery->Edit Media 56 * Handle delete unpublished media 57 */ 58 jq(document).on('click', '.mpp-delete-unpublished-media-button', function () { 59 60 var $this = jq(this); 61 var url = $this.attr('href'); 62 var gallery_id = get_var_in_url('gallery_id', url); 63 var nonce = get_var_in_url('_wpnonce', url); 64 65 jq.post(ajaxurl, { 66 action: 'mpp_hide_unpublished_media', 67 gallery_id: gallery_id, 68 _wpnonce: nonce, 69 cookie: encodeURIComponent(document.cookie) 70 }, function (response) { 71 72 var error; 73 if (typeof response.error !== "undefined") { 74 error = 1; 75 } 76 //hide the button 77 jq('#mpp-unpublished-media-info').hide(); 78 79 mpp.notify(response.message, error); 80 81 }, 82 83 'json'); 84 85 return false; 86 87 }); 88 89 /** 90 * Single Gallery->Reorder 91 * Enable Media sorting/reodering on manage gallery/reorder page 92 * 93 */ 94 if (jq.fn.sortable !== undefined) { 95 jq("#mpp-sortable").sortable({opacity: 0.6, cursor: 'move'}); 96 } 97 /** 98 * Activity upload Form handling 99 * Prepend the upload buttons to Activity form 100 */ 101 102 jq('#whats-new-options').prepend(jq('#mpp-activity-upload-buttons')); 103 //jq('#whats-new-post-in-box').prepend( jq( '#mpp-activity-upload-buttons') ); 104 105 106 //Create an instance of uploader for activity 107 //Creat an instance of mpp Uploader and attach it to the activity upload elements 108 mpp.activity_uploader = new mpp.Uploader({ 109 container: 'body', 110 dropzone: '#mpp-upload-dropzone-activity', 111 browser: '#mpp-upload-media-button-activity', 112 feedback: '#mpp-upload-feedback-activity', 113 media_list: '#mpp-uploaded-media-list-activity',//where we will list the media 114 uploading_media_list: _.template("<li id='<%= id %>'><span class='mpp-attached-file-name'><%= name %></span>(<span class='mpp-attached-file-size'><%= size %></spa>)<span class='mpp-remove-file-attachment'>x</span> <b></b></li>"), 115 uploaded_media_list: _.template("<li class='mpp-uploaded-media-item' id='mpp-uploaded-media-item-<%= id %>' data-media-id='<%= id %>'><img src='<%= url %>' /><a href='#' class='mpp-delete-uploaded-media-item'>x</a></li>"), 116 117 success: function (file) { 118 //let the Base class success method handle the things 119 mpp.Uploader.prototype.success(file); 120 //save media id in cookie 121 mpp_add_attached_media(file.get('id')); 122 123 }, 124 error: function (reason, data, file) { 125 //let the Base class error handler do its job. 126 mpp.Uploader.prototype.error(reason, data, file); 127 _mpp_activity_upload_error(); 128 }, 129 complete: function () { 130 mpp.Uploader.prototype.complete(); 131 _mpp_activity_upload_complete(); 132 }, 133 onAddFile: function (file) { 134 mpp.Uploader.prototype.onAddFile(file); 135 136 }, 137 allFilesAdded: function (up) { 138 _mpp_activity_all_files_added(); 139 }, 140 isRestricted: function (up, file) { 141 142 return false; //return true to restrict upload 143 /*this.error( "Unable to add", {}, file ); 144 if( ! this.media_list ) 145 return; 146 //show loader 147 jq( '.mpp-loader', this.media_list ).hide(); 148 149 return true; 150 */ 151 } 152 153 }); 154 155 //When any of the media icons(audio/video etc) is clicked 156 //show the dropzone 157 158 jq(document).on('click', '#mpp-activity-upload-buttons a', function () { 159 160 var el = jq(this); 161 if (jq('#mpp-upload-dropzone-activity').length) { 162 var $container = jq('#mpp-upload-dropzone-activity').closest('.mpp-media-upload-container'); 163 164 $container.slideUp('slow', function() { 165 jq(this).removeClass('mpp-upload-container-inactive').addClass('mpp-upload-container-active'); 166 }); 167 //set upload context as activity 168 mpp.activity_uploader.param('context', 'activity'); 169 var dropzone = mpp.activity_uploader.dropzone;//.remove(); 170 //set current type as the clicked button 171 _mppData.current_type = jq(this).data('media-type');//use id as type detector , may be photo/audio/video 172 mpp_setup_uploader_file_types(mpp.activity_uploader); 173 174 dropzone.show(); 175 // refresh to reposition the shim. 176 mpp.activity_uploader.refresh(); 177 178 //this may not work on mobile 179 //check 180 // option to disable in 1.4.0 181 _mppData.activity_disable_auto_file_browser = parseInt(_mppData.activity_disable_auto_file_browser, 10); 182 if (!_mppData.activity_disable_auto_file_browser) { 183 jq('#mpp-upload-media-button-activity').click();//simulate click; 184 } 185 } 186 jq('.mpp-remote-add-media-row-activity').show(); 187 188 return false;
189 }); 190 191 jq(document).on('click', '.mpp-upload-container-close', function () { 192 hideActivityUploadContainer(); 193 return false; 194 }); 195 196 function hideActivityUploadContainer() { 197 var $container = jq('#mpp-activity-media-upload-container'); 198 $container.slideDown('slow', function() { 199 jq(this).removeClass('mpp-upload-container-active').addClass('mpp-upload-container-inactive'); 200 }); 201 return false; 202 } 203 204 //Intercept the ajax actions to check if there was an upload from activity 205 //if yes, when it is complete, hide the dropzone 206 207 //filter ajax request but only if the activity post form is present 208 if (jq('#whats-new-form').get(0) || jq('#swa-whats-new-form').get(0)) { 209 210 211 jQuery(document).ajaxSend(function (event, jqxhr, settings) { 212 213 if (is_post_update(settings.data)) { 214 var attached_media = mpp_get_attached_media(); 215 216 if (attached_media) { 217 settings.data = settings.data + '&mpp-attached-media=' + attached_media; 218 mpp_reset_attached_media(); 219 } 220 } 221 }); 222 223 224 jq(document).ajaxComplete(function (evt, xhr, options) { 225 226 var action = get_var_in_query('action', options.data); 227 228 //switch 229 switch (action) { 230 231 case 'post_update': 232 case 'swa_post_update': 233 hideActivityUploadContainer(); 234 mpp.activity_uploader.hide_ui(); //clear the list of uploaded media 235 jq('.mpp-remote-add-media-row-activity').hide(); 236 break; 237 } 238 239 }); 240 241 } 242 243 // called when all selected files are enqueued. 244 function _mpp_activity_all_files_added() { 245 // disable submit. 246 jq('#aw-whats-new-submit').prop('disabled', true); 247 } 248 249 // called when activity upload is complete. 250 function _mpp_activity_upload_complete() { 251 // enable on upload complete. 252 jq('#aw-whats-new-submit').prop('disabled', false); 253 } 254 255 // on activity upload error. 256 function _mpp_activity_upload_error() { 257 // enable on error. 258 jq('#aw-whats-new-submit').prop('disabled', false); 259 } 260 261 function is_post_update(qs) { 262 if (!qs) { 263 return false; 264 } 265 266 var action = get_var_in_query('action', qs); 267 268 if (action === 'post_update' || action === 'swa_post_update') { 269 return true; 270 } 271 272 return false; 273 } 274 275 276 /** For single gallery upload */ 277 278 mpp.guploader = new mpp.Uploader({ 279 container: 'body', 280 dropzone: '#mpp-upload-dropzone-gallery', 281 browser: '#mpp-upload-media-button-gallery', 282 feedback: '#mpp-upload-feedback-gallery', 283 media_list: '#mpp-uploaded-media-list-gallery',//where we will list the media 284 uploading_media_list: _.template("<li id='<%= id %>'><span class='mpp-attached-file-name'><%= name %></span>(<span class='mpp-attached-file-size'><%= size %></spa>)<span class='mpp-remove-file-attachment'>x</span> <b></b></li>"), 285 uploaded_media_list: _.template("<li class='mpp-uploaded-media-item' id='mpp-uploaded-media-item-<%= id %>'><img src='<%= url %>' /></li>") 286 287 288 }); 289 290 var context = 'gallery';//context defines from where it was uploaded 291 var gallery_id = 0; 292 293 if (jq('#mpp-context').get(0)) { 294 context = jq('#mpp-context').val(); 295 } 296 297 if (jq('#mpp-upload-gallery-id').get(0)) { 298 gallery_id = jq('#mpp-upload-gallery-id').val(); 299 } 300 //apply these only when the dropzone exists 301 if (jq('#mpp-upload-dropzone-gallery').get(0)) { 302 303 mpp.guploader.param('context', context); 304 mpp.guploader.param('gallery_id', gallery_id); 305 mpp_setup_uploader_file_types(mpp.guploader); 306 } 307 308 309//For cover uploader 310 311 mpp.cover_uploader = new mpp.Uploader({ 312 container: 'body', 313 dropzone: '.mpp-gallery-editable-cover', 314 browser: '#mpp-cover-upload', 315 feedback: '#mpp-cover-gallery-upload-feedback', 316 media_list: '',//where we will list the media 317 uploading_media_list: _.template("<li id='<%= id %>'><span class='mpp-attached-file-name'><%= name %></span>(<span class='mpp-attached-file-size'><%= size %></spa>)<span class='mpp-remove-file-attachment'>x</span> <b></b></li>"), 318 uploaded_media_list: _.template("<li class='mpp-uploaded-media-item' id='mpp-uploaded-media-item-<%= id %>'><img src='<%= url %>' /></li>"), 319 320 321 complete: function () { 322 323 // console.log('Cover Uploaded'); 324 }, 325 326 success: function (file) { 327 328 var sizes = file.get('sizes'); 329 var original_url = file.get('url'); 330 var id = file.get('id'); 331 var file_obj = file.get('file'); 332 333 var thumbnail = sizes.thumbnail; 334 335 //on success change cover image 336 337 var cover = '#mpp-cover-' + file.get('parent_id'); 338 339 jq(cover).find('.mpp-cover-uploading').hide(); 340 341 jq(cover).find('img.mpp-cover-image').attr('src', thumbnail.url); 342 343 }, 344 345 clear_media_list: function () { 346 347 }, 348 clear_feedback: function () { 349 if (!this.feedback) { 350 return; 351 } 352 353 jq('ul', this.feedback).empty(); 354 }, 355 356 hide_dropzone: function () { 357 358 if (!this.dropzone) { 359 return; 360 } 361 362 jq(this.dropzone).hide(); 363 }, 364 hide_ui: function () { 365 366 this.clear_media_list(); 367 this.clear_feedback(); 368 this.hide_dropzone(); 369 }, 370 371 onAddFile: function (file) { 372 //wehn file is added, set context 373 374 this.param('context', 'cover');//it is cover upload 375 this.param('action', 'mpp_upload_cover');//it is cover upload 376 377 378 var parent = this.browser.parents('.mpp-cover-wrapper'); 379 380 //update parent media or gallery id 381 this.param('mpp-parent-id', parent.find('.mpp-parent-id').val());//it is cover upload 382 //update parent gallery id 383 this.param('mpp-gallery-id', parent.find('.mpp-gallery-id').val());//it is cover upload 384 this.param('mpp-parent-type', parent.find('.mpp-parent-type').val());//it is cover upload 385 386 parent.find('.mpp-cover-uploading').show(); 387 388 }, 389 390 init: function () { 391 392 var parent = this.browser.parents('.mpp-cover-wrapper'); 393 394 jq.each(parent, function () { 395 jq(this).find('.mpp-gallery-editable-cover').append(jq('#mpp-cover-uploading').clone()); 396 397 }); 398 399 } 400 401 }); 402 403 mpp.shortcode_uploader = new mpp.Uploader({ 404 container: 'body', 405 dropzone: '#mpp-upload-dropzone-shortcode', 406 browser: '#mpp-upload-media-button-shortcode', 407 feedback: '#mpp-upload-feedback-shortcode', 408 media_list: '#mpp-uploaded-media-list-shortcode',//where we will list the media 409 uploading_media_list: _.template("<li id='<%= id %>'><span class='mpp-attached-file-name'><%= name %></span>(<span class='mpp-attached-file-size'><%= size %></spa>)<span class='mpp-remove-file-attachment'>x</span> <b></b></li>"), 410 uploaded_media_list: _.template("<li class='mpp-uploaded-media-item' id='mpp-uploaded-media-item-<%= id %>'><img src='<%= url %>' /></li>"), 411 412 413 onAddFile: function (file) { 414 //when file is added, set context 415 416 this.param('context', 'shortcode');//it is cover upload 417 var parent = this.browser.parents('.mpp-upload-shortcode'); 418 var $gallery = parent.find('#mpp-shortcode-upload-gallery-id');
419 var $skip_check = parent.find('#mpp-shortcode-skip-gallery-check'); 420 if (!$skip_check.get(0) && (!$gallery.get(0) || $gallery.val() == 0)) { 421 422 this.uploader.removeFile(file); 423 this.refresh(); 424 425 //remove the feedback that we added 426 this.removeFileFeedback(file); 427 this.uploader.stop(); 428 //notify error message 429 mpp.notify("Please select a gallery before uploading.", 1); 430 431 } 432 433 //update parent gallery id 434 this.param('gallery_id', parent.find('#mpp-shortcode-upload-gallery-id').val());//it is gallery upload voia shortcode 435 jq('.mpp-loader', this.media_list).show(); 436 } 437 }); 438 439 440 //apply these only when the dropzone exists 441 if (jq('#mpp-upload-dropzone-shortcode').get(0)) { 442 443 var $type = jq('#mpp-upload-dropzone-shortcode').parents('.mpp-upload-shortcode').find('.mpp-uploading-media-type'); 444 if ($type.get(0)) { 445 mpp_setup_uploader_file_types(mpp.shortcode_uploader, $type.val()); 446 } 447 } 448 449 //on gallery selection change, we need to update the the media type too 450 451 jQuery('.mpp-upload-shortcode #mpp-shortcode-upload-gallery-id').change(function () { 452 var $option = jQuery(this).find("option:selected"); 453 mpp_setup_uploader_file_types(mpp.shortcode_uploader, $option.data('mpp-type')); 454 }); 455 /// Trigger delete, deletes any trace of a Media 456 // I hurts when people delete loved ones from their heart, but deleting a media is fine 457 jq(document).on('click', '.mpp-uploading-media-list .mpp-delete-uploaded-media-item', function () { 458 459 var $this = jq(this); 460 var $parent = jq($this.parent()); //parents are very important in our life, how can we forget them 461 //is the data-media-id attribute set, like parents keep their child in heart, our $parent does too 462 var id = $parent.data('media-id'); 463 464 if (!id) { 465 return false; 466 } 467 468 var $img = $parent.find('img'); 469 var old_image = $img.attr('src'); 470 //set the loader icon as source 471 472 $img.attr('src', _mppData.loader_src); 473 $this.hide();//no delete button 474 475 //get the security pass for clearance because unidentified intruders are not welcome in the family 476 var nonce = jq('#_mpp_manage_gallery_nonce').val(); 477 478 //Now is the time to take action, 479 jq.post(ajaxurl, { 480 action: 'mpp_delete_media', 481 media_id: id, 482 cookie: encodeURIComponent(document.cookie), 483 _wpnonce: nonce 484 }, function (response) { 485 //how rude the nature is 486 //you deleted my media and still sending me message 487 if (typeof response.success !== "undefined") { 488 $parent.remove(); //can't believe the parent is going away too 489 490 mpp_remove_attached_media(id); 491 mpp.notify(response.message); //let the superman know what consequence his action has done 492 493 } else { 494 //something went wrong, perhaps the media escaped the deletion 495 $this.show(); 496 $img.attr('src', old_image); 497 498 mpp.notify(response.message); 499 } 500 //enough, let us hide the round round feedback 501 502 503 }, 'json'); 504 505 return false; 506 }); 507 508 //allow plugins/theme to override the notification 509 if (mpp.notify === undefined) { 510 511 mpp.notify = function (message, error) { 512 513 var class_name = 'updated success'; 514 if (error !== undefined) { 515 class_name = 'error'; 516 } 517 518 jq('#mpp-notice-message').remove();// will it have side effects? 519 var selectors = ['#mpp-container', '#whats-new-form', '.mpp-upload-shortcode']; //possible containers in preferred order 520 var container_selector = '';//default 521 522 for (var i = 0; i < selectors.length; i++) { 523 if (jQuery(selectors[i]).get(0)) { 524 container_selector = selectors[i]; 525 break; 526 } 527 } 528 529 //if container exists, let us append the message 530 if (container_selector) { 531 jq(container_selector).prepend('<div id="mpp-notice-message" class="mpp-notice mpp-template-notice ' + class_name + '"><p>' + message + '</p></div>').show(); 532 } 533 }; 534 535 mpp.clearNotice = function () { 536 jQuery('#mpp-notice-message').remove(); 537 }; 538 } 539 540 //Lightbox utility API. 541 mpp.lightbox = { 542 /** 543 * Open Lightbox with the Media Collection. 544 * 545 * @param {array} items array of media items 546 * @param {int} position numeric position of the media to be shown by default 547 * @param {string} fallback_url open this url on error. 548 */ 549 open: function (items, position, fallback_url) { 550 if (items.length < 1) { 551 window.location = fallback_url; 552 return; 553 } 554 555 jQuery.magnificPopup.open({ 556 items: items, 557 type: 'inline', 558 closeBtnInside: false, 559 preload: [1, 3], 560 closeOnBgClick: true, 561 showCloseBtn: true, 562 closeMarkup: '<button title="%title%" type="button" class="mfp-close mpp-lightbox-close-btn">×</button>', 563 gallery: { 564 enabled: true, 565 navigateByImgClick: true, 566 //arrowMarkup: '',// disabled default arrows 567 preload: [0, 1] // Will preload 0 - before current, and 1 after the current image 568 } 569 }, 570 position 571 ); 572 573 // new api. 574 jQuery(document).trigger('mpp:lightbox:opened', [items, position] ); 575 576 // backaward compatibility. 577 jQuery(document).trigger('mpp_lightbox_opened'); 578 }, //open lightbox 579 580 /** 581 * Update the lightbox content with given html. 582 * 583 * @param {string} content content. 584 * 585 * @returns {boolean} 586 */ 587 update: function (content) { 588 if (!mpp.lightbox.isLoaded()) { 589 return false;
590 } 591 var magnificPopup = jQuery.magnificPopup.instance; 592 magnificPopup.currItem.src = content; 593 magnificPopup.items[magnificPopup.index] = magnificPopup.currItem; 594 magnificPopup.updateItemHTML(); 595 }, // update current open box with the content. 596 597 gallery: function (gallery_id, position, url, media_id) { 598 var $lightbox = this; 599 //get the details from server. 600 jQuery.post(ajaxurl, { 601 action: 'mpp_fetch_gallery_media', 602 gallery_id: gallery_id, 603 cookie: encodeURIComponent(document.cookie) 604 }, 605 function (response) { 606 if (response.items === undefined) { 607 return;//should we notify too? 608 } 609 610 var items = response.items; 611 // If media ID is given 612 if (typeof media_id !== 'undefined') { 613 position = get_media_position_in_collection(media_id, items); 614 } 615 $lightbox.open(items, position, url); 616 617 }, 'json'); 618 }, 619 620 /** 621 * Open one or more media(photo) in lightbox 622 * 623 * @param {string} media_ids comma separated list of media ids 624 * @param {integer} position which media to display as first 625 * @param {string} url fallback url to open if lightbox is unable to open 626 */ 627 media: function (media_ids, position, url, media_id) { 628 var $lightbox = this; 629 jQuery.post(ajaxurl, { 630 action: 'mpp_lightbox_fetch_media', 631 media_ids: media_ids, 632 cookie: encodeURIComponent(document.cookie) 633 }, 634 function (response) { 635 if (response.items === undefined) { 636 return;//should we notify too? 637 } 638 639 var items = response.items; 640 // If media ID is given 641 if (typeof media_id !== 'undefined') { 642 position = get_media_position_in_collection(media_id, items); 643 } 644 $lightbox.open(items, position, url); 645 646 }, 'json'); 647 }, 648 649 activity: function (activity_id, position, url, media_id) { 650 //get the details from server 651 var $lightbox = this; 652 653 jQuery.post(ajaxurl, { 654 action: 'mpp_fetch_activity_media', 655 activity_id: activity_id, 656 cookie: encodeURIComponent(document.cookie) 657 }, 658 function (response) { 659 if (response.items === undefined) { 660 return;//should we notify too? 661 } 662 663 var items = response.items; 664 // If media ID is given 665 if (typeof media_id !== 'undefined') { 666 position = get_media_position_in_collection(media_id, items); 667 } 668 669 $lightbox.open(items, position, url); 670 671 }, 'json'); 672 }, //open for activity 673 674 /** 675 * Reload given media id. 676 * 677 * @param media_id 678 */ 679 reloadMedia: function (media_id) { 680 var $lightbox = this; 681 jq.post(ajaxurl, {action: 'mpp_reload_lightbox_media', 'media_id': media_id}, function (response) { 682 if (response.success) { 683 // success 684 $lightbox.update(response.data.content); 685 } else { 686 // Failed. 687 } 688 }); 689 }, 690 691 /** 692 * Reload the current lightbox media. It acts as refresh. 693 * 694 * @returns {boolean} 695 */ 696 reloadCurrentMedia: function () { 697 var media_id = this.getCurrentMediaID(); 698 if (media_id) { 699 this.reloadMedia(media_id); 700 return true; 701 } 702 return false;
703 }, 704 705 /** 706 * Get Current Media Opened in the lightbox. 707 * 708 * returns 0 for invalid call. 709 * 710 * @returns {int} 711 */ 712 getCurrentMediaID: function () { 713 if (!this.isLoaded() || !this.isOpen()) { 714 return 0; 715 } 716 717 var magnificPopup = jQuery.magnificPopup.instance; 718 var data = magnificPopup.currItem.data; 719 if (typeof data.id !== 'undefined') { 720 return data.id; 721 } 722 723 return 0; 724 }, 725 726 /** 727 * Is Lightbox Loaded? 728 * 729 * @returns {boolean} 730 */ 731 isLoaded: function () { 732 return jQuery.fn.magnificPopup !== undefined; 733 }, 734 735 /** 736 * Is lightbox Open? 737 * 738 * @returns {boolean} 739 */ 740 isOpen: function () { 741 return jQuery.magnificPopup.instance.isOpen === true; 742 }, 743 // backward compatibility 744 is_lightbox_loaded: function () { 745 return this.isLoaded(); 746 }, 747 /** 748 * Check if lightbox supports given type. 749 * 750 * @param type 751 * @returns {Boolean} 752 */ 753 supportsMediaType: function (type) { 754 // type unknown, or nothing is disabled or type is enabled. 755 return !type || !_mppData.lightboxDisabledTypes || !_mppData.lightboxDisabledTypes[type]; 756 } 757 }; 758 759 // Lightbox Code 760 var isLightBoxLoaded = mpp.lightbox.isLoaded(); 761 // Lightbox popup for activity. 762 if (isLightBoxLoaded && _mppData.enable_activity_lightbox) { 763 764 jq(document).on('click.mpp:activity:lightbox.mpp:lightbox', '.mpp-activity-media-list a.mpp-activity-media, .mpp-activity-media-list a.mpp-activity-item-title', function () { 765 766 var $this = jq(this); 767 if ($this.hasClass('mpp-no-lightbox')) { 768 return; 769 } 770 771 if (!mpp.lightbox.supportsMediaType($this.data('mpp-type'))) { 772 return; 773 } 774 775 var activity_id = $this.data('mpp-activity-id'); 776 var $parent = $this.parents('.mpp-activity-item-content'); 777 var position = 0; 778 if ($parent.get(0)) { 779 position = $this.parents('.mpp-container').find('.mpp-activity-item-content').index($parent); 780 // newer template 781 // or non photo media 782 783 } else if (!activity_id && $this.find('img.mpp-attached-media-item').get(0)) { 784 activity_id = $this.find('img.mpp-attached-media-item').data('mpp-activity-id'); 785 } 786 787 var url = $this.attr('href'); 788 if (!activity_id) { 789 return true; 790 } 791 var media_id = $this.data('mpp-media-id'); 792 //open lightbox 793 mpp.lightbox.activity(activity_id, position, url, media_id); 794 795 return false; 796 }); 797 //for comment 798 jq(document).on('click.mpp:activity:comment:lightbox.mpp:lightbox', '.mpp-activity-comment-media-list a', function () { 799 800 var $this = jq(this); 801 if ($this.hasClass('mpp-no-lightbox')) { 802 return; 803 } 804 805 if (!mpp.lightbox.supportsMediaType($this.data('mpp-type'))) { 806 return; 807 } 808 809 var media_id = $this.data('mpp-media-id'); 810 var position = 0; 811 var url = $this.attr('href'); 812 if (!media_id) { 813 return true; 814 } 815 //open lightbox 816 mpp.lightbox.media(media_id, position, url); 817 818 return false; 819 }); 820 821 822 } //end of activity lightbox 823 824 // For Gallery(when a gallery cover is clicked ) 825 if (isLightBoxLoaded && _mppData.enable_gallery_lightbox) { 826 827 jq(document).on('click.mpp:gallery:cover:lightbox.mpp:lightbox', '.mpp-gallery a.mpp-gallery-cover', function () { 828 829 var $this = jq(this); 830 if ($this.hasClass('mpp-no-lightbox')) { 831 return; 832 } 833 834 if (!mpp.lightbox.supportsMediaType($this.data('mpp-type'))) { 835 return; 836 } 837 838 var gallery_id = $this.data('mpp-gallery-id'); 839 var position = 0;//open first media 840 var url = $this.attr('href'); 841 842 if (!gallery_id) { 843 return true; 844 } 845 //open lightbox 846 mpp.lightbox.gallery(gallery_id, position, url); 847 848 return false;
849 }); 850 851 852 } 853 //for shortcodes, when a media(photo) is clicked 854 if (isLightBoxLoaded) { 855 jq(document).on('click.mpp:shortcode:lightbox.mpp:lightbox', '.mpp-shortcode-lightbox-enabled a.mpp-media-thumbnail, .mpp-shortcode-lightbox-enabled a.mpp-media-title', function () { 856 var $container = jq(jq(this).parents('.mpp-shortcode-lightbox-enabled').get(0)); 857 if (!$container.get(0)) { 858 return; 859 } 860 861 var $this = jq(this); 862 if ($this.hasClass('mpp-no-lightbox')) { 863 return; 864 } 865 866 if (!mpp.lightbox.supportsMediaType($this.data('mpp-type'))) { 867 return; 868 } 869 870 var media_ids = $container.data('media-ids'); 871 var url = $this.attr('href'); 872 var position = 0;// jq( 'a.mpp-media-thumbnail', $container) .index( $this ); 873 var media_id = $this.data('mpp-media-id'); 874 mpp.lightbox.media(media_ids, position, url, media_id); 875 return false; 876 877 }); 878 879 } //end of lightbox for the shortcode 880 881 // enable lightbox for click on the photo inside gallery 882 883 884 // For Gallery(when a gallery cover is clicked ) 885 if (isLightBoxLoaded && _mppData.enable_lightbox_in_gallery_media_list) { 886 887 jq(document).on('click.mpp:gallery:media:lightbox.mpp:lightbox', '.mpp-single-gallery-media-list a.mpp-photo-thumbnail, .mpp-single-gallery-media-list a.mpp-media-title', function () { 888 889 var $this = jq(this); 890 891 if ($this.hasClass('mpp-no-lightbox')) { 892 return; 893 } 894 895 if (!mpp.lightbox.supportsMediaType($this.data('mpp-type'))) { 896 return; 897 } 898 899 var gallery_id = $this.parents('.mpp-single-gallery-media-list').data('gallery-id'); 900 var position = 0;//open first media 901 var url = $this.attr('href'); 902 var media_id = $this.data('mpp-media-id'); 903 if (!gallery_id || !media_id) { 904 return true; 905 } 906 907 //open lightbox 908 mpp.lightbox.gallery(gallery_id, position, url, media_id); 909 910 return false; 911 }); 912 913 914 } 915 916 // Create trigger to open lightbox on any link that have the class 'mpp-lightbox-link' and context 917 if (isLightBoxLoaded) { 918 jq(document).on('click.mpp:link:lightbox.mpp:lightbox', '.mpp-lightbox-link', function () { 919 920 var $this = jq(this); 921 922 if ($this.hasClass('mpp-no-lightbox')) { 923 return; 924 } 925 926 if (!mpp.lightbox.supportsMediaType($this.data('mpp-type'))) { 927 return; 928 } 929 930 var activity_id = $this.data('activity-id'); 931 var gallery_id = $this.data('gallery-id'); 932 var media_id = $this.data('media-id'); 933 var url = $this.attr('href'); 934 var lightbox_opened = false; 935 var position = $this.data('position'); 936 937 if (!position) { 938 position = 0; 939 } else { 940 position = position - 1; 941 } 942 943 if (gallery_id) { 944 // open lightbox 945 mpp.lightbox.gallery(gallery_id, position, url); 946 lightbox_opened = true; 947 } else if (media_id) { 948 mpp.lightbox.media(media_id, position, url); 949 lightbox_opened = true; 950 } else if (activity_id) { 951 mpp.lightbox.activity(activity_id, position, url); 952 lightbox_opened = true; 953 } 954 955 if (lightbox_opened) { 956 return false; 957 } 958 959 }); 960 } 961 962 /** 963 * Find position of the item in the given collection. 964 * 965 * @param media_id 966 * @param items 967 * @returns {number} 968 */ 969 function get_media_position_in_collection(media_id, items) { 970 var index = 0; 971 var position = 0; 972 // calculate the position of this media in the collection 973 for (var i in items) { 974 if (items[i].id == media_id) { 975 position = index; 976 } 977 index++; 978 } 979 980 return position; 981 } 982 983 /** 984 * Show error message in the lighbox media edit form. 985 * 986 * @param form 987 * @param message 988 */ 989 function mpp_ligtbox_show_edit_error(form, message) { 990 var $el = form.find('.mpp-lightbox-edit-error'); 991 if (!$el.get(0)) { 992 form.prepend("<div class='mpp-error mpp-lightbox-edit-error'></div>"); 993 $el = form.find('.mpp-lightbox-edit-error'); 994 } 995 $el.html('<p>' + message + '</p>'); 996 } 997 998 /** 999 * Hide error in the lightbox media edit form. 1000 * 1001 * @param form 1002 */ 1003 function mpp_lightbox_hide_edit_error(form) { 1004 form.find('.mpp-lightbox-edit-error').remove(); 1005 } 1006 1007 // Handle Lightbox edit media link clicked 1008 jq(document).on('click', '.mpp-lightbox-edit-media-link', function () { 1009 var $this = jq(this); 1010 $this.hide(); 1011 var $form = jq('#mpp-lightbox-media-edit-form-' + $this.data('mpp-media-id')); 1012 1013 $form.removeClass('mpp-form-hidden'); 1014 jq('.mpp-lightbox-edit-media-cancel-link').show(); 1015 jq('.mpp-lightbox-media-description').hide(); 1016 1017 return false;
1018 }); 1019 1020 // Lightbox edit media cancel link clicked 1021 jq(document).on('click', '.mpp-lightbox-edit-media-cancel-link', function () { 1022 var $this = jq(this); 1023 var $form = jq('#mpp-lightbox-media-edit-form-' + $this.data('mpp-media-id')); 1024 1025 $form.addClass('mpp-form-hidden'); 1026 $this.hide(); 1027 1028 jq('.mpp-lightbox-edit-media-link').show(); 1029 jq('.mpp-lightbox-media-description').show(); 1030 1031 return false; 1032 }); 1033 1034 1035 // Lightbox Edit:- Cancel button in the form clicked. 1036 jq(document).on('click', '.mpp-lightbox-edit-media-cancel-button', function () { 1037 var $this = jq(this); 1038 var $form = jq('#mpp-lightbox-media-edit-form-' + $this.data('mpp-media-id')); 1039 1040 // Hide form. 1041 $form.addClass('mpp-form-hidden'); 1042 // show edit link. 1043 jq('.mpp-lightbox-edit-media-cancel-link').hide(); 1044 jq('.mpp-lightbox-edit-media-link').show(); 1045 jq('.mpp-lightbox-media-description').show(); 1046 return false; 1047 }); 1048 1049 // Lightbox Edit Media:- On submit. 1050 jq(document).on('click', '.mpp-lightbox-edit-media-submit-button', function () { 1051 var $btn_submit = jq(this); 1052 var $form = $btn_submit.parents('.mpp-lightbox-media-edit-form'); 1053 var $btn_cancel = $form.find('.mpp-lightbox-edit-media-cancel-button'); 1054 1055 $form.find('.mpp-loader-image').show(); 1056 1057 //disable buttons 1058 $btn_submit.attr('disabled', true); 1059 $btn_cancel.attr('disabled', true); 1060 1061 mpp_lightbox_hide_edit_error($form); 1062 // submit form 1063 var data = $form.serialize(); 1064 data += '&action=mpp_update_lightbox_media'; 1065 1066 jq.post(ajaxurl, data, function (response) { 1067 var magnificPopup = jQuery.magnificPopup.instance; 1068 1069 if (response.success) { 1070 // success 1071 var content = response.data.content; 1072 magnificPopup.currItem.src = content; 1073 magnificPopup.items[magnificPopup.index] = magnificPopup.currItem; 1074 magnificPopup.updateItemHTML(); 1075 } else { 1076 // Failed. 1077 var message = response.data.message; 1078 mpp_ligtbox_show_edit_error($form, message); 1079 } 1080 1081 $btn_submit.attr('disabled', false); 1082 $btn_cancel.attr('disabled', false); 1083 1084 $form.find('.mpp-loader-image').hide(); 1085 1086 }); 1087 1088 return false; 1089 }); 1090 1091 1092 /** utility functions*/ 1093 1094 /** 1095 * Get the value of a query parameter from the url 1096 * 1097 * @param item string the query var to be found. 1098 * @param str the query string. 1099 * @returns mixed 1100 */ 1101 function get_var_in_query(item, str) { 1102 var items; 1103 1104 if (typeof str === "undefined" || !str.length) { 1105 return false; 1106 } 1107 1108 var data_fields = str.split('&'); 1109 1110 for (var i = 0; i < data_fields.length; i++) { 1111 1112 items = data_fields[i].split('='); 1113 1114 if (items[0] == item) { 1115 return items[1]; 1116 } 1117 } 1118 1119 return false; 1120 } 1121 1122 /** 1123 * Extract a query variable from url 1124 * 1125 * @param item string 1126 * @param url string 1127 * @returns {Boolean|String|mixed} 1128 */ 1129 function get_var_in_url(item, url) { 1130 var url_chunks = url.split('?'); 1131 return get_var_in_query(item, url_chunks.length > 1 ? url_chunks[1] : ''); 1132 } 1133}); 1134 1135/** 1136 * Activate audi/video player(MediElelement.js player) 1137 * 1138 * @param {type} activity_id 1139 * @returns {undefined} 1140 */ 1141function mpp_mejs_activate(activity_id) { 1142 1143 /* global mejs, _wpmejsSettings */ 1144 var jq = jQuery; 1145 1146 //when document is loading, mediaelementplayer will be undefined, a workaround to avoid double activating it 1147 if (jq.fn.mediaelementplayer === undefined) { 1148 return; 1149 } 1150 1151 var settings = {}; 1152 1153 if (typeof _wpmejsSettings !== 'undefined') { 1154 settings = _wpmejsSettings; 1155 } 1156 1157 settings.success = function (mejs) { 1158 var autoplay, loop; 1159 1160 if ('flash' === mejs.pluginType) { 1161 autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay; 1162 loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop; 1163 1164 autoplay && mejs.addEventListener('canplay', function () { 1165 mejs.play(); 1166 }, false); 1167 1168 loop && mejs.addEventListener('ended', function () { 1169 mejs.play(); 1170 }, false); 1171 } 1172 }; 1173 1174 jq('.wp-audio-shortcode, .wp-video-shortcode', jq('#activity-' + activity_id)).mediaelementplayer(settings); 1175 1176 jq('.wp-playlist', jq('#activity-' + activity_id)).each(function () { 1177 return new WPPlaylistView({el: this}); 1178 }); 1179 1180} 1181 1182/** 1183 * Activate audio/video player(MediElelement.js player) in the lightbox. 1184 * 1185 * @returns {undefined} 1186 */ 1187function mpp_mejs_activate_lightbox_player() { 1188 1189 /* global mejs, _wpmejsSettings */ 1190 var jq = jQuery; 1191 1192 //when document is loading, mediaelementplayer will be undefined, a workaround to avoid double activating it 1193 if (jq.fn.mediaelementplayer === undefined) { 1194 return; 1195 } 1196 1197 var settings = {}; 1198 1199 if (typeof _wpmejsSettings !== 'undefined') { 1200 settings = _wpmejsSettings; 1201 } 1202 1203 settings.success = function (mejs) { 1204 var autoplay, loop; 1205 1206 if ('flash' === mejs.pluginType) { 1207 autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay; 1208 loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop; 1209 1210 autoplay && mejs.addEventListener('canplay', function () { 1211 mejs.play(); 1212 }, false); 1213 1214 loop && mejs.addEventListener('ended', function () { 1215 mejs.play(); 1216 }, false); 1217 } 1218 }; 1219 1220 jq('.wp-audio-shortcode, .wp-video-shortcode', jq('.mfp-content')).mediaelementplayer(settings); 1221 1222 jq('.wp-playlist', jq('.mfp-content')).each(function () { 1223 return new WPPlaylistView({el: this}); 1224 }); 1225 1226}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.