Sunday, January 17, 2010

Lock content for free - simple

Here is my own script that locks down content
I wanted to keep it as simple as possible.

If you want a prof version that can handle lock down of content use
oldenstylehats' WP Guardian
http://www.blackhatworld.com/blackha...-discount.html

You can put what ever HTML you like inside the lightbox.
Content of the light box must be in the var lightDivHTML

Want to change the size of the lightbox locate this line:
divLight.style.cssText and alter the CSS.

Save this file as lock.js and put it in your root of your website.



Code:
var lightDivHTML = 'Close

This is your first visit. Hope you will enjoy it.
';

initDivs();
popUP();

function popUP()
{
var light = document.getElementById('light');
var fader = document.getElementById('fade');
var arrayPageSize = getPageSize();
light.style.display='block';
fader.style.height = (arrayPageSize[1] + 'px');
fader.style.display = 'block';
}

//Init divs
function initDivs() {
//Lightbox
var divLight = document.createElement("div");
divLight.id = "light";
divLight.style.cssText = "display: none;position: absolute;top: 150px;left: 350px;width: 400px;height: 250px;padding: 16px;border: none;background-color: white;overflow: auto;z-index:2;";
divLight.innerHTML = lightDivHTML;
document.body.appendChild(divLight);

//Shadow
var divFade = document.createElement("div");
divFade.id = "fade";
divFade.style.cssText = "display: none;position: absolute;top: 0px;left: 0px;width: 100%;background-color: black;-moz-opacity: 0.8;opacity:.80;filter: alpha(opacity=80);";
document.body.appendChild(divFade);
}


function getPageSize(){
var xScroll, yScroll;

if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}

var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}

// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}

// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}

arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}

//Close function
function closeDiv() {
light.style.display= 'none';
fade.style.display = 'none';
}
Your website you want to lock down - just include a reference to lock.js just above like this short example:

Code:
Here is your website or blog



No comments:

Post a Comment