// unite gallery, version: 1.7.45, released 27 feb 2017
var imgzoom = 1;
var smallimgheight = 68;
/**
* write something to debug line
*/
function debugline(html, addrandom, addhtml) {
if (html === true)
html = "true";
if (html === false)
html = "false";
var output = html;
if (typeof html == "object") {
output = "";
for (name in html) {
var value = html[name];
output += " " + name + ": " + value;
}
}
if (addrandom == true && !addhtml)
output += " " + math.random();
if (addhtml == true) {
var objline = jquery("#debug_line");
objline.width(200);
if (objline.height() >= 500)
objline.html("");
var currenthtml = objline.html();
output = currenthtml + "
--------------
" + output;
}
jquery("#debug_line").show().html(output);
}
/**
*
* debug side some object
*/
function debugside(obj) {
var html = "";
for (name in obj) {
var value = obj[name];
html += name + " : " + value + "
";
}
jquery("#debug_side").show().html(html);
}
/**
* output some string to console
*/
function trace(str) {
if (typeof console != "undefined")
console.log(str);
}
/** -------------- ugfunctions class ---------------------*/
function ugfunctions() {
var g_browserprefix = null;
var t = this;
var g_temp = {
startime: 0,
arrthemes: [],
istouchdevice: -1,
isrgbasupported: -1,
timecache: {},
datacache: {},
lasteventtype: "", //for validate touchstart click
lasteventtime: 0,
lasttouchstartelement: null,
touchthreshold: 700,
handle: null //interval handle
};
this.debugvar = "";
this.z__________full_screen___________ = function () { }
/**
* move to full screen mode
* fullscreen id - the id of current fullscreen
*/
this.tofullscreen = function (element, fullscreenid) {
if (element.requestfullscreen) {
element.requestfullscreen();
} else if (element.mozrequestfullscreen) {
element.mozrequestfullscreen();
} else if (element.webkitrequestfullscreen) {
element.webkitrequestfullscreen();
} else if (element.msrequestfullscreen) {
element.msrequestfullscreen();
} else {
return (false);
}
return (true);
}
/**
* exit full screen mode
* return if operation success (or if fullscreen mode supported)
*/
this.exitfullscreen = function () {
if (t.isfullscreen() == false)
return (false);
if (document.exitfullscreen) {
document.exitfullscreen();
} else if (document.cancelfullscreen) {
document.cancelfullscreen();
} else if (document.mozcancelfullscreen) {
document.mozcancelfullscreen();
} else if (document.webkitexitfullscreen) {
document.webkitexitfullscreen();
} else if (document.msexitfullscreen) {
document.msexitfullscreen();
} else {
return (false);
}
return (true);
}
/**
* cross browser attach even function
*/
function addevent(evnt, elem, func) {
if (elem.addeventlistener) // w3c dom
elem.addeventlistener(evnt, func, false);
else if (elem.attachevent) { // ie dom
elem.attachevent("on" + evnt, func);
}
else { // no much to do
elem[evnt] = func;
}
}
/**
* add fullscreen event to some function
*/
this.addfullscreenchangeevent = function (func) {
if (document["webkitcancelfullscreen"])
addevent("webkitfullscreenchange", document, func);
else if (document["msexitfullscreen"])
addevent("msfullscreenchange", document, func);
else if (document["mozcancelfullscreen"])
addevent("mozfullscreenchange", document, func);
else
addevent("fullscreenchange", document, func);
}
/**
* destroy the full screen change event
*/
this.destroyfullscreenchangeevent = function () {
jquery(document).unbind("fullscreenchange");
jquery(document).unbind("mozfullscreenchange");
jquery(document).unbind("webkitfullscreenchange");
jquery(document).unbind("msfullscreenchange");
}
/**
* get the fullscreen element
*/
this.getfullscreenelement = function () {
var fullscreenelement = document.fullscreenelement || document.mozfullscreenelement || document.webkitfullscreenelement || document.msfullscreenelement;
return (fullscreenelement);
}
/**
* return if fullscreen enabled
*/
this.isfullscreen = function () {
var isfullscreen = document.fullscreen || document.mozfullscreen || document.webkitisfullscreen || document.msfullscreenelement;
if (!isfullscreen)
isfullscreen = false;
else
isfullscreen = true;
return (isfullscreen);
}
this.z__________get_props___________ = function () { }
/**
* get browser prefix, can be empty if not detected.
*/
this.getbrowserprefix = function () {
if (g_browserprefix !== null)
return g_browserprefix;
var arrayofprefixes = ['webkit', 'moz', 'ms', 'o'];
var div = document.createelement("div");
for (var index in arrayofprefixes) {
var prefix = arrayofprefixes[index];
if (prefix + "transform" in div.style) {
prefix = prefix.tolowercase();
g_browserprefix = prefix;
return (prefix);
}
}
g_browserprefix = "";
return "";
}
/**
* get image inside parent data by image (find parent and size)
* scalemode: fit, down, fill, fitvert
*/
this.getimageinsideparentdatabyimage = function (objimage, scalemode, objpadding) {
var objparent = objimage.parent();
var objorgsize = t.getimageoriginalsize(objimage);
var objdata = t.getimageinsideparentdata(objparent, objorgsize.width, objorgsize.height, scalemode, objpadding);
return (objdata);
}
/**
* get data of image inside parent
* scalemode: fit, down, fill, fitvert
*/
this.getimageinsideparentdata = function (objparent, originalwidth, originalheight, scalemode, objpadding, maxwidth, maxheight) {
if (!objpadding)
var objpadding = {};
var objoutput = {};
if (typeof maxwidth === "undefined")
var maxwidth = objparent.width();
if (typeof maxheight === "undefined")
var maxheight = objparent.height();
if (objpadding.padding_left)
maxwidth -= objpadding.padding_left;
if (objpadding.padding_right)
maxwidth -= objpadding.padding_right;
if (objpadding.padding_top)
maxheight -= objpadding.padding_top;
if (objpadding.padding_bottom)
maxheight -= objpadding.padding_bottom;
var imagewidth = null;
var imageheight = "100%";
var imagetop = null;
var imageleft = null;
var style = "display:block;margin:0px auto;";
if (originalwidth > 0 && originalheight > 0) {
//get image size and position
if (scalemode == "down" && originalwidth < maxwidth && originalheight < maxheight) {
imageheight = originalheight;
imagewidth = originalwidth;
imageleft = (maxwidth - imagewidth) / 2;
imagetop = (maxheight - imageheight) / 2;
} else if (scalemode == "fill") {
var ratio = originalwidth / originalheight;
imageheight = maxheight;
imagewidth = imageheight * ratio;
if (imagewidth < maxwidth) {
imagewidth = maxwidth;
imageheight = imagewidth / ratio;
//center y position
imageleft = 0;
imagetop = math.round((imageheight - maxheight) / 2 * -1);
} else { //center x position
imagetop = 0;
imageleft = math.round((imagewidth - maxwidth) / 2 * -1);
}
}
else { //fit to borders
var ratio = originalwidth / originalheight;
imageheight = maxheight;
imagewidth = imageheight * ratio;
imagetop = 0;
imageleft = (maxwidth - imagewidth) / 2;
if (scalemode != "fitvert" && imagewidth > maxwidth) {
imagewidth = maxwidth;
imageheight = imagewidth / ratio;
imageleft = 0;
imagetop = (maxheight - imageheight) / 2;
}
}
imagewidth = math.floor(imagewidth);
imageheight = math.floor(imageheight);
imagetop = math.floor(imagetop);
imageleft = math.floor(imageleft);
style = "position:absolute;";
}
//set padding
if (objpadding.padding_top)
imagetop += objpadding.padding_top;
if (objpadding.padding_left)
imageleft += objpadding.padding_left;
objoutput.imagewidth = imagewidth;
objoutput.imageheight = imageheight;
objoutput.imagetop = imagetop;
objoutput.imageleft = imageleft;
objoutput.imageright = imageleft + imagewidth;
if (imagetop == 0 || imageheight == "100%")
objoutput.imagebottom = null;
else
objoutput.imagebottom = imagetop + imageheight;
objoutput.style = style;
return (objoutput);
}
/**
* get element center position inside parent
* even if the object bigger than the parent
*/
this.getelementcenterposition = function (element, objpadding) {
var parent = element.parent();
var objsize = t.getelementsize(element);
var objsizeparent = t.getelementsize(parent);
var parentwidth = objsizeparent.width;
var parentheight = objsizeparent.height;
if (objpadding && objpadding.padding_top !== undefined)
parentheight -= objpadding.padding_top;
if (objpadding && objpadding.padding_bottom !== undefined)
parentheight -= objpadding.padding_bottom;
if (objpadding && objpadding.padding_left !== undefined)
parentwidth -= objpadding.padding_left;
if (objpadding && objpadding.padding_right !== undefined)
parentwidth -= objpadding.padding_right;
var output = {};
output.left = math.round((parentwidth - objsize.width) / 2);
output.top = math.round((parentheight - objsize.height) / 2);
if (objpadding && objpadding.padding_top !== undefined)
output.top += objpadding.padding_top;
if (objpadding && objpadding.padding_left !== undefined)
output.left += objpadding.padding_left;
return (output);
}
/**
* get the center of the element
* includeparent - including left / right related to the parent
*/
this.getelementcenterpoint = function (element, includeparent) {
if (!includeparent)
var includeparent = false;
var objsize = t.getelementsize(element);
var output = {};
output.x = objsize.width / 2;
output.y = objsize.height / 2;
if (includeparent == true) {
output.x += objsize.left;
output.y += objsize.top;
}
output.x = math.round(output.x);
output.y = math.round(output.y);
return (output);
}
/**
*
* get mouse position from the event
* optimised to every device
*/
this.getmouseposition = function (event, element) {
var output = {
pagex: event.pagex,
pagey: event.pagey,
clientx: event.clientx,
clienty: event.clienty
};
if (event.originalevent && event.originalevent.touches && event.originalevent.touches.length > 0) {
output.pagex = event.originalevent.touches[0].pagex;
output.pagey = event.originalevent.touches[0].pagey;
output.clientx = event.originalevent.touches[0].clientx;
output.clienty = event.originalevent.touches[0].clienty;
}
/**
* get element's mouse position
*/
if (element) {
var elementpos = element.offset();
output.mousex = output.pagex - elementpos.left;
output.mousey = output.pagey - elementpos.top;
}
return (output);
}
/**
* get mouse element related point from page related point
*/
this.getmouseelementpoint = function (point, element) {
//rename the input and output
var newpoint = { x: point.pagex, y: point.pagey };
var elementpoint = t.getelementlocalpoint(newpoint, element);
return (elementpoint);
}
/**
* get element local point from global point position
*/
this.getelementlocalpoint = function (point, element) {
var elementpoint = {};
var elementpos = element.offset();
elementpoint.x = math.round(point.x - elementpos.left);
elementpoint.y = math.round(point.y - elementpos.top);
return (elementpoint);
}
/**
* get image oritinal size
* if originalwidth, originalheight is set, just return them.
*/
this.getimageoriginalsize = function (objimage, originalwidth, originalheight) {
if (typeof originalwidth != "undefined" && typeof originalheight != "undefined")
return ({ width: originalwidth, height: originalheight });
var htmlimage = objimage[0];
if (typeof htmlimage == "undefined")
throw new error("getimageoriginalsize error - image not found");
var output = {};
if (typeof htmlimage.naturalwidth == "undefined") {
//check from cache
if (typeof objimage.data("naturalwidth") == "number") {
var output = {};
output.width = objimage.data("naturalwidth");
output.height = objimage.data("naturalheight");
return (output);
}
//load new image
var newimg = new image();
newimg.src = htmlimage.src;
if (newimg.complete) {
output.width = newimg.width;
output.height = newimg.height;
//caching
objimage.data("naturalwidth", output.width);
objimage.data("naturalheight", output.height);
return (output);
}
return ({ width: 0, height: 0 });
} else {
output.width = htmlimage.naturalwidth;
output.height = htmlimage.naturalheight;
return (output);
}
}
/**
* get current image ratio from original size
*/
this.getimageratio = function (objimage) {
var originalsize = t.getimageoriginalsize(objimage);
var size = t.getelementsize(objimage);
var ratio = size.width / originalsize.width;
return (ratio);
}
/**
* tells if the image fit the parent (smaller then the parent)
*/
this.isimagefitparent = function (objimage) {
var objparent = objimage.parent();
var sizeimage = t.getelementsize(objimage);
var sizeparent = t.getelementsize(objparent);
if (sizeimage.width <= sizeparent.width && sizeimage.height <= sizeparent.height)
return (true);
return (false);
}
/**
* get size and position of some object
*/
this.getelementsize = function (element) {
if (element === undefined) {
throw new error("can't get size, empty element");
}
var obj = element.position();
obj.height = element.outerheight();
obj.width = element.outerwidth();
obj.left = math.round(obj.left);
obj.top = math.round(obj.top);
obj.right = obj.left + obj.width;
obj.bottom = obj.top + obj.height;
return (obj);
}
/**
* return true if the element is bigger then it's parent
*/
this.iselementbiggerthenparent = function (element) {
var objparent = element.parent();
var objsizeelement = t.getelementsize(element);
var objsizeparent = t.getelementsize(objparent);
if (objsizeelement.width > objsizeparent.width || objsizeelement.height > objsizeparent.height)
return (true);
return (false);
}
/**
* tells if the mouse point inside image
* the mouse point is related to image pos
*/
this.ispointinsideelement = function (point, objsize) {
var ismousexinside = (point.x >= 0 && point.x < objsize.width);
if (ismousexinside == false)
return (false);
var ismouseyinside = (point.y >= 0 && point.y < objsize.height);
if (ismouseyinside == false)
return (false);
return (true);
}
/**
* get element relative position according the parent
* if the left / top is offset text (left , center, right / top, middle , bottom)
* the element can be number size as well
*/
this.getelementrelativepos = function (element, pos, offset, objparent) {
if (!objparent)
var objparent = element.parent();
if (typeof element == "number") {
var elementsize = {
width: element,
height: element
};
} else
var elementsize = t.getelementsize(element);
var parentsize = t.getelementsize(objparent);
switch (pos) {
case "top":
case "left":
pos = 0;
if (offset)
pos += offset;
break;
case "center":
pos = math.round((parentsize.width - elementsize.width) / 2);
if (offset)
pos += offset;
break;
case "right":
pos = parentsize.width - elementsize.width;
if (offset)
pos -= offset;
break;
case "middle":
pos = math.round((parentsize.height - elementsize.height) / 2);
if (offset)
pos += offset;
break;
case "bottom":
pos = parentsize.height - elementsize.height;
if (offset)
pos -= offset;
break;
}
return (pos);
}
this.z_________set_element_props_______ = function () { }
/**
*
* zoom image inside parent
* the mouse point is page offset position, can be null
* return true if zoomed and false if not zoomed
*/
this.zoomimageinsideparent = function (objimage, zoomin, step, point, scalemode, maxzoomratio, objpadding) {
if (!step)
var step = 1.2;
if (!scalemode)
var scalemode = "fit";
var zoomratio = step;
var objparent = objimage.parent();
var objsize = t.getelementsize(objimage);
var objoriginalsize = t.getimageoriginalsize(objimage);
var ismouseinside = false;
var newheight, newwidth, panx = 0, pany = 0, newx, newy, panorientx = 0, panorienty = 0;
if (!point) {
ismouseinside = false;
} else {
var pointimg = t.getmouseelementpoint(point, objimage);
ismouseinside = t.ispointinsideelement(pointimg, objsize);
//if mouse point outside image, set orient to image center
panorientx = pointimg.x;
panorienty = pointimg.y;
}
if (ismouseinside == false) {
var imgcenterpoint = t.getelementcenterpoint(objimage);
panorientx = imgcenterpoint.x;
panorienty = imgcenterpoint.y;
}
//zoom:
if (zoomin == true) { //zoom in
newheight = objsize.height * zoomratio;
newwidth = objsize.width * zoomratio;
if (panorientx != 0)
panx = -(panorientx * zoomratio - panorientx);
if (panorienty != 0)
pany = -(panorienty * zoomratio - panorienty);
} else { //zoom out
newheight = objsize.height / zoomratio;
newwidth = objsize.width / zoomratio;
var objscaledata = t.getimageinsideparentdata(objparent, objoriginalsize.width, objoriginalsize.height, scalemode, objpadding);
//go back to original size
if (newwidth < objscaledata.imagewidth) {
t.scaleimagefitparent(objimage, objoriginalsize.width, objoriginalsize.height, scalemode, objpadding);
return (true);
}
if (ismouseinside == true) {
if (panorientx != 0)
panx = -(panorientx / zoomratio - panorientx);
if (panorienty != 0)
pany = -(panorienty / zoomratio - panorienty);
}
}
//check max zoom ratio, ix exeeded, abort
if (maxzoomratio) {
var expectedzoomratio = 1;
if (objoriginalsize.width != 0)
expectedzoomratio = newwidth / objoriginalsize.width;
if (expectedzoomratio > maxzoomratio)
return (false);
}
//resize the element
t.setelementsize(objimage, newwidth, newheight);
//set position:
//if zoom out and mouse point not inside image,
//get the image to center
if (zoomin == false && ismouseinside == false) {
var poscenter = t.getelementcenterposition(objimage);
newx = poscenter.left;
newy = poscenter.top;
} else {
newx = objsize.left + panx;
newy = objsize.top + pany;
}
t.placeelement(objimage, newx, newy);
return (true);
}
/**
* place some element to some position
* if the left / top is offset text (left , center, right / top, middle , bottom)
* then put it in parent by the offset.
*/
this.placeelement = function (element, left, top, offsetleft, offsettop, objparent) {
if (jquery.isnumeric(left) == false || jquery.isnumeric(top) == false) {
if (!objparent)
var objparent = element.parent();
var elementsize = t.getelementsize(element);
var parentsize = t.getelementsize(objparent);
}
//select left position
if (jquery.isnumeric(left) == false) {
switch (left) {
case "left":
left = 0;
if (offsetleft)
left += offsetleft;
break;
case "center":
left = math.round((parentsize.width - elementsize.width) / 2);
if (offsetleft)
left += offsetleft;
break;
case "right":
left = parentsize.width - elementsize.width;
if (offsetleft)
left -= offsetleft;
break;
}
}
//select top position
if (jquery.isnumeric(top) == false) {
switch (top) {
case "top":
top = 0;
if (offsettop)
top += offsettop;
break;
case "middle":
case "center":
top = math.round((parentsize.height - elementsize.height) / 2);
if (offsettop)
top += offsettop;
break;
case "bottom":
top = parentsize.height - elementsize.height;
if (offsettop)
top -= offsettop;
break;
}
}
var objcss = {
"position": "absolute",
"margin": "0px"
};
if (left !== null)
objcss.left = left;
if (top !== null)
objcss.top = top;
element.css(objcss);
}
/**
* place element inside parent center.
* the element should be absolute position
*/
this.placeelementinparentcenter = function (element) {
t.placeelement(element, "center", "middle");
}
/**
* set element size and position
*/
this.setelementsizeandposition = function (element, left, top, width, height) {
var objcss = {
"width": width + "px",
"height": height + "px",
"left": left + "px",
"top": top + "px",
"position": "absolute",
"margin": "0px"
}
element.css(objcss);
}
/**
* set widht and height of the element
*/
this.setelementsize = function (element, width, height) {
var objcss = {
"width": width + "px"
}
if (height !== null && typeof height != "undefined")
objcss["height"] = height + "px"
element.css(objcss);
}
/**
* clone element size and position
*/
this.cloneelementsizeandpos = function (objsource, objtarget, isouter, offsetx, offsety) {
var objsize = objsource.position();
if (objsize == undefined) {
throw new error("can't get size, empty element");
}
if (isouter === true) {
objsize.height = objsource.outerheight();
objsize.width = objsource.outerwidth();
} else {
objsize.height = objsource.height();
objsize.width = objsource.width();
}
objsize.left = math.round(objsize.left);
objsize.top = math.round(objsize.top);
if (offsetx)
objsize.left += offsetx;
if (offsety)
objsize.top += offsety;
t.setelementsizeandposition(objtarget, objsize.left, objsize.top, objsize.width, objsize.height);
}
/**
* place image inside parent, scale it by the options
* and scale it to fit the parent.
* scalemode: fit, down, fill
*/
this.placeimageinsideparent = function (urlimage, objparent, originalwidth, originalheight, scalemode, objpadding) {
var obj = t.getimageinsideparentdata(objparent, originalwidth, originalheight, scalemode, objpadding);
//set html image:
var htmlimage = "";
objparent.html(htmlimage);
//return the image just created
var objimage = objparent.children("img");
return (objimage);
}
/**
* scale image to fit parent, and place it into parent
* parent can be width , height, or object
*/
this.scaleimagecoverparent = function (objimage, objparent, pheight) {
if (typeof objparent == "number") {
var parentwidth = objparent;
var parentheight = pheight;
} else {
var parentwidth = objparent.outerwidth();
var parentheight = objparent.outerheight();
}
var objoriginalsize = t.getimageoriginalsize(objimage);
var imagewidth = objoriginalsize.width;
var imageheight = objoriginalsize.height;
var ratio = imagewidth / imageheight;
var fitheight = parentheight;
var fitwidth = fitheight * ratio;
var posy = 0, posx = 0;
if (fitwidth < parentwidth) {
fitwidth = parentwidth;
fitheight = fitwidth / ratio;
//center y position
posx = 0;
posy = math.round((fitheight - parentheight) / 2 * -1);
} else { //center x position
posy = 0;
posx = math.round((fitwidth - parentwidth) / 2 * -1);
}
fitwidth = math.round(fitwidth);
fitheight = math.round(fitheight);
objimage.css({
"width": fitwidth + "px",
"height": fitheight + "px",
"left": posx + "px",
"top": posy + "px"
});
}
/**
* resize image to fit the parent, scale it by the options
* scalemode: fit, down, fill
*/
this.scaleimagefitparent = function (objimage, originalwidth, originalheight, scalemode, objpadding) {
var objparent = objimage.parent();
var obj = t.getimageinsideparentdata(objparent, originalwidth, originalheight, scalemode, objpadding);
var updatecss = false;
var objcss = {};
if (obj.imagewidth !== null) {
updatecss = true
objimage.removeattr("width");
objcss["width"] = obj.imagewidth + "px";
}
if (obj.imageheight != null) {
updatecss = true
objimage.removeattr("height");
objcss["height"] = obj.imageheight + "px";
}
if (obj.imagetop !== null) {
updatecss = true;
objcss.top = obj.imagetop + "px";
}
if (obj.imageleft !== null) {
updatecss = true;
objcss.left = obj.imageleft + "px";
}
if (updatecss == true) {
objcss.position = "absolute";
objcss.margin = "0px 0px";
objimage.css(objcss);
}
return (obj);
}
/**
* scale image by height
*/
this.scaleimagebyheight = function (objimage, height, originalwidth, originalheight) {
var objoriginalsize = t.getimageoriginalsize(objimage, originalwidth, originalheight);
var ratio = objoriginalsize.width / objoriginalsize.height;
var width = math.round(height * ratio);
height = math.round(height);
t.setelementsize(objimage, width, height);
}
/**
* scale image by height
*/
this.scaleimagebywidth = function (objimage, width, originalwidth, originalheight) {
var objoriginalsize = t.getimageoriginalsize(objimage, originalwidth, originalheight);
var ratio = objoriginalsize.width / objoriginalsize.height;
var height = math.round(width / ratio);
width = math.round(width);
t.setelementsize(objimage, width, height);
}
/**
* scale image to exact size in parent, by setting image size and padding
*/
this.scaleimageexactsizeinparent = function (objimage, originalwidth, originalheight, exactwidth, exactheight, scalemode) {
var objparent = objimage.parent();
var parentsize = t.getelementsize(objparent);
if (parentsize.width < exactwidth)
exactwidth = parentsize.width;
if (parentsize.height < exactheight)
exactheight = parentsize.height;
var obj = t.getimageinsideparentdata(null, originalwidth, originalheight, scalemode, null, exactwidth, exactheight);
var imagewidth = exactwidth;
var imageheight = exactheight;
var paddingleft = obj.imageleft;
var paddingright = obj.imageleft;
var paddingtop = obj.imagetop;
var paddingbottom = obj.imagetop;
var imageleft = math.round((parentsize.width - exactwidth) / 2);
var imagetop = math.round((parentsize.height - exactheight) / 2);
var totalwidth = obj.imagewidth + paddingleft + paddingright;
var diff = exactwidth - totalwidth;
if (diff != 0)
paddingright += diff;
var totalheight = obj.imageheight + paddingtop + paddingbottom;
var diff = exactheight - totalheight;
if (diff != 0)
paddingbottom += diff;
//update css:
objimage.removeattr("width");
objimage.removeattr("height");
var objcss = {
position: "absolute",
margin: "0px 0px"
};
objcss["width"] = imagewidth + "px";
objcss["height"] = imageheight + "px";
objcss["left"] = imageleft + "px";
objcss["top"] = imagetop + "px";
objcss["padding-left"] = paddingleft + "px";
objcss["padding-top"] = paddingtop + "px";
objcss["padding-right"] = paddingright + "px";
objcss["padding-bottom"] = paddingbottom + "px";
objimage.css(objcss);
//return size object
var objreturn = {};
objreturn["imagewidth"] = imagewidth;
objreturn["imageheight"] = imageheight;
return (objreturn);
}
/**
* show some element and make opacity:1
*/
this.showelement = function (element, element2, element3) {
element.show().fadeto(0, 1);
if (element2)
element2.show().fadeto(0, 1);
if (element3)
element3.show().fadeto(0, 1);
}
this.z_________gallery_related_functions_______ = function () { }
/**
* disable button
*/
this.disablebutton = function (objbutton, classname) {
if (!classname)
var classname = "ug-button-disabled";
if (t.isbuttondisabled(objbutton, classname) == false)
objbutton.addclass(classname);
}
/**
* convert custom prefix options
* prefix - the prefix.
* base - after the prefix text. example lightbox_slider_option (lightbox - prefix, slider - base)
*/
this.convertcustomprefixoptions = function (objoptions, prefix, base) {
if (!prefix)
return (objoptions);
var modifiedoptions = {};
jquery.each(objoptions, function (key, option) {
if (key.indexof(prefix + "_" + base + "_") === 0) {
var newkey = key.replace(prefix + "_" + base + "_", base + "_");
modifiedoptions[newkey] = option;
} else {
modifiedoptions[key] = option;
}
});
return (modifiedoptions);
}
/**
* enable button
*/
this.enablebutton = function (objbutton, classname) {
if (!classname)
var classname = "ug-button-disabled";
if (t.isbuttondisabled(objbutton, classname) == true)
objbutton.removeclass(classname);
}
/**
* check if some buggon disabled
*/
this.isbuttondisabled = function (objbutton, classname) {
if (!classname)
var classname = "ug-button-disabled";
if (objbutton.hasclass(classname))
return (true);
return (false);
}
this.z_________math_functions_______ = function () { }
/**
*
* normalize the value for readable "human" setting value.
*/
this.normalizesetting = function (realmin, realmax, settingmin, settingmax, value, fixbounds) {
if (!fixbounds)
var fixbounds = false;
var ratio = (value - settingmin) / (settingmax - settingmin);
value = realmin + (realmax - realmin) * ratio;
if (fixbounds == true) {
if (value < realmin)
value = realmin;
if (value > realmax)
value = realmax;
}
return (value);
}
/**
*
* get "real" setting from normalized setting
*/
this.getnormalizedvalue = function (realmin, realmax, settingmin, settingmax, realvalue) {
var ratio = (realvalue - realmin) / (realmax - realmin);
realvalue = realmin + (settingmax - settingmin) * ratio;
return (realvalue);
}
/**
* get distance between 2 points
*/
this.getdistance = function (x1, y1, x2, y2) {
var distance = math.round(math.sqrt(math.abs(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))));
return distance;
}
/**
* get center point of the 2 points
*/
this.getmiddlepoint = function (x1, y1, x2, y2) {
var output = {}
output.x = x1 + math.round((x2 - x1) / 2);
output.y = y1 + math.round((y2 - y1) / 2);
return (output);
}
/**
* get number of items in space width gap
* even item sizes
* by lowest
*/
this.getnumitemsinspace = function (spacesize, itemssize, gapsize) {
var numitems = math.floor((spacesize + gapsize) / (itemssize + gapsize));
return (numitems);
}
/**
* get number of items in space width gap
* even item sizes
* by math.round
*/
this.getnumitemsinspaceround = function (spacesize, itemssize, gapsize) {
var numitems = math.round((spacesize + gapsize) / (itemssize + gapsize));
return (numitems);
}
/**
* get space (width in carousel for example) by num items, item size, and gap size
*/
this.getspacebynumitems = function (numitems, itemsize, gapsize) {
var space = numitems * itemsize + (numitems - 1) * gapsize;
return (space);
}
/**
* get item size by space and gap
*/
this.getitemsizeinspace = function (spacesize, numitems, gapsize) {
var itemsize = math.floor((spacesize - (numitems - 1) * gapsize) / numitems);
return (itemsize);
}
/**
* get column x pos with even column sizes, start from 0
*/
this.getcolx = function (col, colwidth, colgap) {
var posx = col * (colwidth + colgap);
return posx;
}
/**
* get column number by index
*/
this.getcolbyindex = function (numcols, index) {
var col = index % numcols;
return (col);
}
/**
* get col and row by index
*/
this.getcolrowbyindex = function (index, numcols) {
var row = math.floor(index / numcols);
var col = math.floor(index % numcols);
return ({ col: col, row: row });
}
/**
* get index by row, col, numcols
*/
this.getindexbyrowcol = function (row, col, numcols) {
if (row < 0)
return (-1);
if (col < 0)
return (-1);
var index = row * numcols + col;
return (index);
}
/**
* get previous row item in the same column
*/
this.getprevrowsamecolindex = function (index, numcols) {
var obj = t.getcolrowbyindex(index, numcols);
var previndex = t.getindexbyrowcol(obj.row - 1, obj.col, numcols);
return (previndex);
}
/**
* get next row item in the same column
*/
this.getnextrowsamecolindex = function (index, numcols) {
var obj = t.getcolrowbyindex(index, numcols);
var nextindex = t.getindexbyrowcol(obj.row + 1, obj.col, numcols);
return (nextindex);
}
this.z_________data_functions_______ = function () { }
/**
* set data value
*/
this.setglobaldata = function (key, value) {
jquery.data(document.body, key, value);
}
/**
* get global data
*/
this.getglobaldata = function (key) {
var value = jquery.data(document.body, key);
return (value);
}
this.z_________event_data_functions_______ = function () { }
/**
* handle scroll top, return if scroll mode or not
*/
this.handlescrolltop = function (storedeventid) {
if (t.istouchdevice() == false)
return (null);
var objdata = t.getstoredeventdata(storedeventid);
var horpass = 15;
var vertpass = 15;
//check if need to set some movement
if (objdata.scrolldir === null) {
if (math.abs(objdata.diffmousex) > horpass)
objdata.scrolldir = "hor";
else
if (math.abs(objdata.diffmousey) > vertpass && math.abs(objdata.diffmousey) > math.abs(objdata.diffmousex)) {
objdata.scrolldir = "vert";
objdata.scrollstarty = objdata.lastmouseclienty;
objdata.scrollorigin = jquery(document).scrolltop();
g_temp.datacache[storedeventid].scrollstarty = objdata.lastmouseclienty;
g_temp.datacache[storedeventid].scrollorigin = objdata.scrollorigin;
}
//update scrolldir
g_temp.datacache[storedeventid].scrolldir = objdata.scrolldir;
}
if (objdata.scrolldir !== "vert")
return (objdata.scrolldir);
var currentscroll = jquery(document).scrolltop();
var scrollpos = objdata.scrollorigin - (objdata.lastmouseclienty - objdata.scrollstarty);
if (scrollpos >= 0)
jquery(document).scrolltop(scrollpos);
return (objdata.scrolldir);
}
/**
* return true / false if was vertical scrolling
*/
this.wasverticalscroll = function (storedeventid) {
var objdata = t.getstoredeventdata(storedeventid);
if (objdata.scrolldir === "vert")
return (true);
return (false);
}
/**
* store event data
*/
this.storeeventdata = function (event, id, adddata) {
var mousepos = t.getmouseposition(event);
var time = jquery.now();
var obj = {
starttime: time,
lasttime: time,
startmousex: mousepos.pagex,
startmousey: mousepos.pagey,
lastmousex: mousepos.pagex,
lastmousey: mousepos.pagey,
startmouseclienty: mousepos.clienty,
lastmouseclienty: mousepos.clienty,
scrolltop: jquery(document).scrolltop(),
scrolldir: null
};
if (adddata)
obj = jquery.extend(obj, adddata);
g_temp.datacache[id] = obj;
}
/**
* update event data with last position
*/
this.updatestoredeventdata = function (event, id, adddata) {
if (!g_temp.datacache[id])
throw new error("updateeventdata error: must have stored cache object");
var obj = g_temp.datacache[id];
var mousepos = t.getmouseposition(event);
obj.lasttime = jquery.now();
if (mousepos.pagex !== undefined) {
obj.lastmousex = mousepos.pagex;
obj.lastmousey = mousepos.pagey;
obj.lastmouseclienty = mousepos.clienty;
}
if (adddata)
obj = jquery.extend(obj, adddata);
g_temp.datacache[id] = obj;
}
/**
* get stored event data
*/
this.getstoredeventdata = function (id, isvertical) {
if (!g_temp.datacache[id])
throw new error("updateeventdata error: must have stored cache object");
var obj = g_temp.datacache[id];
obj.diffmousex = obj.lastmousex - obj.startmousex;
obj.diffmousey = obj.lastmousey - obj.startmousey;
obj.diffmouseclienty = obj.lastmouseclienty - obj.startmouseclienty;
obj.difftime = obj.lasttime - obj.starttime;
//get mouse position according orientation
if (isvertical === true) {
obj.startmousepos = obj.lastmousey;
obj.lastmousepos = obj.lastmousey;
obj.diffmousepos = obj.diffmousey;
} else {
obj.startmousepos = obj.lastmousex;
obj.lastmousepos = obj.lastmousex;
obj.diffmousepos = obj.diffmousex;
}
return (obj);
}
/**
* return if click event approved according the done motion
*/
this.isapprovestoredeventclick = function (id, isvertical) {
if (!g_temp.datacache[id])
return (true);
var objdata = t.getstoredeventdata(id, isvertical);
var passeddistanceabs = math.abs(objdata.diffmousepos);
if (objdata.difftime > 400)
return (false);
if (passeddistanceabs > 30)
return (false);
return (true);
}
/**
* clear stored event data
*/
this.clearstoredeventdata = function (id) {
g_temp.datacache[id] = null;
}
this.z_________check_support_functions_______ = function () { }
/**
* is canvas exists in the browser
*/
this.iscanvasexists = function () {
var canvas = jquery('')[0];
if (typeof canvas.getcontext == "function")
return (true);
return (false);
}
/**
* tells if vertical scrollbar exists
*/
this.isscrollbarexists = function () {
var hasscrollbar = window.innerwidth > document.documentelement.clientwidth;
return (hasscrollbar);
}
/**
* check if this device are touch enabled
*/
this.istouchdevice = function () {
//get from cache
if (g_temp.istouchdevice !== -1)
return (g_temp.istouchdevice);
try {
document.createevent("touchevent");
g_temp.istouchdevice = true;
}
catch (e) {
g_temp.istouchdevice = false;
}
return (g_temp.istouchdevice);
}
/**
* check if
*/
this.isrgbasupported = function () {
if (g_temp.isrgbasupported !== -1)
return (g_temp.isrgbasupported);
var scriptelement = document.getelementsbytagname('script')[0];
var prevcolor = scriptelement.style.color;
try {
scriptelement.style.color = 'rgba(1,5,13,0.44)';
} catch (e) { }
var result = scriptelement.style.color != prevcolor;
scriptelement.style.color = prevcolor;
g_temp.isrgbasupported = result;
return result;
}
this.z_________general_functions_______ = function () { }
/**
* check if current jquery version is more then minimal version
* version can be "1.8.0" for example
*/
this.checkminjqueryversion = function (version) {
var arrcurrent = jquery.fn.jquery.split('.');
var arrmin = version.split('.');
for (var i = 0, len = arrcurrent.length; i < len; i++) {
var numcurrent = parseint(arrcurrent[i]);
var nummin = parseint(arrmin[i]);
if (typeof arrmin[i] == "undefined")
return (true);
if (nummin > numcurrent)
return (false);
if (numcurrent > nummin)
return (true);
}
//if all equal then all ok
return true;
}
/**
* get css size parameter, like width. if % given, leave it, if number without px - add px.
*/
this.getcsssizeparam = function (sizeparam) {
if (jquery.isnumeric(sizeparam))
return (sizeparam + "px");
return (sizeparam);
}
/**
* convert hex color to rgb color
*/
this.converthextorgb = function (hexinput, opacity) {
var hex = hexinput.replace('#', '');
if (hex === hexinput)
return (hexinput);
r = parseint(hex.substring(0, 2), 16);
g = parseint(hex.substring(2, 4), 16);
b = parseint(hex.substring(4, 6), 16);
result = 'rgba(' + r + ',' + g + ',' + b + ',' + opacity + ')';
return result;
}
/**
* get timestamp to string
*/
this.timestamptostring = function (stamp) {
var d = new date(stamp);
var str = d.getdate() + "/" + d.getmonth();
str += " " + d.gethours() + ":" + d.getminutes() + ":" + d.getseconds() + ":" + d.getmilliseconds();
return (str);
}
/**
* get touches array (if exists) from the event
*/
this.getarrtouches = function (event) {
var arrtouches = [];
if (event.originalevent && event.originalevent.touches && event.originalevent.touches.length > 0) {
arrtouches = event.originalevent.touches;
}
return (arrtouches);
}
/**
* extract touch positions from arrtouches
*/
this.getarrtouchpositions = function (arrtouches) {
var arroutput = [];
for (var i = 0; i < arrtouches.length; i++) {
var point = {
pagex: arrtouches[i].pagex,
pagey: arrtouches[i].pagey
};
arroutput.push(point);
}
return (arroutput);
}
/**
* start time debug
*/
this.starttimedebug = function () {
g_temp.startime = jquery.now();
}
/**
* show time debug
*/
this.showtimedebug = function () {
var endtime = jquery.now();
var difftime = endtime - g_temp.startime;
debugline({ "time passed": difftime }, true);
}
/**
* put progress indicator to some parent by type
* return the progress indicator object
*/
this.initprogressindicator = function (type, options, objparent) {
//check canvas compatability
if (type != "bar" && t.iscanvasexists() == false)
type = "bar";
//put the progress indicator
switch (type) {
case "bar":
var g_objprogress = new ugprogressbar();
g_objprogress.puthidden(objparent, options);
break;
default:
case "pie":
var g_objprogress = new ugprogresspie();
g_objprogress.puthidden(objparent, options);
break;
case "pie2":
options.type_fill = true;
var g_objprogress = new ugprogresspie();
g_objprogress.puthidden(objparent, options);
break;
}
return (g_objprogress);
}
/**
* add to button ug-nohover class on ipad
* need to be processed in css
*/
this.setbuttonmobileready = function (objbutton) {
objbutton.on("touchstart", function (event) {
//event.preventdefault();
jquery(this).addclass("ug-nohover");
});
objbutton.on("mousedown touchend", function (event) {
//debugline("button touchend",true,true);
//event.preventdefault();
event.stoppropagation();
event.stopimmediatepropagation();
//debugline(event.type, true, true);
return (false);
});
}
/**
* register gallery theme
*/
this.registertheme = function (themename) {
g_temp.arrthemes.push(themename);
}
/**
* get themes array
*/
this.getarrthemes = function () {
return (g_temp.arrthemes);
}
/**
* check if theme exists
*/
this.isthemeregistered = function (theme) {
if (jquery.inarray(theme, g_temp.arrthemes) !== -1)
return (true);
return (false);
}
/**
* get first registered theme name
*/
this.getfirstregisteredtheme = function () {
if (g_temp.arrthemes.length == 0)
return ("");
var themename = g_temp.arrthemes[0];
return (themename);
}
/**
* function checks if enought time passsed between function calls.
* good for filtering same time events
*/
this.istimepassed = function (handlername, timelimit) {
if (!timelimit)
var timelimit = 100;
var currenttime = jquery.now();
if (g_temp.timecache.hasownproperty(handlername) == false)
lasttime = 0;
else
lasttime = g_temp.timecache[handlername];
var difftime = currenttime - lasttime;
g_temp.timecache[handlername] = currenttime;
//debugline(difftime,true,true);
if (difftime <= timelimit)
return (false);
return (true);
}
/**
* check if continious event is over like resize
*/
this.whencontiniouseventover = function (handlername, oneventover, timelimit) {
if (!timelimit)
var timelimit = 300;
if (g_temp.timecache.hasownproperty(handlername) == true && g_temp.timecache[handlername] != null) {
cleartimeout(g_temp.timecache[handlername]);
g_temp.timecache[handlername] = null;
}
g_temp.timecache[handlername] = settimeout(oneventover, timelimit);
}
/**
* validate click and touchstart events.
* if click comes after touchstart, return false.
*/
this.validateclicktouchstartevent = function (eventtype) {
var returnval = true;
var diff = jquery.now() - g_temp.lasteventtime;
//debugline({lasttype:g_temp.lasteventtype, diff:diff},true, true);
if (eventtype == "click" && g_temp.lasteventtype == "touchstart" && diff < 1000)
returnval = false;
g_temp.lasteventtime = jquery.now();
g_temp.lasteventtype = eventtype;
return (returnval);
}
/**
* add some class on hover (hover event)
*/
this.addclassonhover = function (element, classname) {
if (!classname)
var classname = "ug-button-hover";
element.hover(function () {
jquery(this).addclass(classname);
}, function () {
jquery(this).removeclass(classname);
});
}
/**
* destroy hover effect on elements
*/
this.destroybutton = function (element) {
element.off("mouseenter");
element.off("mouseleave");
element.off("click");
element.off("touchstart");
element.off("touchend");
element.off("mousedown");
element.off("tap");
}
/**
* set button on click event, advanced
*/
this.setbuttononclick = function (objbutton, onclickfunction) {
t.setbuttonmobileready(objbutton);
objbutton.on("click touchstart", function (event) {
objthis = jquery(this);
event.stoppropagation();
event.stopimmediatepropagation();
if (t.validateclicktouchstartevent(event.type) == false)
return (true);
onclickfunction(objthis, event);
});
}
/**
* set button on tap
*/
this.setbuttonontap = function (objbutton, onclickfunction) {
//set the event
objbutton.on("tap", onclickfunction);
//set tap event trigger
if (t.istouchdevice() == false) {
objbutton.on("click", function (event) {
var objelement = jquery(this);
if (t.validateclicktouchstartevent(event.type) == false)
return (true);
objelement.trigger("tap");
});
} else {
//set tap event
objbutton.on("touchstart", function (event) {
var objelement = jquery(this);
objelement.addclass("ug-nohover");
g_temp.lasttouchstartelement = jquery(this);
g_temp.lasteventtime = jquery.now();
});
objbutton.on("touchend", function (event) {
var objelement = jquery(this);
//validate same element
if (objelement.is(g_temp.lasttouchstartelement) == false)
return (true);
//validate time passed
if (!g_temp.lasteventtime)
return (true);
var timepassed = jquery.now() - g_temp.lasteventtime;
if (timepassed > g_temp.touchthreshold)
return (true);
objelement.trigger("tap");
});
}
}
/**
* load javascript dynamically
*/
this.loadjs = function (url, addprotocol) {
if (addprotocol === true)
url = location.protocol + "//" + url;
var tag = document.createelement('script');
tag.src = url;
var firstscripttag = document.getelementsbytagname('script')[0];
firstscripttag.parentnode.insertbefore(tag, firstscripttag);
}
/**
* load css dymanically
*/
this.loadcss = function (url, addprotocol) {
if (addprotocol === true)
url = location.protocol + "//" + url;
var tag = document.createelement("link");
tag.setattribute("rel", "stylesheet");
tag.setattribute("type", "text/css");
tag.setattribute("href", url);
document.getelementsbytagname("head")[0].appendchild(tag);
}
/**
* add event listener with old browsers fallback
*/
this.addevent = function (elem, event, func) {
if (typeof (elem.addeventlistener) != "undefined") {
elem.addeventlistener(event, func, false);
} else if (elem.attachevent) {
elem.attachevent('on' + event, func);
}
}
/**
* fire event where all images are loaded
*/
this.checkimagesloaded = function (objimages, oncomplete, onprogress) {
var arrimages = [];
var counter = 0;
var numimages = objimages.length;
//if no images - exit
if (numimages == 0 && oncomplete) {
oncomplete();
return (false);
}
//nested function
function checkcomplete(image, iserror) {
counter++;
if (typeof onprogress == "function") {
settimeout(function () {
onprogress(image, iserror);
});
}
if (counter == numimages && typeof oncomplete == "function") {
settimeout(function () {
oncomplete();
});
}
}
//start a little later
settimeout(function () {
//start the function
for (var index = 0; index < numimages; index++) {
var image = objimages[index];
//arrimages.push(jquery(image));
if (image.naturalwidth !== undefined && image.naturalwidth !== 0) {
checkcomplete(objimages[index], false);
}
else {
var proxyimage = jquery('');
proxyimage.data("index", index);
proxyimage.on("load", function () {
var index = jquery(this).data("index");
checkcomplete(objimages[index], false);
});
proxyimage.on("error", function () {
var index = jquery(this).data("index");
checkcomplete(objimages[index], true);
});
proxyimage.attr("src", image.src);
}
}
});
}
/**
* run the function when the element size will be not 0
*/
this.waitforwidth = function (element, func) {
var width = element.width();
if (width != 0) {
func();
return (false);
}
g_temp.handle = setinterval(function () {
width = element.width();
if (width != 0) {
clearinterval(g_temp.handle);
func();
}
}, 300);
}
/**
* shuffle (randomise) array
*/
this.arrayshuffle = function (arr) {
if (typeof arr != "object")
return (arr);
for (var j, x, i = arr.length; i; j = parseint(math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
return arr;
}
/**
* get object length
*/
this.getobjectlength = function (object) {
var num = 0;
for (var item in object)
num++;
return num;
}
/**
* normalize the percent, return always between 0 and 1
*/
this.normalizepercent = function (percent) {
if (percent < 0)
percent = 0;
if (percent > 1)
percent = 1;
return (percent);
}
/**
* strip tags from string
*/
this.striptags = function (html) {
var text = html.replace(/(<([^>]+)>)/ig, "");
return (text);
}
/**
* escape double slash
*/
this.escapedoubleslash = function (str) {
return str.replace('"', '\"');
}
/**
* html entitles
*/
this.htmlentitles = function (html) {
var text = jquery('