///////////////////////////////////////////////////////////////////////////////
// Floating Action Button //
// COPYRIGHT 2008-2015 Josh Abbott and Robert Puddy //
// http://floatingactionbutton.com //
// //
// All Rights Reserved //
///////////////////////////////////////////////////////////////////////////////
// Position Constants
var LEFT = 1;
var MIDDLE = 2;
var RIGHT = 3;
var TOP = 1;
var BOTTOM =3;
// Selected Position of Button
var hAlign = LEFT;
var vAlign = BOTTOM;
// Padding/Margin Left/Right Margin Top/Bottom Margin
var fabHMargin = 2;
var fabVMargin = 20;
var fabStartDelay = 1000;
var fabSlideTime = 700;
var fabOpacity = 1;
xAddEventListener(window, 'load',
function () {
var e = xCreateElement('DIV');
e.id = "divActionButton";
e.style.backgroundColor = "";
e.style.padding = "10";
xInnerHtml(e, "
|
X |
This is a Floating Action Button. It will follow you as you scroll down the salespage, so you can just click the button whenever you're ready to order! Create unlimited buttons just like this for a one-time payment of only $37.95 |
|
");
document.body.appendChild(e);
xOpacity("divActionButton",fabOpacity);
setTimeout("winOnResize()",fabStartDelay);
xAddEventListener(window, 'resize', winOnResize, false);
xAddEventListener(window, 'scroll', winOnScroll, false);
}, false
);
function closeFab() {
xInnerHtml('divActionButton', "");
xVisibility('divActionButton', false);
}
function winOnResize() {
xMoveTo('divActionButton', calculateXpos(), calculateYpos());
xVisibility('divActionButton', true);
winOnScroll(); // initial slide
}
function winOnScroll() {
xSlideTo('divActionButton', calculateXpos(), calculateYpos(), fabSlideTime);
}
function calculateXpos() {
switch(hAlign) {
case LEFT: return fabHMargin;
case MIDDLE: return (xClientWidth()/2) - (xWidth('divActionButton')/2);
case RIGHT: return xClientWidth()-xWidth('divActionButton') - fabHMargin;
}
}
function calculateYpos() {
switch(vAlign) {
case TOP: return xScrollTop() + fabVMargin;
case MIDDLE: return xScrollTop() + ((xClientHeight()/2) - (xHeight('divActionButton')/2));
case BOTTOM: return xScrollTop() + xClientHeight()-xHeight('divActionButton') - fabVMargin;
}
}
// XBrowser Functions below
/* Compiled from X 4.17 by XC 1.06 on 17Nov07 */
xLibrary={version:'4.17',license:'GNU LGPL',url:'http://cross-browser.com/'};
// xAddEventListener r8, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xAddEventListener(e,eT,eL,cap)
{
if(!(e=xGetElementById(e)))return;
eT=eT.toLowerCase();
if(e.addEventListener)e.addEventListener(eT,eL,cap||false);
else if(e.attachEvent)e.attachEvent('on'+eT,eL);
else {
var o=e['on'+eT];
e['on'+eT]=typeof o=='function' ? function(v){o(v);eL(v);} : eL;
}
}
// xCamelize r1, Copyright 2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xCamelize(cssPropStr)
{
var i, c, a = cssPropStr.split('-');
var s = a[0];
for (i=1; iw.innerWidth) v-=16;
}
return v;
}
// xClientWidth r5, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xClientWidth()
{
var v=0,d=document,w=window;
if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientWidth)
{v=d.documentElement.clientWidth;}
else if(d.body && d.body.clientWidth)
{v=d.body.clientWidth;}
else if(xDef(w.innerWidth,w.innerHeight,d.height)) {
v=w.innerWidth;
if(d.height>w.innerHeight) v-=16;
}
return v;
}
// xDef r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xDef()
{
for(var i=0; i=0) {
var pt=0,pb=0,bt=0,bb=0;
if (document.compatMode=='CSS1Compat') {
var gcs = xGetComputedStyle;
pt=gcs(e,'padding-top',1);
if (pt !== null) {
pb=gcs(e,'padding-bottom',1);
bt=gcs(e,'border-top-width',1);
bb=gcs(e,'border-bottom-width',1);
}
// Should we try this as a last resort?
// At this point getComputedStyle and currentStyle do not exist.
else if(xDef(e.offsetHeight,e.style.height)){
e.style.height=h+'px';
pt=e.offsetHeight-h;
}
}
h-=(pt+pb+bt+bb);
if(isNaN(h)||h<0) return;
else e.style.height=h+'px';
}
h=e.offsetHeight;
}
else if(css && xDef(e.style.pixelHeight)) {
if(h>=0) e.style.pixelHeight=h;
h=e.style.pixelHeight;
}
return h;
}
// xLeft r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xLeft(e, iX)
{
if(!(e=xGetElementById(e))) return 0;
var css=xDef(e.style);
if (css && xStr(e.style.left)) {
if(xNum(iX)) e.style.left=iX+'px';
else {
iX=parseInt(e.style.left);
if(isNaN(iX)) iX=xGetComputedStyle(e,'left',1);
if(isNaN(iX)) iX=0;
}
}
else if(css && xDef(e.style.pixelLeft)) {
if(xNum(iX)) e.style.pixelLeft=iX;
else iX=e.style.pixelLeft;
}
return iX;
}
// xMoveTo r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xMoveTo(e,x,y)
{
xLeft(e,x);
xTop(e,y);
}
// xNum r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xNum()
{
for(var i=0; i=0) {
var pl=0,pr=0,bl=0,br=0;
if (document.compatMode=='CSS1Compat') {
var gcs = xGetComputedStyle;
pl=gcs(e,'padding-left',1);
if (pl !== null) {
pr=gcs(e,'padding-right',1);
bl=gcs(e,'border-left-width',1);
br=gcs(e,'border-right-width',1);
}
// Should we try this as a last resort?
// At this point getComputedStyle and currentStyle do not exist.
else if(xDef(e.offsetWidth,e.style.width)){
e.style.width=w+'px';
pl=e.offsetWidth-w;
}
}
w-=(pl+pr+bl+br);
if(isNaN(w)||w<0) return;
else e.style.width=w+'px';
}
w=e.offsetWidth;
}
else if(css && xDef(e.style.pixelWidth)) {
if(w>=0) e.style.pixelWidth=w;
w=e.style.pixelWidth;
}
return w;
}
// xCreateElement r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xCreateElement(sTag)
{
if (document.createElement) return document.createElement(sTag);
else return null;
}
// xInnerHtml r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xInnerHtml(e,h)
{
if(!(e=xGetElementById(e)) || !xStr(e.innerHTML)) return null;
var s = e.innerHTML;
if (xStr(h)) {e.innerHTML = h;}
return s;
}