Guest User

JS na Dashboard

a guest
Aug 18th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function($) {
  2.  
  3.     // JS para abrir o Media Upload
  4.     $('#add_gallery_to_product').on('click', function(event) {
  5.         event.preventDefault();
  6.        
  7.         // Recupera os IDs atuais e cria o shortcode da galeria
  8.         var gallery_ids = $('#seutema_page_gallery_ids').val();
  9.         var gallery_shortcode = '[gallery ids="' + gallery_ids + '"]';
  10.  
  11.         Abre a edição da galeria
  12.         wp.media.gallery.edit(gallery_shortcode).on('update', function(g) {
  13.             var ids = [];
  14.  
  15.             $.each(g.models, function(id, img) {
  16.                 ids.push(img.id);
  17.             });
  18.  
  19.             var ids_string = ids.join(',');
  20.  
  21.             // Guarda os ids das imagens no INPUT:
  22.             $('#seutema_page_gallery_ids').val(ids_string);
  23.  
  24.             // Recupera o NONCE:
  25.             var nonce_val = $('#seutema-gallery-nonce').val();
  26.  
  27.             // Recupera uma nova galeria via Ajax
  28.             $.ajax({
  29.                 url: ajaxurl,
  30.                 type: 'POST',
  31.                 data: {
  32.                     action: 'get_new_gallery',
  33.                     gallery_ids: ids_string,
  34.                     seutema_ajax_gallery: nonce_val
  35.                 },
  36.             })
  37.             .done(function(data) {
  38.                 if (data.status == 'ok') {
  39.                     $('#seutema-page-gallery').empty().html(data.response);
  40.                 } else {
  41.                     alert('Ops... tivemos um erro carregando a nova galeria.');
  42.                 }
  43.             })
  44.             .fail(function() {
  45.                 alert('Ops... A conexão falhou, tente novamente daqui a pouco.');
  46.             });
  47.            
  48.         });
  49.     });
  50. });
Advertisement
Add Comment
Please, Sign In to add comment