0

I'm using https://github.com/GBKS/Wookmark-jQuery to do some dynamic layout, i'm also attaching a function on window resize:

var $windowWidth = $window.width();
var options = {
        itemWidth: 100, 
        autoResize: true, 
        container: $('#tiles'), 
        offset: 5, 
        outerOffset: 0, 
        flexibleWidth: '30%' 
    };

if ($windowWidth >= 768 && $windowWidth <= 1200) {
    options.itemsize = 200;
    options.offset = 7;
} else if ($windowWidth > 1200) {  
    options.itemsize = 300;
    options.offset = 10;
}

$('#tiles li').woodmark(options); <-- this is fine

but i want to create a function to return the properties:

function getOptions() {
    var $windowWidth = $(window).width();
    var sizes = {
       itemsize: 100,
       offset: 5,
       autoResize: true, 
       outerOffset: 0,
       flexibleWidth: '30%' 
       }; 

    if ($windowWidth >= 768 && $windowWidth <= 1200) {
        sizes.itemsize = 200;
        sizes.offset = 7;
    } else if ($windowWidth > 1200) {
        sizes.itemsize = 300;
        sizes.offset = 10;
    }
   return sizes;
}

$('#tiles li').wookmark(getOptions); <-- doesn't work
$('#tiles li').wookmark(function() { getOptions }); <-- doesn't work

all the code samples in wookmark are done as a jquery plugin, and normal breakpoint doesn't work in chrome inspector..

Sterling Archer
  • 22,070
  • 18
  • 81
  • 118
Lee Gary
  • 2,357
  • 2
  • 22
  • 38
  • What's "wookmark" or "woodmark"? – gen_Eric Jan 17 '14 at 16:01
  • @RocketHazmat `wookmark` appears to be a jquery plugin for saving images – Sterling Archer Jan 17 '14 at 16:02
  • You're not executing the function... Do `$('#tiles li').wookmark(getOptions());` – crush Jan 17 '14 at 16:02
  • 1
    Have you tried `$('#tiles li').wookmark(getOptions());`? I'm assuming `wookmark` wants an object, not a function. You need to call `getOptions` to get the object from it. `wookmark` probably isn't programmed to call the function for you. – gen_Eric Jan 17 '14 at 16:02
  • 1
    P.S. This has nothing to do with JSON. JSON is a data transport format (like XML or CSV). You don't have a "JSON factory" here. You are creating a JavaScript object, not a JSON string. – gen_Eric Jan 17 '14 at 16:05
  • @RocketHazmat you are right, more like a javascript object literal? – Lee Gary Jan 17 '14 at 16:09
  • @LeeGary: Yeah, an object literal. I'm just a bit picky about terminology, sorry :-) – gen_Eric Jan 17 '14 at 16:09

1 Answers1

0

You need to pass .wookmark() an object, not a function. When called, getOptions() returns an object. When you do $('#tiles li').wookmark(getOptions);, the plugin has no idea what to do with the function you passed it, it wanted an object.

Try this:

$('#tiles li').wookmark(getOptions());
gen_Eric
  • 223,194
  • 41
  • 299
  • 337