';
//add layer specific html
switch(type){
case "image":
html += '
';
break;
default:
case "text":
html += objLayer.text;
break;
case "video":
var styleVideo = "width:"+objLayer.video_width+"px;height:"+objLayer.video_height+"px;";
switch(objLayer.video_type){
case "youtube":
case "vimeo":
styleVideo += ";background-image:url("+objLayer.video_image_url+");";
break;
case "html5":
if(objLayer.video_image_url !== undefined && objLayer.video_image_url != "")
styleVideo += ";background-image:url("+objLayer.video_image_url+");";
break;
}
html += "
"
html += "
" + objLayer.video_title + "
";
html += "
";
break;
}
//add cross icon:
html += "
";
html += '
';
return(html);
}
/**
* update layer by data object
*/
var updateLayer = function(serial,objData){
var layer = getLayer(serial);
if(!layer)
return(false);
for(key in objData){
layer[key] = objData[key];
}
setLayer(serial,layer);
}
/**
* update current layer
*/
var updateCurrentLayer = function(objData){
if(!arrLayers[selectedLayerSerial]){
UniteAdminRev.showErrorMessage("error! the layer with serial: "+selectedLayerSerial+" don't exists");
return(false);
}
updateLayer(selectedLayerSerial,objData);
}
/**
* add image layer
*/
var addLayerImage = function(urlImage){
objLayer = {
style : "",
text : "Image " + (id_counter+1),
type : "image",
image_url : urlImage
};
addLayer(objLayer);
}
/**
* get video layer object from video data
*/
var getVideoObjLayer = function(videoData){
var objLayer = {
type:"video",
style : "",
video_type: videoData.video_type,
video_width:videoData.width,
video_height:videoData.height,
video_data:videoData
};
if(objLayer.video_type == "youtube" || objLayer.videoType == "vimeo"){
objLayer.video_id = videoData.id;
objLayer.video_title = videoData.title;
objLayer.video_image_url = videoData.thumb_medium.url;
objLayer.video_args = videoData.args;
}
//set sortbox text
switch(objLayer.video_type){
case "youtube":
objLayer.text = "Youtube: " + videoData.title;
break;
case "vimeo":
objLayer.text = "Vimeo: " + videoData.title;
break;
case "html5":
objLayer.text = "Html5 Video";
objLayer.video_title = objLayer.text;
objLayer.video_image_url = "";
if(videoData.urlPoster != "")
objLayer.video_image_url = videoData.urlPoster;
break;
}
return(objLayer);
}
/**
* add video layer
*/
var addLayerVideo = function(videoData){
var objLayer = getVideoObjLayer(videoData);
addLayer(objLayer);
}
/**
* add text layer
*/
var addLayerText = function(){
var objLayer = {
text:initText + (id_counter+1),
type:"text"
};
addLayer(objLayer);
}
/**
* add layer
*/
var addLayer = function(objLayer,isInit){
if(!isInit)
var isInit = false;
//set init fields (if not set):
if(objLayer.order == undefined)
objLayer.order = (id_counter);
objLayer.order = Number(objLayer.order);
//set init position
if(objLayer.type == "video"){
if(objLayer.left == undefined)
objLayer.left = initLeftVideo;
if(objLayer.top == undefined)
objLayer.top = initTopVideo;
objLayer = checkUpdateFullwidthVideo(objLayer);
}else{
if(objLayer.left == undefined)
objLayer.left = initLeft;
if(objLayer.top == undefined)
objLayer.top = initTop;
}
//set animation:
if(objLayer.animation == undefined)
objLayer.animation = jQuery("#layer_animation").val();
//set easing:
if(objLayer.easing == undefined)
objLayer.easing = jQuery("#layer_easing").val();
//set speed:
if(objLayer.speed == undefined)
objLayer.speed = initSpeed;
if(objLayer.align_hor == undefined)
objLayer.align_hor = "left";
if(objLayer.align_vert == undefined)
objLayer.align_vert = "top";
//set animation:
if(objLayer.hiddenunder == undefined)
objLayer.hiddenunder = "";
if(objLayer.resizeme == undefined)
objLayer.resizeme = "";
//set image link
if(objLayer.link == undefined)
objLayer.link = "";
//set image link open in
if(objLayer.link_open_in == undefined)
objLayer.link_open_in = "same";
//set slide link:
if(objLayer.link_slide == undefined)
objLayer.link_slide = "nothing";
//set scroll under offset
if(objLayer.scrollunder_offset == undefined)
objLayer.scrollunder_offset = "";
//set style, if empty, add first style from the list
if(objLayer.style == undefined)
objLayer.style = jQuery("#layer_caption").val();
objLayer.style = jQuery.trim(objLayer.style);
if(isInit == false && objLayer.type == "text" && (!objLayer.style || objLayer.style == "") ){
objLayer.style = getFirstStyle();
}
//add time
if(objLayer.time == undefined)
objLayer.time = getNextTime();
objLayer.time = Number(objLayer.time); //casting
//end time:
if(objLayer.endtime == undefined)
objLayer.endtime = "";
if(objLayer.endspeed == undefined)
objLayer.endspeed = initSpeed;
//set end animation:
if(objLayer.endanimation == undefined)
objLayer.endanimation = jQuery("#layer_endanimation").val();
//set end easing:
if(objLayer.endeasing == undefined)
objLayer.endeasing = jQuery("#layer_endeasing").val();
//set corners
if(objLayer.corner_left == undefined)
objLayer.corner_left = "nothing";
if(objLayer.corner_right == undefined)
objLayer.corner_right = "nothing";
//round position
objLayer.top = Math.round(objLayer.top);
objLayer.left = Math.round(objLayer.left);
objLayer.serial = id_counter;
arrLayers[id_counter] = objLayer;
//add html
var htmlLayer = makeLayerHtml(id_counter,objLayer);
container.append(htmlLayer);
var objHtmlLayer = getHtmlLayerFromSerial(id_counter);
//update layer position
updateHtmlLayerPosition(objHtmlLayer,objLayer.top,objLayer.left,objLayer.align_hor,objLayer.align_vert);
//update corners
updateHtmlLayerCorners(objHtmlLayer,objLayer);
//update cross position
updateCrossIconPosition(objHtmlLayer,objLayer);
//add layer to sortbox
addToSortbox(id_counter,objLayer);
//refresh draggables
refreshEvents(id_counter);
id_counter++;
//enable "delete all" button, not event, but anyway :)
jQuery("#button_delete_all").removeClass("button-disabled");
//select the layer
if(isInit == false){
setLayerSelected(objLayer.serial);
jQuery("#layer_text").focus();
}
}
/**
*
* delete layer from layers object
*/
var deleteLayerFromObject = function(serial){
var arrLayersNew = {};
var flagFound = false;
for (key in arrLayers){
if(key != serial)
arrLayersNew[key] = arrLayers[key];
else
flagFound = true;
}
if(flagFound == false)
UniteAdminRev.showErrorMessage("Can't delete layer, serial: "+serial+" not found");
arrLayers = arrLayersNew;
}
/**
* delete the layer from html.
*/
var deleteLayerFromHtml = function(serial){
var htmlLayer = getHtmlLayerFromSerial(serial);
htmlLayer.remove();
}
/**
* delete all representation of some layer
*/
var deleteLayer = function(serial){
deleteLayerFromObject(serial);
deleteLayerFromHtml(serial);
deleteLayerFromSortbox(serial);
}
/**
*
* call "deleteLayer" function with selected serial
*/
var deleteCurrentLayer = function(){
if(selectedLayerSerial == -1)
return(false);
deleteLayer(selectedLayerSerial);
//set unselected
selectedLayerSerial = -1;
//clear form and disable buttons
disableFormFields();
}
/**
* duplicate layer, set it a little aside of the layer position
*/
var duplicateLayer = function(serial){
var obj = arrLayers[serial];
var obj2 = jQuery.extend(true, {}, obj); //duplicate object
obj2.left += 5;
obj2.top += 5;
obj2.order = undefined;
obj2.time = undefined;
addLayer(obj2);
redrawSortbox();
}
/**
* call "duplicateLayer" function with selected serial
*/
var duplicateCurrentLayer = function(){
if(selectedLayerSerial == -1)
return(false);
duplicateLayer(selectedLayerSerial);
}
/**
* delete all layers
*/
var deleteAllLayers = function(){
arrLayers = {};
container.html("");
emptySortbox();
selectedLayerSerial = -1;
disableFormFields();
jQuery("#button_delete_all").addClass("button-disabled");
}
/**
* update the corners
*/
var updateHtmlLayerCorners = function(htmlLayer,objLayer){
var ncch = htmlLayer.outerHeight();
var bgcol = htmlLayer.css('backgroundColor');
switch(objLayer.corner_left){
case "curved":
htmlLayer.append("