SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question jQuery Help Needed

    Hello everyon,

    I have a small jQuery related task to complete, and keep failing to do so, unfortunately. I need to output the value of a custom defined variable, as follows:
    Code:
    $(document).ready(function()
    {
    	$('#preFeature').siteFeature({
                    outputElementId: 'CustomSliderName',
    	});
    	return false;
    });
    Below is the code to replace the default value with the custom defined one:
    Code:
    (function ($) {
        $.fn.siteFeature = function (b) {
            var c = $.extend({}, $.fn.siteFeature.defaults, b);
            return this.each(function (i) {
                obj = $(this);
                var a = {};
                a.which = i;
                createFeature(c, a);
                customizeFeature(c, a);
                eventFeature(c, a)
            })
        };
        $.fn.siteFeature.defaults = {
            outputElementId: 'siteFeature',
        };
    })(jQuery);
    
    function siteFeatureAutoPlayer(a)
    {
        var defaultSliderId = jQuery.fn.siteFeature.defaults.outputElementId; // this defines the default ID, works well
        var sliderID = jQuery.fn.siteFeature.......outputElementId; // need to fix this part
    }
    I can't figure out how to call the outputElementId variable in a function outside the jQuery class (see the red highlighted text). Could someone tell me the right way to do it, that would be much appreciated, thanks!

  2. #2
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I'd probably have to question why you would need to access the value of your default options outside of the plugin block.

    The idea of the default options that you can extend is that they are reasonably sane defaults set by the plugin that should not be changeable from the outside, but you can override them by passing in new values.

    I'd also recommend using clear variable names, "a", "b" and "c" aren't the most descriptive names.

    For more info on writing jQuery plugin code see:

    - http://docs.jquery.com/Plugins/Authoring
    - http://www.learningjquery.com/2007/1...opment-pattern
    - There's even a "plugin template builder" that will help you put some essentials together http://starter.pixelgraphics.us/
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found a solution, thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •