Sha256: 073d4418c804332354010f8f5afbbcc433db8bf3036d0c4d8fc506afb1c109ef

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

/**
 * jQuery Serialize List
 * Copyright (c) 2009 Mike Botsko, Botsko.net LLC
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * Copyright notice and license must remain intact for legal use
 * Version .2
 *
 * Serialize an unordered or ordered list item. Optional ability
 * to determine which attributes are included. The serialization
 * will be read by PHP as a multidimensional array which you may
 * use for saving state.
 *
 * http://github.com/botskonet/jquery.serialize-list
 */

(function($) {
  $.fn.serializelist = function(options) {
    var defaults = {
        attributes: ['id'],
        allow_nest: true,
        prepend: 'ul',
        att_regex: false,
        is_child: false
      },
      opts = $.extend(defaults, options),
      attrs = opts.attributes,
      serialStr = '',
      val, x, att, child_base;

    var att_rep = function(att, val) {
      if(!opts.att_regex) { return val; }
			  
			for(x in opts.att_regex) {
				if(opts.att_regex[x].att === att) {
					return val.replace(opts.att_regex[x].regex, '');
				}
			}
		};

    if(!opts.is_child) { opts.prepend = '&' + opts.prepend; }

    this.each(function(ul_count, ul) {
      $(ul).children().each(function(li_count, li) {
    		if(opts.allow_nest || attrs.length > 1) {
    			for(att in attrs) {
    				val = att_rep(attrs[att], $(li).attr(attrs[att]));
    				serialStr += opts.prepend+'['+ul_count+']['+li_count+']['+attrs[att]+']='+val;
    			}
    		} else {
    			val = att_rep(attrs[0], $(li).attr(attrs[0]));
    			serialStr += opts.prepend+'['+ul_count+']['+li_count+']='+val;
    		}
    
    		if(opts.allow_nest) {
    			child_base = opts.prepend+'['+ul_count+']['+li_count+'][children]';
    			$(li).children().each(function() {
    				if(this.tagName == 'UL' || this.tagName == 'OL') {
    					serialStr += $(this).serializelist({'prepend': child_base, 'is_child': true});
    				}
    			});
    		}
    		
        li_count++;
      });
    });
    
    return(serialStr);
  };
})(jQuery);

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
refinerycms-sidebar-2.0.0.dev spec/dummy/tmp/dragonfly/cache/body/93/ebbf02317e13e58c1cac8cde30f3e2c81fe37a
refinerycms-menus-2.0.7 spec/dummy/tmp/dragonfly/cache/body/93/ebbf02317e13e58c1cac8cde30f3e2c81fe37a
refinerycms-menus-2.0.6 spec/dummy/tmp/dragonfly/cache/body/93/ebbf02317e13e58c1cac8cde30f3e2c81fe37a