Passing an Array as a Config Option in jQuery plugin

Passing an Array as a Config Option in jQuery plugin

Hi,
I have posted this question on stack overflow to help me understand how to pass an array of objects in my plugin config option, but I have had no reply in the last 3 days. Would it be possible to know how I can pass an array inside my default config settings to allow users to add as many images as they like depending on the type of "array or parameter" that is provided.

The reason I am using arrays is depending on the type of array (desktop_xl[] , desktop_l[] , ipad_p[] , mobile_l[], mobile_p[]  ), the user will have the option to add as many images as they like inside different div containers. Please see below my plugin (my arrays are not connected with the default options yet.., thanks very much in advance for any help or advises:


  1. ;(function($, window, document, undefined){

  2. //define MyjQueryPlugin object with default config settings:
  3.     
  4. $.MyjQueryPlugin = {
  5. defaults: {
  6.             imagecontainer: "#container",
  7.             version: "v01",
  8.             transitionfx: "fade"   // "fade", "scrollHorz", "flipHorz", "shuffle", "tileSlide"
  9. // add my Arrays to default options here?
  10. // arrays should allow users to add as many images to #container div as they require
  11. // arrays are desktop_xl[] , desktop_l[] , ipad_p[] , mobile_l[], mobile_p[]  
  12. }
  13. };

  14.     
  15. //extend jquery with the plugin
  16. $.fn.extend({
  17.     MyjQueryPlugin:function(config) {
  18.     //use defaults or properties supplied by user
  19.     var config = $.extend({}, $.MyjQueryPlugin.defaults, config );
  20.     
  21. //append slides         
  22. $(config.imagecontainer).append('<div class="cycle-slideshow slides-xld" data-cycle-fx="'+ config.transitionfx +'" data-cycle-timeout="0" data-cycle-log="false" data-cycle-pager="#pagerxld" data-cycle-center-horz="true" data-cycle-auto-height="container"></div><div class="cycle-slideshow slides-ld" data-cycle-fx="'+ config.transitionfx +'" data-cycle-timeout="0" data-cycle-log="false" data-cycle-pager="#pagerld" data-cycle-center-horz="true" data-cycle-auto-height="container"></div><div class="cycle-slideshow slides-ipadp" data-cycle-fx="'+ config.transitionfx +'" data-cycle-timeout="0" data-cycle-log="false" data-cycle-pager="#pageripadp" data-cycle-center-horz="true" data-cycle-auto-height="container"></div><div class="cycle-slideshow slides-mobilel" data-cycle-fx="'+ config.transitionfx +'" data-cycle-timeout="0" data-cycle-log="false" data-cycle-pager="#pagermobilel" data-cycle-center-horz="true" data-cycle-auto-height="container"></div><div class="cycle-slideshow slides-mobilep" data-cycle-fx="'+ config.transitionfx +'" data-cycle-timeout="0" data-cycle-log="false" data-cycle-pager="#pagermobilep" data-cycle-center-horz="true" data-cycle-auto-height="container"></div>').css('height', $(window).height() );
  23.      
  24. // append MyjQueryPlugin sidebar
  25.     this.append( '<div id="Mysidebar" class="open">' +
  26.         '<p class="review">Version ' + config.version  + '- ready for review</p>'+
  27.         '<hr>' +
  28.         '</div>')
  29.         .children()
  30.         .css('height', $(window).height() );
  31.         
  32.       

  33. //create array of objects        
  34. var desktop_xl = [
  35.     {
  36.     "title":"Homepage", // text for sidebar
  37.     "src":"slides/1200/Homepage.jpg"// path to image >= 1200px wide
  38.     },
  39.        {
  40.     "title":"Categories", // text for sidebar
  41.     "src":"slides/1200/Categories.jpg"// path to image >= 1200px wide
  42.     },
  43.     {
  44.     "title":"Product description", // text for sidebar
  45.     "src":"slides/1200/Product_description.jpg" // path to image >= 1200px wide
  46.     }
  47. ];
  48.         
  49. var desktop_l = [
  50.     // if array is empty, remove elements from the page
  51. ];
  52.         
  53. var ipad_p = [
  54.     {
  55.     "title":"Homepage", // text for sidebar
  56.     "src":"slides/480/Homepage.jpg" // path to image >= 480px wide
  57.     }
  58. ]; 
  59. var mobile_l = [];        
  60. var mobile_p = [];
  61.         
  62. // set Global Variables
  63. var width           =   $(window).width();
  64. var currHeight      =   $(window).height();
  65. var ctrl            =   $(".ctrl");
  66. var ulscreenlia     =   $('ul.screen li a');
  67. var sidebarlia      =   $('#MyjQueryPluginsidebar li a');
  68. var sidebar         =   $("#MyjQueryPluginsidebar");
  69. var ulscreenli      =   $('ul.screen li');

  70. if (desktop_xl.length === 0) {
  71.   ulscreenli.eq(0).hide();
  72. $('div.select_join option[value="xld"]').remove();    
  73. }
  74. if (desktop_l.length === 0) {
  75.   ulscreenli.eq(1).hide();
  76. $('div.select_join option[value="ld"]').remove(); 
  77. }
  78. if (ipad_p.length === 0) {
  79.   ulscreenli.eq(2).hide();
  80. $('div.select_join option[value="ip"]').remove(); 
  81. }
  82. if (mobile_l.length === 0) {
  83.   ulscreenli.eq(3).hide();
  84. $('div.select_join option[value="ml"]').remove(); 
  85. }        
  86. if (mobile_p.length === 0) {
  87.   ulscreenli.eq(4).hide();
  88. $('div.select_join option[value="mp"]').remove(); 
  89. }
  90.         
  91.     //create img desktop_xl loop    
  92.     $.each(desktop_xl, function( index , value ){
  93.         
  94.         $('#container .slides-xld').append( 
  95.             //getting values from array but cannot understand how to pass array(s): desktop_xl, desktop_l, ipad_p, mobile_l, mobile_p  inside config option
  96.              //And Each arrays should allow user to add multiple images to #container dive
  97.                         $("<img />").attr({ 
  98.                                     id: value.title, 
  99.                                     src: value.src,
  100.                                     title: value.title
  101.                         })
  102.             
  103.          
  104.          );
  105.      });
  106.         
  107.        //create img ipadp loop    
  108.     $.each(ipad_p, function( index , value){
  109.         
  110.         $('#container .slides-ipadp').append( 
  111.             
  112.                         $("<img />").attr({ 
  113.                                     id: value.title, 
  114.                                     src: value.src,
  115.                                     title: value.title
  116.                                 })
  117.          );
  118.      });
  119.         
  120.       
  121. function rundateobject(){
  122.           
  123.             var current_date = new Date ( );
  124.             
  125.             var month_names = new Array ( );
  126.             month_names[month_names.length] = "January";
  127.             month_names[month_names.length] = "February";
  128.             month_names[month_names.length] = "March";
  129.             month_names[month_names.length] = "April";
  130.             month_names[month_names.length] = "May";
  131.             month_names[month_names.length] = "June";
  132.             month_names[month_names.length] = "July";
  133.             month_names[month_names.length] = "August";
  134.             month_names[month_names.length] = "September";
  135.             month_names[month_names.length] = "October";
  136.             month_names[month_names.length] = "November";
  137.             month_names[month_names.length] = "December";
  138.             
  139.             var day_names = new Array ( );
  140.             day_names[day_names.length] = "Sunday";
  141.             day_names[day_names.length] = "Monday";
  142.             day_names[day_names.length] = "Tuesday";
  143.             day_names[day_names.length] = "Wednesday";
  144.             day_names[day_names.length] = "Thursday";
  145.             day_names[day_names.length] = "Friday";
  146.             day_names[day_names.length] = "Saturday";
  147.             
  148.             $('#date').html( day_names[current_date.getDay()] 
  149.             + ', ' 
  150.             + month_names[current_date.getMonth()] 
  151.             + ' ' 
  152.             + current_date.getDate() 
  153.             + ' ' 
  154.             + current_date.getFullYear() );

  155. };

  156. //create animation for anchor links with jQuery DOM ready function        
  157. $(function(){     
  158.     $('a').hover(function(){
  159.           $(this).animate({
  160.              'margin-left':10,
  161.              'padding-left':20
  162.               
  163.           },200); 
  164.         $(this).dequeue(); 
  165.         },
  166.         function() {
  167.           $(this).animate({
  168.              'margin-left':0,
  169.              'padding-left':15
  170.           },200);
  171.             $(this).dequeue(); 
  172.         }        
  173.       );
  174. }); 
  175.        
  176. //on resize browser, adjust elements height
  177.         
  178.   
  179. //initialise plugins
  180. $(".nano").nanoScroller();   
  181.         
  182. //initialise functions
  183. rundateobject(); 
  184.     
  185. //return the jquery object for chaining
  186. return this;
  187.         
  188.   }// config options  
  189.    
  190. }); // jQuery extend
  191.  
  192.   
  193. })(jQuery, window, document);