...
Drupal.behaviors.designer = {
// attach is a property of Drupal.behaviors.designer, that points to a method.
// This method will later on get called by Drupal core on initialization.
attach: function (context, settings) {
// Here this doesn't make a lot of sense.
// Here you are writing height as if it were the property of an object.
// Technically it is not wrong syntax because everything in JavaScript is an
// an object. That means methods are objects too! Which also means that your
// attach() method above supports both properties and methods.
// However, here practically you are assigning the contents of settings.designer.jquery_modal_height
// to the height property of the attach() method.
height: settings.designer.jquery_modal_height,
}
};
...
So basically what you are saying above is
// Add the height property to the attach() method, and add some value to it.
Drupal.behaviors.designer.attach.height = settings.designer.jquery_modal_height;
I don't think you want to do that! Of all the Drupal JavaScript objects there are, I would not consider the attach() method the most durable object.
If you want to use the contents of settings.designer.jquery_modal_height, you either pass it to another method, or assign it to a more durable object. For example.
// Assuming you assigned the string "foo" to settings.designer.jquery_modal_height in PHP.
someFunction(param1, param2) {
console.log(param1);
console.log(param2);
}
var someRandomObject = {
aProperty = "";
someRandomMethod: function() {
console.log(this.aProperty);
}
}
Drupal.behaviors.designer = {
myCustomMethod: function(param) {
console.log(param);
}
attach: function (context, settings) {
// Consume the contents of settings.designer.jquery_modal_height.
// This should print your string properly.
// prints "foo"
console.log(settings.designer.jquery_modal_height);
// Could print "foo". Maybe you should consider accessing myCustomMethod() through
// the context variable passed into attach().
console.log(Drupal.behaviors.designer.myCustomMethod( settings.designer.jquery_modal_height);
// Probably won't work. "this" right now probably refers to "attach" and not "designer"
console.log(this.myCustomMethod(settings.designer.jquery_modal_height));
// Here we assign it to a local variable. Not a very durable storage location
// because we are within a closure right now. As soon as the attach() method
// finishes it's execution, localVar goes Ka-Poof!
var localVar = settings.designer.jquery_modal_height;
// But we can do some stuff with it in the meantime.
// Should print "foo bar".
someFunction(localVar, " bar");
// Here we store our "Drupal setting" in a relatively more durable object.
someRandomObject.aProperty = settings.designer.jquery_modal_height;
// Should print "foo".
someRandomObject.someRandomMethod().
}
};
So the short answer is: you're probably doing it wrong, revise your code ;)
heightis a paramater inside a function call, ex: $('.my-class').fancybox({ width: 720, height: settings.designer.jquery_modal_height, overlayShow: 1 }); If I try height: 400, things work as expected, and if I run console.log(settings.designer.jquery_modal_height) I see 400 in the console.console.log(settings.designer.jquery_modal_height)using the above code?height: 400works right. Then what you want is an integer in that property. It would seem that what you are getting is a "string literal". You could just try and cast that from a string literal to an integer in JavaScript. Also, in PHP, when setting up the property, are you assigning a string, or an integer to that property? My spider senses tell me you are assigning a string...