Percentage Width/Height

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Percentage Width/Height

mdodge
I recently had a need to use shadowbox with percentage widths/heights, and modded the code to accomplish this. The following is how I implemented it for an iframe. If someone wants to make this a global change, feel free.

Search for this text (around line 1350):

var h = obj.height ? parseInt(obj.height, 10) : SL.getViewportHeight();
var w = obj.width ? parseInt(obj.width, 10) : SL.getViewportWidth();

And replace with the following:

var get_size = function(size,dimension) {
   size = size.toString();
   if (size.substring(size.length - 1) == "%") {
     // Percentage
     size = size.substring(0, size.length - 1);
     var pagesize = (dimension == 'h' ? SL.getViewportHeight() : SL.getViewportWidth());
     return Math.floor(pagesize*size/100);
   } else {
     return parseInt(size, 10);
   }
}
var h = obj.height ? get_size(obj.height,'h') : SL.getViewportHeight();
var w = obj.width ? get_size(obj.width,'w') : SL.getViewportWidth();

Enjoy!
Reply | Threaded
Open this post in threaded view
|

Re: Percentage Width/Height

Wizzud
Neat.

Can reduce slightly...

var getSize = function(vp, wh) {
  if(!wh){
    return vp;
  }else{
    wh = (wh+'').split('%');
    return wh.length > 1 ? Math.floor(vp*wh[0]/100) : parseInt(wh[0], 10);
  }
};
var h = getSize(SL.getViewportHeight(), obj.height);
var w = getSize(SL.getViewportWidth(), obj.width);
Combine literacy with curiosity and a whole world of information opens up to you
Reply | Threaded
Open this post in threaded view
|

Re: Percentage Width/Height

talisien
In reply to this post by mdodge
I've looked for this code

var h = obj.height ? parseInt(obj.height, 10) : SL.getViewportHeight();
var w = obj.width ? parseInt(obj.width, 10) : SL.getViewportWidth();

but can't find it anywhere!

In which file do i have to look for this?
Reply | Threaded
Open this post in threaded view
|

Re: Percentage Width/Height

Rody van Sambeek
You can look for the code in the src/player/shadowbox-iframe.js around line 54.

Rody van Sambeek
Reply | Threaded
Open this post in threaded view
|

Re: Percentage Width/Height

talisien
Thanks,

This is what I've found at line 41

 Shadowbox.iframe = function(id, obj){
        this.id = id;
        this.obj = obj;

        // height defaults to full viewport height
        this.height = this.obj.height ? parseInt(this.obj.height, 10) : SL.getViewportHeight();

        // width defaults to full viewport width
        this.width = this.obj.width ? parseInt(this.obj.width, 10) : SL.getViewportWidth();
    };

I bit different then the code shown in previous post about this topic, but maybe it will work too?

Rody van Sambeek wrote
You can look for the code in the src/player/shadowbox-iframe.js around line 54.

Rody van Sambeek
Reply | Threaded
Open this post in threaded view
|

Re: Percentage Width/Height

Zante
This post was updated on .
In reply to this post by mdodge
My iframe file doesn't have anything near 1350 lines. What's going on?

How can I get this working with just the build version and not the source one? I can't seem to work with the src version as it's beyond my capability to install.

Edit: Got it all working. Great stuff. :]</panic attack>
Reply | Threaded
Open this post in threaded view
|

Re: Percentage Width/Height

evanmoore
In reply to this post by mdodge
Could I see an example of why this would be used or could I at least see how yours is functioning?

Thanks!

Evan
sdf
Reply | Threaded
Open this post in threaded view
|

Re: Percentage Width/Height

sdf
In reply to this post by mdodge
SL.getViewportHeight();
In the above method SL Means what?