Advertisement
Guest User

Untitled

a guest
Aug 28th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // function to create an array of input values
  2.     function ids(inputs) {
  3.         var a = [];
  4.         for (var i = 0; i < inputs.length; i++) {
  5.             a.push(inputs[i].val);
  6.         }
  7.         //$("span").text(a.join(" "));
  8.     }
  9.     // repeatable fields
  10.     $('.meta_box_repeatable_add').live('click', function() {
  11.         // clone
  12.         var row = $(this).closest('.meta_box_repeatable').find('tbody tr:last-child');
  13.         var clone = row.clone();
  14.         clone.find('select.chosen').removeAttr('style', '').removeAttr('id', '').removeClass('chzn-done').data('chosen', null).next().remove();
  15.         clone.find('input.regular-text, textarea, select').val('');
  16.         clone.find('input[type=checkbox], input[type=radio]').attr('checked', false);
  17.         row.after(clone);
  18.         // increment name and id
  19.         clone.find('input, textarea, select')
  20.             .attr('name', function(index, name) {
  21.                 return name.replace(/(\d+)/, function(fullMatch, n) {
  22.                     return Number(n) + 1;
  23.                 });
  24.             });
  25.         var arr = [];
  26.         $('input.repeatable_id:text').each(function(){ arr.push($(this).val()); });
  27.         clone.find('input.repeatable_id')
  28.             .val(Number(Math.max.apply( Math, arr )) + 1);
  29.         if (!!$.prototype.chosen) {
  30.             clone.find('select.chosen')
  31.                 .chosen({allow_single_deselect: true});
  32.         }
  33.         //
  34.         return false;
  35.     });
  36.    
  37.     $('.meta_box_repeatable_remove').live('click', function(){
  38.         $(this).closest('tr').remove();
  39.         return false;
  40.     });
  41.        
  42.     $('.meta_box_repeatable tbody').sortable({
  43.         opacity: 0.6,
  44.         revert: true,
  45.         cursor: 'move',
  46.         handle: '.hndle'
  47.     });
  48.    
  49.     // post_drop_sort  
  50.     $('.sort_list').sortable({
  51.         connectWith: '.sort_list',
  52.         opacity: 0.6,
  53.         revert: true,
  54.         cursor: 'move',
  55.         cancel: '.post_drop_sort_area_name',
  56.         items: 'li:not(.post_drop_sort_area_name)',
  57.         update: function(event, ui) {
  58.             var result = $(this).sortable('toArray');
  59.             var thisID = $(this).attr('id');
  60.             $('.store-' + thisID).val(result)
  61.         }
  62.     });
  63.  
  64.     $('.sort_list').disableSelection();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement