Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery scoped settings for plugin based on Plugins/Authoring article
    primarykey
    data
    text
    <p>I have a jQuery plugin which follows the Plugins/Authoring example from docs.jQuery.com and I am having trouble figuring out how to keep unique settings for each element the plugin is applied to. There are two elements on the page each having the plugin applied to them separately.</p> <p>Here is my code so far:</p> <pre><code>(function( $ ) { /* Default settings */ var defaults = { id: null, properties: null, container: '.comp-settings', /* override for .retail or .distressed */ priceLabel: '.comp-section-header span', slide: slideCallback, minRange: 100000 }; /* Some public here: $.compSlider('method', options) */ var methods = { init: function( options ) { var settings = $.extend( {}, defaults, options ); return this.each(function() { $(this).slider( settings ); }); } } /* Some methods here */ function opt( name ) { return settings[ name ]; } /* Plugin namespace */ $.fn.compSlider = function( method ) { // Method calling logic if ( methods[method] ) { return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); } else if ( typeof method === 'object' || ! method ) { return methods.init.apply( this, arguments ); } else if ( typeof method === 'string' ) { return this.slider( method, Array.prototype.slice.call( arguments, 1 ) ); } }; })( jQuery ) </code></pre> <p>Issues:</p> <ol> <li>The settings variable isn't accessible in the plugins functions</li> <li>If I store the settings variable in $(this).data('settings') I still can't access $(this).data('settings') from the 'opt' function because "this" isn't the element (I believe it's the DOM window.)</li> </ol> <p>Any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload