var proPhoto = false; selected_element_border_color = '#d4aee1' var pageType = 'create'; var create_template_filename = 'lag.php'; selected_element_border_size = 3; var templateType = 'photogift'; if (typeof(templateConfig) != 'undefined') { templateType = templateConfig.type; } // Disable IE CACHE!! //jQuery.ajaxSetup({cache: false}); needsupdate = false; if (navigator.userAgent.match(/Safari/)) { safari = true; } else { safari = false; } config_selectedyear = 0; var currentImage = 0; //var numimage = 0; var selectedCount = 0; function flashSelectedImage () { if (selectedCount > 3) { return; } selectDiv = jQuery('#selectedImageFrame'); if (selectedCount % 2 == 0) { selectDiv.css("borderColor", "red"); } else { selectDiv.css('border', selected_element_border_size + 'px solid ' + selected_element_border_color); } selectedCount++; setTimeout(flashSelectedImage, 200); } function doTheFlash () { flashSelectedImage (); } function getRandomString(num) { if (!num) { num = 16; } var chars = "abcdefghjklmnopqrstuvwxyz0123456789"; var output = ""; for (var i = 0; i scrollTop && sy < scrollTop + vpHeight) || (sy + $(this).height() > scrollTop && sy < scrollTop + vpHeight)) { if ($(this).attr('preview') == "true") { $(this).attr('loading', 'true'); template = new Array( $(this).attr('preview'), $(this).attr('uuid'), parent.attr('id')); loadTemplates.push(template); } else { $(this).attr('src', $(this).attr('real_src')); } } }); if (loadTemplates.length > 0) { $.ajax({ url: '/sections/cardscalendars/ajax/load_templates.php?type=' + templateType, dataType: 'json', data: {templates: $.toJSON(loadTemplates)}, type: 'post', success: function(data) { if (data.error) { sessionTimedOut(); } else { for (var id in data) { $('#' + id).html(data[id]); } } } }); } } function init() { // Hack to it only works with card/calendars if ($('#templateArea').length > 0) { changeSelection (); } } function selectFolder() { value = $('#folderList').val(); if (value == '') { return; } $('#loadingAlbum').css('display', 'block'); $('#albumContent').css('display', 'none'); $.get("ajax/copyImages.php?folder=" + value, function (data) { document.location.href='create.php'; }); } function changeSelection() { var num_images = $('#userimages').find('div.template_page_active').attr('value'); var format = $('#format').find('div.template_page_active').attr('value'); var user_texts = $('#usertexts').find('div.template_page_active').attr('value'); var pages = $('#num_pages').find('div.template_page_active').attr('value'); var category = ''; if (typeof(card_category) == 'undefined') { } else { category = card_category; } $('#templateArea').html('Laster mal-liste...'); $.post("/sections/cardscalendars/ajax/get_template_list.php?type=" + templateType, {parts: pages, category: category, images: num_images, format: format, usertexts: user_texts}, function (data) { //$.post("/sections/cardscalendars/ajax/get_template_list.php?type=" + templateType, jQuery('#chooseForm').serialize(), function (data) { $('#templateArea').html(data); doLoadVisibleTemplates(); }); } function calendarSetNumberOfPages(obj) { $('#num_pages').find('div').removeClass('template_page_active'); $(obj).addClass('template_page_active'); changeSelection (); } function cardSetNumberOfImages(obj) { $('#userimages').find('div').removeClass('template_page_active'); $(obj).addClass('template_page_active'); changeSelection (); } function cardSetFormat(obj) { $('#format').find('div').removeClass('template_page_active'); $(obj).addClass('template_page_active'); changeSelection (); } function cardSetUserTexts(obj) { $('#usertexts').find('div').removeClass('template_page_active'); $(obj).addClass('template_page_active'); changeSelection (); } function photogiftUpdatePrices(custom) { // Set prices to default values: var i = 0; while (document.getElementById('quantity_photogift_' + i)) { document.getElementById('product_price_' + i).innerHTML = ".."; var obj = $('#quantity_photogift_' + i); var qty = parseInt( obj.val() ); var minqty = parseInt( obj.attr('minqty') ); if ( qty > 0 && qty < minqty ) { obj.val( minqty ); } i++; } qpg = document.getElementById('product_price'); if (qpg) { qpg.innerHTML = '..'; } tQ = document.getElementById('totalQuantity'); if (tQ) { tQ.innerHTML = '..'; } tP = document.getElementById('totalPrice'); if (tP) { tP.innerHTML = '..'; } if (custom == "custom") { addr = "/sections/cardscalendars/ajax/getprices_custom.php?template=" + current_template_uuid; } else { addr = "/sections/cardscalendars/ajax/getprices.php?template=" + current_template_uuid; } if ($('#quantity_photogift').length > 0) { if ( parseInt($('#quantity_photogift').val()) < parseInt( $('#quantity_photogift').attr('minqty') ) ) { $('#quantity_photogift').val( $('#quantity_photogift').attr('minqty') ); } } $.get(addr, jQuery('#copiesForm').serialize(), function (data) { sdata = data.split(";"); var i = 0; while (document.getElementById('quantity_photogift_' + i)) { document.getElementById('product_price_' + i).innerHTML = sdata[i]; i++; } if (qpg) { qpg.innerHTML = sdata[0]; } if (tQ) { tQ.innerHTML = sdata[i]; } i++; if (tP) { tP.innerHTML = sdata[i]; } }); } function editShoppingCartEntry () { document.location.href = "/sections/cardscalendars/ajax/update_shoppingcart_entry.php?template=" + current_template_uuid; } function addToShoppingCart (skip_warning) { var skip = ""; if (skip_warning) { skip="&skip_warning=1"; } OpenPopup("/sections/cardscalendars/ajax/add_to_shoppingcart.php?template=" + current_template_uuid + skip); } function photogiftNumberOfCopies() { totalQty = 0 i = 0 while (document.getElementById('quantity_photogift_' + i)) { totalQty += document.getElementById('quantity_photogift_' + i).value; i++; } elm = document.getElementById('quantity_photogift'); if (elm) { totalQty += elm.value; } if (totalQty == 0) { alert("Du må velge antall før du kan fortsette!"); return; } $.getJSON("/sections/cardscalendars/ajax/do_add_to_shoppingcart.php?template=" + current_template_uuid, jQuery('#copiesForm').serialize(), function (data) { /* This function is missing on consumer if (!handleGenericJsonResponse(data)) { return; } */ if (data.result == "DONE") { document.location.href = '/sections/printsorder/shoppingcart.php?product=' + current_product_name; } }); } function addPackageToShoppingCart(packagename) { if (!packageAddToCartWarning) { doAddPackageToShoppingCart(packagename); return } jQuery.get('/sections/cardscalendars/ajax/add_package_to_shoppingcart.php?check=1&packagename=' + packagename, function (data) { if (data == ".") { doAddPackageToShoppingCart(packagename); } else { OpenPopup('/sections/cardscalendars/ajax/add_package_to_shoppingcart.php?packagename=' + packagename); } }); } function startPromoteProductCycle() { $.getScript('/sections/prophoto/ajax/promote.php?script=1'); } function doAddPackageToShoppingCart(packagename) { jQuery.getJSON('/sections/cardscalendars/ajax/do_add_package_to_shoppingcart.php', {uuid: current_package_uuid}, function (data) { if (!handleGenericJsonResponse(data)) { return; } if (data.result == "DONE") { document.location.href = '/sections/printsorder/shoppingcart.php?product=' + current_product_name; } else if (data.result == 'MISSING_IMAGES') { alert('Atleast one of the products in the package is missing a picture. Please assign a picture before adding the package to the shopping cart.'); var obj = $('#package_container .package').eq( (data.productnum-1) ); loadPackageTemplate(obj, data.packagenum); } else { alert('Error adding to shopping cart'); } }); } function addFolderCardsToCart() { totalQty = 0 i = 0 while (document.getElementById('quantity_photogift_' + i)) { totalQty += document.getElementById('quantity_photogift_' + i).value; i++; } elm = document.getElementById('quantity_photogift'); if (elm) { totalQty += elm.value; } if (totalQty == 0) { alert("Du må velge antall før du kan fortsette!"); return; } $.get("ajax/do_add_foldercards_to_cart.php", jQuery('#copiesForm').serialize(), function (data) { document.location = '/sections/printsorder/shoppingcart.php'; }); } function chooseNumberOfCopies(templatetype) { copies = document.getElementById('numberofcopies').value; if (copies == 0) copies = 1; $.get("ajax_wizard.php?page=numberofcopies&copies=" + copies + "&type=" + templatetype, function (data) { document.location = '/sections/printsorder/shoppingcart.php'; }); } function waitWhileGenerating(templatetype) { $.get("ajax_wizard.php?page=checkGenerating&type=" + templatetype, function (data) { checkIfDone(data, templatetype); }); } function checkIfDone(data, type) { if (data == "done") { document.location = '/sections/printsorder/shoppingcart.php'; } else { $('#wizard').html(data); setTimeout('waitWhileGenerating("'+type+'")', 5000); } } function logIn() { $.get("ajax_wizard.php?page=login", jQuery('#calendarLoginForm').serialize(), wizardPageComplete); } function calendarLogin() { $.get("/sections/cardscalendars/ajax/login.php", jQuery('#loginForm').serialize(), function (data) { if (data != "OK") { $('#loginError').html(data); $('#loginError').css("display", "inline"); } else { OpenPopup("/sections/cardscalendars/ajax/choosealbum.php"); } }); } function OpenLocalAlbum() { OpenPopup("/sections/cardscalendars/ajax/localalbum.php", null, true); } function photogiftLogin() { $.get('/sections/cardscalendars/ajax/login.php', jQuery('#loginForm').serialize(), function (data) { if (data != "OK") { $('#loginError').html(data + '
'); $('#loginError').css('display', 'inline'); } else { OpenLocalAlbum(); } }); } function chooseFolder() { $.get("ajax_wizard.php?page=choosefolder", jQuery('#showFolderList').serialize(), function(data) { top.location.href="/sections/cardscalendars/calendarsv2/create.php"; }); } function getWindowSizeXY() { var winW = 630, winH = 460; if (navigator.appName=="Netscape") { winW = window.innerWidth; winH = window.innerHeight; } else { winW = document.body.offsetWidth; winH = document.body.offsetHeight; } return [winW, winH]; } function getScrollXY() { var scrOfX = 0, scrOfY = 0; if( typeof( window.pageYOffset ) == 'number' ) { //Netscape compliant scrOfY = window.pageYOffset; scrOfX = window.pageXOffset; } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { //DOM compliant scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft; } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { //IE6 standards compliant mode scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft; } return [ scrOfX, scrOfY ]; } function hideTemplatePreview() { templatepreview = document.getElementById('templatePreview'); if (templatepreview) { templatepreview.style.display = 'none'; } } function showTemplatePreview(id, event, type) { if (showTemplatepreview == false) return; if (!event) event = window.event; var scroll = getScrollXY(); currentx = event.clientX+scroll[0] + 15; currenty = event.clientY+scroll[1] + 15; templatepreview = document.getElementById('templatePreview'); newimage = document.getElementById('image' + id); if (type == 1) { newheight = 300; newwidth = 180; divheight = 370; divwidth = 220; } else { newheight = 220; newwidth = 250; divheight = 310; divwidth = 270; } if (!templatepreview) { var previewdiv = document.createElement('div'); previewdiv.setAttribute("id", "templatePreview"); previewdiv.onclick = function() { makeTemplate(newimage.src); } previewdiv.style.border = '1px solid black'; previewdiv.style.width = divwidth + 'px'; previewdiv.style.height = divheight + 'px'; previewdiv.style.backgroundColor = 'white'; previewdiv.style.paddingTop = '30px'; previewdiv.innerHTML = '
'; document.body.appendChild(previewdiv); size = fitIn(newimage.width, newimage.height, newwidth, newheight); image = document.getElementById('previewImage'); image.style.height = size[1] + 'px'; image.style.width = size[0] + 'px'; } else { image = document.getElementById('previewImage'); if (image) { image.src = newimage.src; size = fitIn(newimage.width, newimage.height, newwidth, newheight); image.style.height = size[1] + 'px'; image.style.width = size[0] + 'px'; } } previewlargetext = document.getElementById('previewLargeText'); textinfo = false; if (document.getElementById('previewtext_' + id)) { if (previewlargetext) previewlargetext.innerHTML = '' + document.getElementById('previewtext_' + id).innerHTML + ''; else { var text = '' + document.getElementById('previewtext_' + id).innerHTML + ''; textinfo = document.createElement('div'); textinfo.setAttribute('id', 'previewLargeText'); textinfo.innerHTML = text; textinfo.style.position = 'absolute'; if (image) { valigntop = (stripPt(image.style.height) + 10 + 40); textinfo.style.top = valigntop + 'px'; } textinfo.style.left = '19px'; textinfo.style.fontSize = '16px'; textinfo.style.fontFamily = 'verdana'; } } // document.getElementById('debug').innerHTML += image.src; templatepreview = document.getElementById('templatePreview'); // templatepreview.appendChild(image); if (textinfo) templatepreview.appendChild(textinfo); templatepreview.style.position = 'absolute'; var windowsize = getWindowSizeXY(); // alert(windowsize[0]); if ((currentx + divwidth) > windowsize[0]) var left = (currentx-divwidth-40); else var left = currentx; if ((currenty + divheight) > windowsize[1]) var top = (currenty-divheight-50); else var top = currenty; // alert(top); //top = currenty + 10; // left = currentx + 10; if (top < 0) top = 0; templatepreview.style.top = top + 'px'; templatepreview.style.left = left + 'px'; templatepreview.style.display = ''; return false; } function makeTemplate(template, type, muuid) { var param = "" if (type == 1) { OpenPopup("/sections/cardscalendars/ajax/chooseyear.php?template=" + escape(template) + "&medium=" + muuid); } else if (type == 2) { document.location.href = create_template_filename + "?template=" + template + "&medium=" + muuid; /* $.get("ajax_wizard.php", {page: 'choosecardtemplate', template: template, medium: muuid}, function (data) { changeTemplateCheckReload(data); }); */ } } function changeTemplateCheckReload(data) { if (data == "reload") document.location = 'create.php?loadscript=1'; else document.location='create.php'; } function closeWizard() { showTemplatepreview = true; /* Enable main form */ /* sizes = document.getElementsByName('sizes[]'); for (var i = 0; i < sizes.length; i++) { sizes[i].disabled = false; } parts = document.getElementsByName('parts[]'); for (var i = 0; i < parts.length; i++) { parts[i].disabled = false; } */ $('#wizard').hide(); $('#wizard.').html('Laster...'); } function documentClick() { templatepreview = document.getElementById('templatePreview'); if (templatepreview) templatepreview.style.display = 'none'; closeStringToolbarItems(); } function yearMouseOver(year) { $('#' + year).className('yearActive'); } function yearMouseOut(id, year) { if (config_selectedyear == year) return; year = document.getElementById(id); year.className = 'yearInActive'; } function setYear(year) { if (year == config_selectedyear) return; oldyear = document.getElementById('year' + config_selectedyear); if (oldyear) oldyear.className = 'yearInActive'; config_selectedyear = year; // Enable next step button: document.getElementById('nextStep').style.display = 'block'; } function calendarChangeTemplate() { createWizard(); $.get("ajax_wizard.php?page=calendarchangetemplate", jQuery('#chooseYearForm').serialize(), wizardPageComplete); } function calendarSetYear(template) { year = ""; yearform = document.getElementById("chooseYearForm"); current_template_uuid = template; // If only one radio element: if (typeof(yearform.year.length) == "undefined") { year = yearform.year.value; } else { for (var i=0; i < yearform.year.length; i++) { if (yearform.year[i].checked) { year = yearform.year[i].value; } } } document.location.href= create_template_filename + "?year=" + year + "&uuid=" + template; } function chooseImageSource(template) { year = ""; current_template_uuid = template; yearform = document.getElementById("chooseYearForm"); // If only one radio element: if (typeof(yearform.year.length) == "undefined") { year = yearform.year.value; } else { for (var i=0; i < yearform.year.length; i++) { if (yearform.year[i].checked) { year = yearform.year[i].value; } } } document.location.href = '../create.php'; return; OpenPopup("/sections/cardscalendars/ajax/imagesource.php?year=" + year + "&uuid=" + template); } flashnum = 0; function flashEmptyMonths() { if (flashnum > 11) { flashnum = 0; return; } if (flashnum % 2 == 0) { for (i = 1; i<13; i++) { image = document.getElementById('month_' + i); if (image) { var re = image.style.backgroundImage.match(/green|_active/); if (!re) { image.style.backgroundImage = 'url("/design/DEFAULT/graphics/calendar/monthbutton_red.png")'; } } } } else { for (i = 1; i<13; i++) { image = document.getElementById('month_' + i); if (image) { var re = image.style.backgroundImage.match(/green|_active/); if (!re) { image.style.backgroundImage = 'url("/design/DEFAULT/graphics/calendar/monthbutton_inactive.png")'; } } } } flashnum += 1; setTimeout("flashEmptyMonths()", 200); } function createWizard() { // Check if it exists already: if ($('#wizard').length > 0) { $('#wizard').css('display', 'block'); } else { var wiz = $('
Laster...
'); $('#xcontent').append(wiz); } } function finishCalendar() { createWizard(); $.get("ajax_wizard.php?page=checkifdone", {}, wizardPageComplete); } function finishCard() { createWizard(); $.get("ajax_wizard.php?page=checkifdone&type=card", {}, wizardPageComplete); } function loadAlbum() { folderId = $('#folderId').val(); $.get("/sections/cardscalendars/ajax/addfolder.php", {folder: folderId}, function (data) { document.location.href = 'create.php?uuid=' + current_template_uuid; }); } function chooseAlbum(template_uuid) { current_template_uuid = template_uuid; OpenPopup("/sections/cardscalendars/ajax/choosealbum.php"); } function loadTemplate() { if (window.location.href.match(/(calendarsv2)/)) { $.get("ajax_template.php", {}, function (data) { updateTemplateJs();checkIfImageIsTooSmall(); }); } } function nextMonthPage() { loading = document.getElementById('divLoading'); if (loading) { alert("Vennligst vent til bildet er lastet før du navigerer bort."); return; } if ((calendarCurrentMonth+1) < calendarTotalMonths) { if (window.location.href.match(/(calendarsv2)/)) { swaptab_0(calendarCurrentMonth+1); tabselect_0("javascript:gotoMonthPage("+(calendarCurrentMonth+1)+");"); } else { gotoMonthPage((calendarCurrentMonth+1)); } } } function previousMonthPage() { loading = document.getElementById('divLoading'); if (loading) { alert("Vennligst vent til bildet er lastet før du navigerer bort."); return; } if ((calendarCurrentMonth) >= 0) { if (window.location.href.match(/(calendarsv2)/)) { swaptab_0(calendarCurrentMonth-1); tabselect_0("javascript:gotoMonthPage("+(calendarCurrentMonth-1)+");"); } else { gotoMonthPage((calendarCurrentMonth-1)); } } } function gotoMonthPage(page) { var loading = document.getElementById('divLoading'); if (loading && page !== null) { alert("Vennligst vent til bildet er lastet før du navigerer bort."); return; } jQuery.getJSON('/sections/cardscalendars/ajax/get_template.php', {gotopage: page, template: current_template_uuid}, function (data) { if (data.redirect) { document.location.href = data.redirect; return; } jQuery('#templatecontent').html(data.template); eval(data.script); updateTemplateJs(); // Select the current page: $('div.template_page').removeClass('template_page_active'); $('div.template_page').eq(calendarCurrentMonth).addClass('template_page_active'); if (!NTLF_CONFIG.portal.is_prophoto) { // Quality check the current pictures: $('.userimage_overlay').each ( function () { var id = $(this).attr('id'); var re = id.match(/^.*_(\d+)$/); var imagenum = parseInt(re[1]); checkImageQuality(imagenum); }); } }); } function updateTemplateJs() { jQuery.get("/sections/cardscalendars/ajax/template_script.php?template=" + current_template_uuid, function (data) { if (data != "") { eval(data); checkIfImageIsTooSmall(); } }); // JS fix for IE8: $('div.userimagecontainer').css('background-size', 'cover'); } function closeToolbar() { var toolbar = document.getElementById('toolbarDiv'); if (toolbar) { toolbar.parentNode.removeChild(toolbar); } } function changeAllPackageImages (photouuid) { $.getJSON('/sections/cardscalendars/ajax/do_change_all_package_template_pictures.php?package=' + current_package_uuid + '&picture=' + photouuid, function (data) { if (!handleGenericJsonResponse(data)) { return; } // If package... updatePackagePreviews(); gotoMonthPage(0); }); } function changeAllImages (photouuid) { $.getJSON('/sections/cardscalendars/ajax/do_change_all_template_pictures.php?template=' + current_template_uuid + '&picture=' + photouuid, function (data) { if (!handleGenericJsonResponse(data)) { return; } // Loading should not show here, as it cause problems: $('#divLoading').remove (); gotoMonthPage(0); updatePackagePreview(); }); /* var i = 0; $('.userimagecontainer').each ( function () { changeImage(i, photouuid, true); i++; }); */ } function permutate(array, callback) { // Do the actual permuation work on array[], starting at index function p(array, index, callback) { // Swap elements i1 and i2 in array a[] function swap(a, i1, i2) { var t = a[i1]; a[i1] = a[i2]; a[i2] = t; } if (index == array.length - 1) { callback(array); return 1; } else { var count = p(array, index + 1, callback); for (var i = index + 1; i < array.length; i++) { swap(array, i, index); count += p(array, index + 1, callback); swap(array, i, index); } return count; } } if (!array || array.length == 0) { return 0; } return p(array, 0, callback); } function changeImage (imageNum, photouuid, do_change, gp, keywords) { // This function is used for package previews also: if (pageType == "preview") { $.get("/sections/cardscalendars/ajax/add_preview_image.php", {uuid: photouuid}, function () { changeSelection(); }); return; } // Container element: var elm = jQuery('#userimage_' + imageNum); // We can't change the image if the template don't have this image: if (elm.length == 0) { return; } if (typeof(keywords) == "string") { keywords = keywords.split(/,/); } if ( typeof(gp) == "string" && gp === "false") { gp = false; } // Start loading image: loadingImage(); // Check if we got a image spot: if (jQuery('#img_' + imageNum).length == 0) { jQuery('#userimage_' + imageNum).html(''); } if (typeof(locked_image_tags) == 'undefined') { var locked_image_tags = []; } // Customer option only allow some tags on templates with that tag: var tag = elm.attr('tag'); for (idx in locked_image_tags) { var locked_tags = locked_image_tags[idx]; if (locked_tags.indexOf(':') >= 0) { // Template must have all: var tags = locked_tags.split(":"); var found = true; for (var i in tags) { if ($.inArray(tags[i], keywords) < 0) { found = false; break; } } // Locked to, but valid: if (found) { var combos = []; // Permutate [1, 2, 3], pushing every permutation onto result[] permutate(tags, function (a) { // Create a copy of a[] and add that to result[] combos.push(a.slice(0)); }); found = false; for (i in combos) { if (combos[i].join(":") == tag) { found = true; break; } } if (!found) { var msg = 'Dette+bildet+kan+kun+brukes+med+den+tildelte+malen.'; OpenPopup('/sections/misc/popup/alert.php?message=' + msg); checkLoading(); return false; } } } else { var tags = locked_tags.split("/"); var found = false; for (var i in tags) { if ($.inArray(tags[i], keywords) >= 0) { found = true; break; } } if (found) { var templateTag = tag.split("/"); found = false; for (i in tags) { for (j in templateTag) { if (templateTag[j] == tags[i]) { found = true; break; } } if (found) { break; } } if (!found) { var msg = 'Dette+bildet+kan+kun+brukes+med+den+tildelte+malen.'; OpenPopup('/sections/misc/popup/alert.php?message=' + msg); checkLoading(); return false; } } } } if (typeof(disable_portrait_in_group_pictures) != 'undefined' && disable_portrait_in_group_pictures) { // Is this a group picture module? if ($.inArray('GROUPPICTURES', templateCategories) >= 0) { // It's a group picture template, now.. Is the picture a group picture? if (!gp) { var msg = 'Portrettbilder+kan+ikke+brukes+p%C3%A5+gruppebildemaler'; OpenPopup('/sections/misc/popup/alert.php?message=' + msg); checkLoading(); return; } } } if (typeof(disable_group_picture_in_portrait_pictures) != 'undefined' && disable_group_picture_in_portrait_pictures) { // Is this a group picture module? if ($.inArray('PORTRAITPACKAGES', templateCategories) >= 0) { // It's a portrait picture template, now.. Is the picture a portrait picture? if (gp) { var msg = 'Gruppebilder+kan+ikke+brukes+p%C3%A5+portrettbildemaler'; OpenPopup('/sections/misc/popup/alert.php?message=' + msg); checkLoading(); return; } } } if (elm.attr('locked_to_tag') ) { var tag = elm.attr('locked_to_tag'); if (!checkIfPictureAllowed(tag, keywords)) { var msg = 'Denne+malen+kan+kun+brukes+med+det+tildelte+bildet.'; OpenPopup('/sections/misc/popup/alert.php?message=' + msg); checkLoading(); return false; } } jQuery("#layer_" + imageNum).html(''); jQuery.getJSON ('/sections/cardscalendars/ajax/change_image.php', {imageNum: imageNum, uuid: photouuid, template: current_template_uuid}, function (obj) { if (obj.error) { document.location.reload (); return; } jQuery('#img_' + imageNum).css('position', 'absolute'); jQuery('#img_' + imageNum).css('left', obj.left + "px"); jQuery('#img_' + imageNum).css('top', obj.top + "px"); jQuery('#img_' + imageNum).css('width', obj.width + "px"); jQuery('#img_' + imageNum).css('height', obj.height + "px"); loadTemplateImage(obj.path, imageNum, false); selectImage(imageNum); if (obj.background) { var rotation = obj['background_rotation'] + '/'; var effect = obj['effect'] + '/'; $('#userimage_' + imageNum).css( { backgroundImage: 'url(/design/DEFAULT/graphics/templateimagebackgrounds/' + rotation + effect + obj['background'] + ')' }); } updatePackagePreview(); if (obj.reloadtexts) { reloadTextStrings(); } if (obj.pages_filled) { setTemplatePagesFilled(obj.pages_filled); } // Sorry, just one error at the time :/ if (obj.change_all_package_pictures) { //changeAllPackageImages(photouuid); OpenPopup("/sections/cardscalendars/ajax/change_all_package_template_pictures.php?template=" + current_template_uuid + "&picture=" + photouuid + "&imagenum=" + imageNum); } else if (obj.change_all_warning) { OpenPopup("/sections/cardscalendars/ajax/change_all_template_pictures.php?template=" + current_template_uuid + "&picture=" + photouuid + "&imagenum=" + imageNum); } else if (obj.megapixel_warning) { OpenPopup("/sections/misc/popup/warning.php?message=Oppl%C3%B8sningen+p%C3%A5+bildefilen+din+er+d%C3%A5rlig+%28under+1+megapixel%29.+Dette+vil+medf%C3%B8re+at+utskriftskvaliteten+kan+bli+tilsvarende+d%C3%A5rlig."); } }); } function setTemplatePagesFilled(pages) { var i = 0; $('div.template_page').each ( function () { if (pages[i]) { $(this).addClass('template_page_complete'); } i++; }); } function adjustImage (keepToolBar, numimage, noreload) { // This is not required anymore return; } function checkIfPictureAllowed (tag, keywords) { var compareMode = 0; var tags = tag.split("/"); if (tags.length == 1) { tags = tag.split(":"); compareMode = 1; } var found = false; if (compareMode == 0) { // Verify that the tags is allowed: found = false; for (var i in tags) { if ($.inArray(tags[i], keywords) >= 0) { found = true; break; } } if (!found) { return false; } } else { // Require all: found = true; for (var i in tags) { if ($.inArray(tags[i], keywords) < 0) { found = false; break; } } if (!found) { return false; } } 0 return true; } function nextPage() { loading = document.getElementById('divLoading'); if (loading) { alert("Vennligst vent til bildet er lastet før du navigerer bort."); return; } var i = 0; while (userimage = document.getElementById('userimage_' + i)) { // FIXME Droppables.remove('userimage_' + i); i++; } $.get("ajax_template.php?nextpage=1", {}, function (data) { $('#templateEditArea').html(data); updateTemplateJs(); }); } function prevPage() { loading = document.getElementById('divLoading'); if (loading) { alert("Vennligst vent til bildet er lastet før du navigerer bort."); return; } var i = 0; while (userimage = document.getElementById('userimage_' + i)) { // FIXME Droppables.remove('userimage_' + i); i++; } $.get("ajax_template.php?prevpage=1", {}, function (data) { $('#templateEditArea').html(data); updateTemplateJs(); }); } function errorNoImage() { createWizard(); $.get("ajax_wizard.php?page=errornoimage", {}, wizardPageComplete); } function uploadImage(imagenum) { createWizard(); $.get("ajax_wizard.php", {page: "uploadimage", imagenum: imagenum}, wizardPageComplete); } function onOpenFacebook (callback, win) { if (!win) { win = window; } win.facebook = ntlf_facebook(facebookAppId); facebook.setCompleteCallback( callback ); facebook.init(); ClosePopup(); } function onOpenInstagram (callback, win) { if (!win) { win = window; } win.instagram = ntlf_instagram("50e922fa40094ab1b29a360bbb742ce5"); instagram.setCompleteCallback( callback ); instagram.init(); ClosePopup(); } function openInstagramAuth() { var redirect = "http://www.digitalbilder.no/sections/cardscalendars/instagram_auth.php"; var url = 'https://api.instagram.com/oauth/authorize/?client_id=50e922fa40094ab1b29a360bbb742ce5&redirect_uri='+redirect+'&response_type=code'; newwindow=window.open(url,'name','height=500,width=650'); if (window.focus) {newwindow.focus()} return false; } function openFacebookAuth(url) { newwindow=window.open(url,'FacebookAuth','height=550,width=1000'); if (window.focus) {newwindow.focus()} return false; } function openGooglePlusAuth(url) { newwindow=window.open(url,'GooglePlusAuth','height=550,width=1000'); if (newwindow && newwindow.focus) { newwindow.focus() } else { var timer = window.setTimeout( function(){ if(newwindow && newwindow.focus)newwindow.focus(); }, 100 ); } return false; } function selectImage (imagenum, evt) { if (typeof(imagenum) == 'undefined') { imagenum = currentImage; } if (typeof(evt) != 'undefined') { evt.cancelBubble = true; if (evt.stopPropagation) { evt.stopPropagation(); } } var imageElement = jQuery('#userimage_' + imagenum); if (imageElement.length == 0) { return; } var pos = imageElement.offset(); if (jQuery('#selectedImageFrame').length == 0) { var selectDiv = jQuery('
'); selectDiv.css('border', selected_element_border_size + 'px solid ' + selected_element_border_color); selectDiv.css('zIndex', 2); jQuery(document.body).append(selectDiv); $(window).resize ( function () { var imageElement = jQuery('#userimage_' + currentImage); // Set position var pos = imageElement.offset(); selectDiv.css("left", pos.left-selected_element_border_size + "px"); selectDiv.css("top", pos.top-selected_element_border_size + "px"); selectDiv.css("width", imageElement.css('width')); selectDiv.css("height", imageElement.css('height')); selectDiv.css("cursor", "pointer"); }); } var selectDiv = jQuery('#selectedImageFrame'); selectedCount = 0; flashSelectedImage(); // Check number of images: imgcount = 0; while (jQuery('#userimage_' + imgcount).length > 0) { imgcount++; } if (imgcount == 1) { selectDiv.css("border", ""); } // Set position selectDiv.css("left", pos.left-selected_element_border_size + "px"); selectDiv.css("top", pos.top-selected_element_border_size + "px"); selectDiv.css("width", imageElement.css('width')); selectDiv.css("height", imageElement.css('height')); selectDiv.css("cursor", "pointer"); selectDiv.unbind('click'); selectDiv.click( function() { if ($(this).hasClass('noclick')) { $(this).removeClass('noclick'); return; } // Fix only for prophoto selectImage(imagenum); if (!proPhoto) { // We no longer want click on image to choose picture if ( $('#userimage_' + imagenum).find('img').length == 0) { cardChooseImage(imagenum); } } } ); currentImage = imagenum; jQuery.getJSON('/sections/cardscalendars/ajax/set_data.php', {currentImage: imagenum, template: current_template_uuid}, function (data) { // Check if we should enable edit: if (document.getElementById('img_' + currentImage)) { jQuery("#editboxOverlay").css("display", "none"); } else { if (jQuery('#editboxOverlay').length > 0) { jQuery('#editboxOverlay').css("display", "inline"); } } if (data.error) { // Reload page: document.location.reload (); return; } if (data.effect == 'sepia') { jQuery('#editbuttonSepia').attr('checked',1); } else if (data.effect == 'bw') { jQuery('#editbuttonBw').attr('checked',1); } else { jQuery('#editbuttonOriginal').attr('checked',1); } // Check if we should enable edit: if (document.getElementById('img_' + currentImage)) { jQuery("#editboxOverlay").css("display", "none"); } else { if (jQuery('#editboxOverlay').length > 0) { jQuery('#editboxOverlay').css("display", "inline"); } } }); // $('#selectedImageFrame').css('background-color', 'red'); $('#selectedImageFrame').draggable({ start: function (event, ui) { $(this).addClass('noclick'); start_left = ui.position.left; start_top = ui.position.top; image = $('#img_' + currentImage); if (image.length == 0) { return false; } image_start_left = parseInt(image.css('left').replace(/px/, "")); image_start_top = parseInt(image.css('top').replace(/px/, "")); image_width = parseInt(image.css('width').replace(/px/, "")); image_height = parseInt(image.css('height').replace(/px/, "")); container = $('#userimage_' + currentImage); container_width = parseInt(container.css('width').replace(/px/, "")); container_height = parseInt(container.css('height').replace(/px/, "")); // Stop flashing: stopBorderFlashing (); $('#selectedImageFrame').css({ borderTop: 'none', borderLeft: 'none', borderRight: 'none', borderBottom: 'none' }); $('#selectedImageFrame').html(''); }, drag: function(event, ui) { curr_left = ui.position.left; curr_top = ui.position.top; image = $('#img_' + currentImage); adaption = image.parent().attr('adaption'); if (adaption == 'fill-in') { l = image_start_left - (start_left - curr_left); t = image_start_top - (start_top - curr_top); if (l > 0) { l = 0; } if (t > 0) { t = 0; } if (l+image_width < container_width) { l = container_width - image_width; } if (t+image_height < container_height) { t = container_height-image_height; } image.css('left', l); image.css('top', t); } else { // Fit in l = image_start_left - (start_left - curr_left); t = image_start_top - (start_top - curr_top); // We can only have one side < size: if (t > 0 && image_height > container_height) { t = 0; } if (l > 0 && image_width > container_width) { l = 0; } if (t > 0 || image_height < container_height) { t = (container_height/2) - (image_height/2); if (l > 0) { l = 0; } if (l+image_width < container_width && image_width > container_width) { l = container_width - image_width; } } else if (l > 0 || image_width < container_width) { // Half way: l = (container_width/2) - (image_width/2); if (t > 0) { t = 0; } if (t+image_height < container_height && image_height > container_height ) { t = container_height-image_height; } } // Zoomed in if (l < 0 && l + image_width < container_width) { l = container_width - image_width; } if (t < 0 && t + image_height < container_height) { t = container_height - image_height; } image.css('left', l); image.css('top', t); } }, stop: function (event, ui) { $('#selectedImageFrame').css('left', start_left); $('#selectedImageFrame').css('top', start_top); $('#selectedImageFrame').css('border', selected_element_border_size + 'px solid ' + selected_element_border_color) image = $('#img_' + currentImage); offsetx = image.css('left').replace(/px/, ""); offsety = image.css('top').replace(/px/, ""); newwidth = image.css('width').replace(/px/, ""); newheight = image.css('height').replace(/px/, ""); saveConfig("zoomData", "offsetx=" + offsetx + "&offsety=" + offsety + "&width=" + newwidth + "&height=" + newheight + "&imagenum=" + currentImage); $('#selectedImageFrame').html(''); return true; } }); /* Disable mouse scroll as it seem to cause more problems than it solve: $('#selectedImageFrame').unmousewheel(); $('#selectedImageFrame').mousewheel( function (event, delta) { if (delta == 1) { zoomIn(); } else { zoomOut(); } return false; }); */ checkImageQuality(currentImage); } function showToolBar(imagenum) { if (typeof(imagenum) != 'undefined') { currentImage = imagenum; } if (!document.getElementById('img_' + currentImage)) { errorNoImage(); return; } selectImage(imagenum); // Remove old toolbar (In case image switch etc) closeToolbar() toolbar = document.getElementById('toolbarDiv'); if (toolbar) { return false; } var toolbar = document.createElement('div'); toolbar.style.width = 115; toolbar.style.height = 232; toolbar.setAttribute('id', 'toolbarDiv'); toolbar.style.position = "absolute"; toolbar.style.right = "0px"; toolbar.style.bottom = "0px"; toolbar.style.borderLeft = '5px solid white'; toolbar.style.borderTop = '5px solid white'; // Add toolbar to body: document.getElementById('templateEditArea').appendChild(toolbar); // document.body.appendChild(toolbar); // Load content: $.get("ajax_toolbar.php", {imagenum: currentImage}, function (data) { $('#toolbarDiv').html(data); }); } var currentZoom = 0; function zoomIn(evt) { stopBubble(evt); var zoomlevel = 1.1; image = document.getElementById('img_' + currentImage); if (!image) { return; } // Check if zoom is disabled: var container = $(image).closest('div.userimagecontainer'); if ( container.attr('disable_zoom')) { return; } var current_zoom = 0; if ( $(image).attr('zoom') ) { current_zoom = parseInt($(image).attr('zoom')); } current_zoom++; // Stop flashing: stopBorderFlashing (); // Remove overlay: jQuery('#layer_' + currentImage).find('.template_zoomalert').remove (); /* if (current_zoom > 5) { return; } */ $(image).attr('zoom', current_zoom); oldwidth = stripPt(image.style.width); oldheight = stripPt(image.style.height); newheight = Math.floor(oldheight*zoomlevel); newwidth = Math.floor(oldwidth*zoomlevel); oldx = stripPt(image.style.left); oldy = stripPt(image.style.top); imageContainer = document.getElementById('userimage_' + currentImage); userimageareawidth = stripPt(imageContainer.style.width); userimageareaheight = stripPt(imageContainer.style.height); z = ((userimageareawidth*0.5/oldwidth) - (1.0*oldx / oldwidth)); offsetx = oldx - (newwidth-oldwidth)*z; z = ((userimageareaheight*0.5/oldheight) - (1.0*oldy / oldheight)); offsety = oldy - (newheight-oldheight)*z; image.style.width = newwidth + "px"; image.style.height = newheight + "px"; if (offsety > 0) { image.style.borderTop = '3 px solid green'; } image.style.top = offsety + "px"; image.style.left = offsetx + "px"; saveConfig("zoomData", "offsetx=" + offsetx + "&offsety=" + offsety + "&width=" + newwidth + "&height=" + newheight + "&imagenum=" + currentImage); checkIfImageIsTooSmall(); checkImageQuality(currentImage); /* saveConfig('offsetx', offsetx); saveConfig('offsety', offsety); saveConfig('width', newwidth); saveConfig('height', newheight); */ } function openFacebookIntegrationSempro (callback) { ClosePopup(); openElitefotoFaceBookIntegration(callback); } function externFacebookCallback (list) { OpenPopup('/sections/cardscalendars/ajax/popup_extern_download.php', function () { $.post("/sections/cardscalendars/image_from_url.php", {json: $.toJSON(list)}, function (data) { if (data.length > 0) { changeImage(currentImage, data[0]['uuid']); } // Add image sizes: for (idx in data) { var file = data[idx]; imageSizes[file["uuid"]] = file["width"] + " " + file['height']; } ClosePopup(); }, "json"); }); } function dump(arr,level) { var dumped_text = ""; if(!level) level = 0; //The padding given at the beginning of the line. var level_padding = ""; for(var j=0;j \"" + value + "\"\n"; } } } else { //Stings/Chars/Numbers etc. dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; } return dumped_text; } function checkImageQuality(imagenum) { if (typeof (imagenum) == "undefined") { imagenum = currentImage; } var image = document.getElementById('img_' + imagenum); // Not given that there is a image yet: if (!image) { return; } var imageContainer = document.getElementById('userimage_' + imagenum); var adaption = jQuery(imageContainer).attr('adaption'); var dstwidth = stripPt(imageContainer.style.width); var dstheight = stripPt(imageContainer.style.height); var imgoffsetx = stripPt(image.style.left); var imgoffsety = stripPt(image.style.top); var imgwidth = parseInt(stripPt(image.style.width)); var imgheight = parseInt(stripPt(image.style.height)); var re = image.src.match(/uuid\=([A-f\-0-9]+)/); if (re == null) { re = image.src.match(/photoid\=([A-f\-0-9]+)/); } // Still no image? if (!re) { return; } var imgid = re[1]; imagesize = imageSizes[imgid]; if (imagesize == "undefined" || imagesize == undefined) { return; } var size = imagesize.split(" "); var orgimgwidth = parseInt(size[0]); var orgimgheight = parseInt(size[1]); var rotation = 0; re = image.src.match(/rotation=(\d+)/); if (re) { rotation = parseInt(re[1]); } // In case image been rotated: if (rotation == 90 || rotation == 180) { var tmpow = orgimgwidth; var tmpoh = orgimgheight; orgimgwidth = tmpoh; orgimgheight = tmpow; } /* console.log('Original image size: ' + orgimgwidth + 'x' + orgimgheight); console.log('Displayed image size: ' + imgwidth + 'x' + imgheight); console.log('Adaption: ' + adaption); */ var realdstwidth = Math.round(dstwidth / templateScaleratio); var realdstheight = Math.round(dstheight / templateScaleratio); var imgsize = 0; // Get displayed pixels: if (adaption == 'fill-in') { var display_width = imgwidth - Math.abs(imgoffsetx) - (imgwidth - dstwidth - Math.abs(imgoffsetx)); var display_height = imgheight - Math.abs(imgoffsety) - (imgheight - dstheight - Math.abs(imgoffsety)); var ratio = imgwidth / orgimgwidth; // Real pixels: var real_display_width = (display_width / ratio); var real_display_height = (display_height / ratio); imgsize = parseInt(real_display_width * real_display_width); } else { // Fit in image: var display_width = imgwidth - Math.abs(imgoffsetx) - (imgwidth - dstwidth - Math.abs(imgoffsetx)); var display_height = imgheight - Math.abs(imgoffsety) - (imgheight - dstheight - Math.abs(imgoffsety)); if (imgoffsetx > 0) { display_width = imgwidth; } if (imgoffsety > 0) { display_height = imgheight; } var ratio = imgwidth / orgimgwidth; // Real pixels: var real_display_width = (display_width / ratio); var real_display_height = (display_height / ratio); //console.log(real_display_width); imgsize = parseInt(real_display_width * real_display_width); // As it's fit in, we might want to reduce the area size as not all need to be filled: if (imgoffsetx > 0) { var percent = (imgwidth/dstwidth); realdstwidth *= percent; } if (imgoffsety > 0) { var percent = (imgheight/dstheight); realdstheight *= percent; } } var dstsize = parseInt( realdstwidth * realdstheight ); var printsize10x10pixels = 1452025; // 1205 * 1205; 3305124 // Wrong template size? //var printsize15x15pixels = 3240000; // 1800 * 1800; // This is the actual template size (15.4cm) + safety margins var printsize15x15pixels = 3312400; // 1820 * 1820; var printsize20x30pixels = 8633994; // 2397 * 3602; var printsize50x70pixels = 48816635; // 5905 * 8267; //var sm_megapixels_0_4 = 374544; // 612*612 pixels (instagram) // Small adjustment: var sm_megapixels_0_4 = 360000; // 600*600 pixels (instagram) var sm_megapixels_2 = 2000000; var sm_megapixels_5 = 5000000; var sm_megapixels_10 = 10000000; var warning = false; if (dstsize > printsize50x70pixels) { if (imgsize < sm_megapixels_10) warning = true; } else if (dstsize > printsize20x30pixels) { if (imgsize < sm_megapixels_5) warning = true; } else if (dstsize > printsize15x15pixels) { if (imgsize < sm_megapixels_2) warning = true; } else if (dstsize >= printsize10x10pixels) { if (imgsize < sm_megapixels_0_4) warning = true; } else if (imgsize <= 50000) { warning = true; } if (jQuery('#layer_' + imagenum).find('.template_qualityalert').length == 0) { var elm = jQuery('
Bildefilen din har for lav oppløsning, eller du har zoomet for langt inn. Dette kan påvirke utskriftskvaliteten.
').appendTo( jQuery('#layer_' + currentImage) ); elm.css('width', jQuery('#layer_' + currentImage).width()); } // Actuall quality check var elm = jQuery('#layer_' + imagenum).find('.template_qualityalert'); if (warning) { elm.css({ 'display': 'block' }); } else { elm.css({ 'display': 'none' }); } return; } function stopBorderFlashing () { // Stop flashing: rightflashCounter = 10; leftflashCounter = 10; rightflashCounter = 10; bottomflashCounter = 10; } function flashTopBorder() { // selectedDiv = document.getElementById('userimage_' + numimage); var selectedDiv = document.getElementById('selectedImageFrame'); if (topflashCounter < 10) { if (topflashCounter % 2 == 0) { selectedDiv.style.borderTop = selected_element_border_size + 'px dashed red'; } else { selectedDiv.style.borderTop = selected_element_border_size + 'px dashed black'; } topflashCounter = topflashCounter+1; setTimeout("flashTopBorder()", 200); } else { // Restore frame etc: selectedDiv.style.borderTop = selected_element_border_size + 'px solid ' + selected_element_border_color; } } function flashLeftBorder() { // selectedDiv = document.getElementById('userimage_' + numimage); var selectedDiv = document.getElementById('selectedImageFrame'); if (leftflashCounter < 10) { if (leftflashCounter % 2 == 0) { selectedDiv.style.borderLeft = selected_element_border_size + 'px dashed red'; } else { selectedDiv.style.borderLeft = selected_element_border_size + 'px dashed black'; } leftflashCounter = leftflashCounter+1; setTimeout("flashLeftBorder()", 200); } else { // Restore frame etc: selectedDiv.style.borderLeft = selected_element_border_size + 'px solid ' + selected_element_border_color; } } function flashRightBorder() { // selectedDiv = document.getElementById('userimage_' + numimage); var selectedDiv = document.getElementById('selectedImageFrame'); if (rightflashCounter < 10) { if (rightflashCounter % 2 == 0) { selectedDiv.style.borderRight = selected_element_border_size + 'px dashed red'; } else { selectedDiv.style.borderRight = selected_element_border_size + 'px dashed black'; } rightflashCounter = rightflashCounter+1; setTimeout("flashRightBorder()", 200); } else { // Restore frame etc: selectedDiv.style.borderRight = selected_element_border_size + 'px solid ' + selected_element_border_color; } } function flashBottomBorder() { // selectedDiv = document.getElementById('userimage_' + numimage); var selectedDiv = document.getElementById('selectedImageFrame'); if (bottomflashCounter < 10) { if (bottomflashCounter % 2 == 0) { selectedDiv.style.borderBottom = selected_element_border_size + 'px dashed red'; } else { selectedDiv.style.borderBottom = selected_element_border_size + 'px dashed black'; } bottomflashCounter = bottomflashCounter+1; setTimeout("flashBottomBorder()", 200); } else { // Restore frame etc: selectedDiv.style.borderBottom = selected_element_border_size + 'px solid ' + selected_element_border_color; } } function pictureFillInContainer(obj) { var dwidth = $(obj).closest('div').width (); var dheight = $(obj).closest('div').height (); var swidth = obj.width; var sheight = obj.height; var info = getImageSize ('fill-in', swidth, sheight, dwidth, dheight); $(obj).css ( { top: info[1], left: info[0], width: info[2], height: info[3] }); } topflashCounter = 0; leftflashCounter = 0; rightflashCounter = 0; bottomflashCounter = 0; function checkFitIn(offsetx,offsety,width,height) { imageContainer = document.getElementById('userimage_' + currentImage); image = document.getElementById('img_' + currentImage); ret = 1; adaption = imageContainer.getAttribute('adaption'); cwidth = stripPt(imageContainer.style.width); cheight = stripPt(imageContainer.style.height) if (adaption == 'fill-in') { if (offsety > 0) { topflashCounter=0; flashTopBorder(); ret = 0; } if (offsetx > 0) { leftflashCounter=0; flashLeftBorder(); ret = 0; } if (width + offsetx < stripPt(imageContainer.style.width)) { rightflashCounter=0; flashRightBorder(); ret = 0; } if (height + offsety < stripPt(imageContainer.style.height)) { bottomflashCounter=0; flashBottomBorder(); ret = 0; } } else { // Fit-in if (offsety > 0 && width + offsetx < cwidth) { return 0; } else if (offsety > 0 && height + offsety < cheight) { image.style.top = (cheight/2)-(height/2) + "px"; return 2; } else if (offsety + height < cheight) { ret = 0; } else if (offsety > 0 && offsety+height > cheight ) { ret = 0; } // X-axis if (offsetx > 0 && height + offsety < cheight) { ret = 0; } else if (offsetx > 0 && width + offsetx < cwidth) { image.style.left = (cwidth/2)-(width/2) + "px"; return 3; } else if (offsetx + width < cwidth) { ret = 0; } else if (offsetx > 0 && width + offsetx > cwidth) { ret = 0; } } return ret; } function zoomOut(evt) { stopBubble(evt); var zoomlevel = 0.9; image = document.getElementById('img_' + currentImage); if (!image) { return; } // Check if zoom is disabled: var container = $(image).closest('div.userimagecontainer'); if ( container.attr('disable_zoom')) { return; } // Stop flashing: stopBorderFlashing (); re = image.src.match(/uuid=([a-f0-9-]+)/) image_uuid = re[1] imageContainer = document.getElementById('userimage_' + currentImage); userimageareawidth = stripPt(imageContainer.style.width); userimageareaheight = stripPt(imageContainer.style.height); oldwidth = stripPt(image.style.width); oldheight = stripPt(image.style.height); newheight = oldheight*zoomlevel; newwidth = oldwidth*zoomlevel; oldx = stripPt(image.style.left); oldy = stripPt(image.style.top); z = ((userimageareawidth*0.5/oldwidth) - (1.0*oldx / oldwidth)); offsetx = oldx - (newwidth-oldwidth)*z; z = ((userimageareaheight*0.5/oldheight) - (1.0*oldy / oldheight)); offsety = oldy - (newheight-oldheight)*z; ret = checkFitIn(offsetx, offsety, newwidth, newheight); if (ret != 0) { image.style.width = newwidth + "px"; image.style.height = newheight + "px"; if (ret == 3 || ret == 1) { image.style.top = offsety + "px"; } if (ret == 2 || ret == 1) { image.style.left = offsetx + "px"; } } else { if ($(imageContainer).attr('adaption') == 'fill-in') { // Assume fill in for now: if (offsety > 0) { offsety = 0; } if (offsetx > 0) { offsetx = 0; } if (offsetx + newwidth < userimageareawidth) { if (userimageareawidth - newwidth <= 0) { offsetx = userimageareawidth - newwidth; } } if (offsety + newheight < userimageareaheight) { if (userimageareaheight - newheight <= 0) { offsety = userimageareaheight - newheight; } } if (offsety + newheight < userimageareaheight) { newheight = userimageareaheight; var ratio = oldheight / newheight; newwidth = oldwidth / ratio; offsety = 0; offsetx = oldx / ratio; if (offsetx + newwidth < userimageareawidth) { if (userimageareawidth - newwidth < 0) { offsetx = userimageareawidth - newwidth; } } } if (offsetx + newwidth < userimageareawidth) { newwidth = userimageareawidth; var ratio = oldwidth / newwidth; newheight = oldheight / ratio; offsety = oldy / ratio; offsetx = 0; if (offsety + newheight < userimageareaheight) { if (userimageareaheight - newheight < 0) { offsety = userimageareaheight - newheight; } } } image.style.top = offsety + "px"; image.style.left = offsetx + "px"; image.style.width = newwidth + "px"; image.style.height = newheight + "px"; } else { // "Smart" zoomout for fit in is not made return; } } if (oldx == offsetx && oldy == offsety && oldwidth == newwidth && oldheight == newheight) { if (jQuery('#layer_' + currentImage).find('.template_zoomalert').length == 0) { var elm = jQuery('
Det er ikke mulig å zoome ut mer
').appendTo( jQuery('#layer_' + currentImage) ); elm.css('width', jQuery('#layer_' + currentImage).width()); } // Actuall quality check var elm = jQuery('#layer_' + currentImage).find('.template_zoomalert'); elm.css('display', 'block'); setTimeout (function () { elm.fadeOut ( function () { elm.remove (); }); }, 4000); // No reason to save: return; } saveConfig("zoomData", "offsetx=" + offsetx + "&offsety=" + offsety + "&width=" + newwidth + "&height=" + newheight + "&imagenum=" + currentImage) checkIfImageIsTooSmall(); checkImageQuality(currentImage); var current_zoom = 0; if ( $(image).attr('zoom') ) { current_zoom = parseInt($(image).attr('zoom')); } current_zoom--; $(image).attr('zoom', current_zoom); /* saveConfig('offsetx', offsetx); saveConfig('offsety', offsety); saveConfig('width', newwidth); saveConfig('height', newheight); */ } function checkIfImageIsTooSmall() { image = document.getElementById('img_' + currentImage); if (!image) { return; } offsetx = stripPt(image.style.left); offsety = stripPt(image.style.top); imagewidth = stripPt(image.style.width); imageheight = stripPt(image.style.height); warningdiv = document.getElementById('warningBox'); if (!warningdiv) { return; } divelement = document.getElementById('userimage_' + currentImage); userimageareawidth = stripPt(divelement.style.width); userimageareaheight = stripPt(divelement.style.height); if (offsetx > 0 || offsety > 0) { warningdiv.style.display = ''; } else if (offsetx+imagewidth < userimageareawidth) { warningdiv.style.display = ''; } else if (offsety+imageheight < userimageareaheight) { warningdiv.style.display = ''; } else { warningdiv.style.display = 'none'; } } // Need to fix cache of this! CONFIG_CACHE = new Array() CONFIG_VALUE = new Array() function saveConfig(name, value, func) { if (typeof(func) != "undefined") { doSaveConfig(name, value, func, currentImage); return; } if (!loadingimage) { loadingimage = true; loadingImageStart(currentImage); } if (!CONFIG_VALUE[name]) CONFIG_VALUE[name] = new Array() // No matter what, we always want the last value CONFIG_VALUE[name][currentImage] = value if (!CONFIG_CACHE[name]) CONFIG_CACHE[name] = new Array() if (CONFIG_CACHE[name][currentImage] == 2 || CONFIG_CACHE[name][currentImage] == 1) { CONFIG_CACHE[name][currentImage] = 1 return } // Its changed since last run, we need to do it again: CONFIG_CACHE[name][currentImage] = 1 doSave(name, value, func, currentImage); } function doSave(name, value, func, imagenum) { if (CONFIG_CACHE[name][imagenum] == 2) { CONFIG_CACHE[name][imagenum] = 0 doSaveConfig(name, CONFIG_VALUE[name][imagenum], func, imagenum) } else { CONFIG_CACHE[name][imagenum] = 2 setTimeout("doSave('" + name + "', '" + value + "', '" + func +"', " + imagenum +")", 1000); } } function updatePackagePreview () { num_packages = $('.package').length; if (typeof(current_package_page) == "undefined") { return; } obj = $('#package_template_' + current_package_page); $.get('/sections/cardscalendars/ajax/template_preview.php', {package: current_package_page, template: current_template_uuid}, function(data) { html = '
'+ ( parseInt(current_package_page)+1)+' / ' + num_packages + '
'; obj.html(data + html); var template = obj.find('div:first'); var width = template.css('width').replace('px', ''); var height = template.css('height').replace('px', ''); startx = 129/2 - width/2; starty = 98/2 - height/2; template.css('top', starty); template.css('left', startx); }); } function updatePackagePreviews() { num_packages = $('.package').length; $('.package').each ( function() { var obj = $(this); var templateUuid = $(this).attr('data-uuid'); $.get('/sections/cardscalendars/ajax/template_preview.php', {package: $(this).attr('packageoffset'), template: templateUuid, uuid: current_package_uuid}, function(data) { html = '
'+ ( parseInt(obj.attr('packageoffset'))+1)+' / ' + num_packages + '
'; obj.html(data + html); var template = obj.find('div:first'); var width = template.css('width').replace('px', ''); var height = template.css('height').replace('px', ''); startx = 129/2 - width/2; starty = 98/2 - height/2; template.css('top', starty); template.css('left', startx); }); }); } function doSaveConfig(name, value, func, imageNum) { /* Save config */ if (func == "undefined") { if (name == "zoomData") { jQuery.getJSON("/sections/cardscalendars/ajax/set_data.php?" + value + "&imagenum=" + imageNum + "&template=" + current_template_uuid, function (obj) { if (obj == null) { if ( $('.blockUI').length == 0) { $.blockUI ({message: "Vennligst vent mens vi lagrer innstillingene"}); } setTimeout("doSaveConfig('" + name + "', '"+value+"', '" + func + "', '" + imageNum + "')", 2000); return; } if (obj.error) { document.location.reload (); return; } $.unblockUI(); checkLoading(); updatePackagePreview(); checkImageQuality(imageNum); }); } else { jQuery.getJSON("/sections/cardscalendars/ajax/set_data.php?" + name + "=" + value + "&imagenum=" + imageNum + "&template=" + current_template_uuid, function (obj) { if (obj == null) { if ( $('.blockUI').length == 0) { $.blockUI ({message: "Vennligst vent mens vi lagrer innstillingene"}); } setTimeout("doSaveConfig('" + name + "', '"+value+"', '" + func + "', '" + imageNum + "')", 2000); return; } if (obj.error) { document.location.reload (); return; } $.unblockUI(); checkLoading(); updatePackagePreview(); } ); } } else if (func == 'rotate') { jQuery.getJSON("/sections/cardscalendars/ajax/set_data.php?" + name + "=" + value + "&imagenum=" + imageNum + "&template=" + current_template_uuid, function (obj) { if (obj == null) { if ( $('.blockUI').length == 0) { $.blockUI ({message: "Vennligst vent mens vi lagrer innstillingene"}); } setTimeout("doSaveConfig('" + name + "', '"+value+"', '" + func + "', '" + imageNum + "')", 2000); return; } if (obj.error) { // Reload the page: errorSavingData(obj.error) } $.unblockUI(); jQuery('#img_' + imageNum).css('position', 'absolute'); jQuery('#img_' + imageNum).css('left', obj.left + "px"); jQuery('#img_' + imageNum).css('top', obj.top + "px"); jQuery('#img_' + imageNum).css('width', obj.width + "px"); jQuery('#img_' + imageNum).css('height', obj.height + "px"); loadTemplateImage(obj.path, imageNum, false); checkImageQuality(imageNum); updatePackagePreview(); }); } else if (name == 'effect') { jQuery.getJSON("/sections/cardscalendars/ajax/set_data.php?" + name + "=" + value + "&imagenum=" + imageNum + "&template=" + current_template_uuid, function (obj) { if (obj == null) { if ( $('.blockUI').length == 0) { $.blockUI ({message: "Vennligst vent mens vi lagrer innstillingene"}); } setTimeout("doSaveConfig('" + name + "', '"+value+"', '" + func + "', '" + imageNum + "')", 2000); return; } if (obj.error) { // Reload the page: errorSavingData(obj.error) return; } if (obj.background) { var rotation = obj['background_rotation'] + '/'; var effect = obj['effect'] + '/'; $('#userimage_' + imageNum).css( { backgroundImage: 'url(/design/DEFAULT/graphics/templateimagebackgrounds/' + rotation + effect + obj['background'] + ')' }); } $.unblockUI(); loadTemplateImage(obj.path, imageNum, false); updatePackagePreview(); }); } else { jQuery.getJSON("/sections/cardscalendars/ajax/set_data.php?" + name + "=" + value + "&imagenum=" + imageNum + "&template=" + current_template_uuid, function (obj) { if (obj == null) { if ( $('.blockUI').length == 0) { $.blockUI ({message: "Vennligst vent mens vi lagrer innstillingene"}); } setTimeout("doSaveConfig('" + name + "', '"+value+"', '" + func + "', '" + imageNum + "')", 2000); return; } if (obj.error) { // Reload the page: errorSavingData(obj.error) return; } $.unblockUI(); loadTemplateImage(obj.path, imageNum, false); updatePackagePreview(); }); } } function errorSavingData(msg) { document.location.reload(); } function setProductTemplate(template, product) { $.getJSON('/sections/cardscalendars/ajax/change_template.php', {uuid: getUrlParam('uuid') , template: template, product: product}, function () { // Reload to update all names, prices etc: document.location.reload(); }); } function checkLoading() { // Check if we can remove loading image: found = false; for (i in CONFIG_CACHE) { for (j = 0; j 0) { found = true; } } } if (found == true) { if (!loadingimage) { loadingimage = true; loadingImageStart(imageNum); } } else { loading = document.getElementById('divLoading'); loadingimage = false; if (loading) { loading.parentNode.removeChild(loading); } } } function moveUp(evt) { // Stop flashing: stopBorderFlashing (); stopBubble(evt); image = document.getElementById('img_' + currentImage); if (image) { var newpos = stripPt(image.style.top) - 10; ret = checkFitIn(image.style.left, newpos, stripPt(image.style.width), stripPt(image.style.height)); if (ret == 0) return; if (ret == 1 || ret == 3) image.style.top = newpos + "px"; saveConfig('offsety', newpos); checkIfImageIsTooSmall(); } } function moveDown(evt) { // Stop flashing: stopBorderFlashing (); stopBubble(evt); image = document.getElementById('img_' + currentImage); if (image) { var newpos = stripPt(image.style.top) + 10; ret = checkFitIn(image.style.left, newpos, stripPt(image.style.width), stripPt(image.style.height)); if (ret == 0) return; if (ret == 1 || ret == 3) image.style.top = newpos + "px"; saveConfig('offsety', newpos); checkIfImageIsTooSmall(); } } function moveLeft(evt) { // Stop flashing: stopBorderFlashing (); stopBubble(evt); image = document.getElementById('img_' + currentImage); if (image) { var newpos = stripPt(image.style.left) - 10; ret = checkFitIn(newpos, image.style.top, stripPt(image.style.width), stripPt(image.style.height)); if (ret == 0) return; if (ret == 1 || ret == 2) image.style.left = newpos + "px"; saveConfig('offsetx', newpos); checkIfImageIsTooSmall(); } } function moveRight(evt) { // Stop flashing: stopBorderFlashing (); stopBubble(evt); image = document.getElementById('img_' + currentImage); if (image) { var newpos = stripPt(image.style.left) + 10; ret = checkFitIn(newpos, image.style.top, stripPt(image.style.width), stripPt(image.style.height)); if (ret == 0) return; if (ret == 1 || ret == 2) image.style.left = newpos + "px"; saveConfig('offsetx', newpos); checkIfImageIsTooSmall(); } } function stopBubble (evt) { if (evt) { if (evt.stopPropagation) { evt.stopPropagation(); } else if (evt.cancelBubble) { evt.cancelBubble = true; } } } function rotateLeft(evt) { var image = document.getElementById('img_' + currentImage); if (image) { saveConfig('rotateleft', 'true', 'rotate'); loadingImage(); stopBubble(evt); } } function rotateRight(evt) { var image = document.getElementById('img_' + currentImage); if (image) { saveConfig('rotateright', 'true', 'rotate'); loadingImage(); stopBubble(evt); } } loadingnum = 0; loadingimage = false; function loadingImage(numimage) { loadingimage = true; loadingImageStart(numimage); } function loadingImageStart(numimage) { if (typeof(numimage) == 'undefined') { numimage = currentImage; } if(loadingimage == false) { return; } loading = jQuery('#divLoading'); if (loading.length == 0) { loading = jQuery('
'); loading.css({ 'position': 'absolute', 'backgroundColor': 'white', 'color': 'black', 'padding': '2px', 'left': '0px', 'top': '0px' }); loading.height(20); loading.html('Laster bilde...'); loading.attr('id', 'divLoading'); jQuery("#selectedImageFrame").append(loading); } loading = jQuery('#divLoading'); if (loadingnum == 0) loading.html('Laster bilde'); else if (loadingnum == 1) loading.html('Laster bilde.'); else if (loadingnum == 2) loading.html('Laster bilde..'); else { loading.html( 'Laster bilde...'); loadingnum = 0; } loadingnum += 1; setTimeout("loadingImageStart("+numimage+")", 500); } function scaleEffectImage(img) { var imgwidth = $(img).width(); var imgheight = $(img).height(); var dheight = $(img).parent().height(); if (dheight == "auto") { dheight = 100000; } var info = getImageSize('fit-in', imgwidth, imgheight, $(img).parent().width(), dheight); $(img).css({'width': info[2], 'height': info[3], 'position': 'absolute', 'left': info[0], 'top': info[1], 'display': 'block' }); } function addCustomScrollbar(element) { $('div.customScrollBar').remove (); $(element).niceScroll( {cursorborder:"", cursorcolor:"#444", cursoropacitymin: 0.5, cursoropacitymax:0.9, cursorwidth:11, boxzoom:false}); } function changeColors() { // Get image id: loadingImage(); buttons = document.getElementsByName('imagetype'); for (i = 0; i < buttons.length; i++) { if (buttons[i].checked == true) imagetype = buttons[i].value; } doSaveConfig('effect', imagetype, 'true', currentImage); } function viewImageEffects (evt) { stopBubble(evt); $('div.edit_text').remove (); var url = "/sections/cardscalendars/ajax/view_effects.php?template=" + current_template_uuid + "&imagenum=" + currentImage; OpenPopup(url, null, true); } function setImageEffect (effect,evt) { image = document.getElementById('img_' + currentImage); if (image) { stopBubble(evt); loadingImage(); doSaveConfig('effect', effect, 'true', currentImage); } ClosePopup (); } var textupdatetimer = null; var lastupdatetext = ""; function updateTemplateText(obj, evt) { var num = $('#stringnum').val (); var val = obj.value; if (lastupdatetext == obj.value) { return; } lastupdatetext = obj.value; if (textupdatetimer != null) { clearTimeout(textupdatetimer); } var textelm = jQuery('div.template_textstring').eq(num); // Add gif if not present: if ( $('#textloader').length == 0) { var elm = $('
').appendTo(document.body); var pos = textelm.offset(); elm.css({ top: pos.top, left: pos.left }); } textelm.css('opacity', 0.6); textupdatetimer = setTimeout(function () { textupdatetimer = null; doUpdateTextString(num, {text: obj.value}); }, 1000); } function onCloseTextEdit () { if ($('#textloader').length > 0) { // Wait till loaded: setTimeout(onCloseTextEdit, 300); return; } // Do remove it: jQuery(".edit_text").remove(); } function doUpdateTextString(num, options) { var textelm = jQuery('div.template_textstring').eq(num); // Add gif if not present: if ( $('#textloader').length == 0) { var elm = $('
').appendTo(document.body); var pos = textelm.offset(); elm.css({ top: pos.top, left: pos.left }); } textelm.css({ opacity: 0.6 }); $('#yourtext_' + num).css({ backgroundColor: 'white', color: 'black' }); $('#tooLongTextDiv').css('display', 'none'); jQuery.getJSON("/sections/cardscalendars/ajax/set_text.php?template=" + current_template_uuid, jQuery("#textform").serialize(), function (data) { if (data.status == "ERROR") { var number = data.stringnum; var text = data.text; errorinput = jQuery('#yourtext_' + number); if (errorinput) errorinput.css("background-color", '#ff8282'); warningtext = jQuery('#tooLongTextDiv'); warningtext.html(text); warningtext.css("display", ""); $('#textloader').remove (); textelm.css('opacity', 1); } else if (data.error) { document.location.reload (); } else if (data.redirect) { document.location.href = data.redirect; return; } // We load the image, even when errors: // Preload the image: var url = ""; if (navigator.userAgent.match(/MSIE (5.5|6.0)/)) { var bgimage = textelm.css("filter"); var re = bgimage.match(/(TextString.php\?partnum=\d+&stringnum=\d+)/); url = re[1]; } else { var bgimage = textelm.css("background-image"); var re = bgimage.match(/(TextString.php\?partnum=\d+&stringnum=\d+)/); url = re[1]; } var d = new Date(); var localtime = d.getTime(); url += "&time=" + localtime; url += "&uuid=" + current_template_uuid; /* if (typeof(options) != 'undefined' && options !== null) { url += "&options=" + encodeURIComponent($.toJSON(options)); } */ // add basepath: url = '/sections/cardscalendars/' + url; var img = new Image (); img.onload = function () { var url = $(this).attr('src'); if (navigator.userAgent.match(/MSIE (5.5|6.0)/)) { textelm.css("filter", 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + url + '" , sizingMethod="scale")'); } else { textelm.css('background-image', 'url(' + url + ')'); } $('#textloader').remove (); textelm.css('opacity', 1); } img.src = url; }); } function previewPage () { var copy = $('#templatecontent').clone (); var elm_pos = $('#templatecontent').offset(); var left = elm_pos.left; var top = elm_pos.top; var height = $(document).height (); var width = $(document).width (); $('#selectedImageFrame').remove(); copy.find('.userimage_overlay').remove (); $(copy).attr('id', 'template_choose_picture') $(copy).css({ position: 'absolute', left: left, top: top, zIndex: 101, margin: 0 }); copy.find('.template_imagearea_overlay').attr('onclick', '').css('cursor', 'auto'); copy.find('.userimagecontainer img').attr('onclick', '').css('cursor', 'auto'); copy.find('.template_textstring').attr('onclick', '').css('cursor', 'auto'); $('body').append("
") $('body').append(copy); $('#change_pic_bg').click ( function () { $('#change_pic_bg').remove (); $('#change_text_infotext_visible').remove (); $('#template_choose_picture').remove (); }); copy.click ( function () { $('#change_pic_bg').remove (); $('#change_text_infotext_visible').remove (); $('#template_choose_picture').remove (); }); } function cardChooseTextChange () { // If no texts? if ( $('.template_textstring').length == 0) { OpenPopup("/sections/cardscalendars/ajax/template_no_text.php"); return; } // Remove text: $('div.edit_text').remove (); var copy = $('#templatecontent').clone (); var elm_pos = $('#templatecontent').offset(); var left = elm_pos.left; var top = elm_pos.top; var height = $(document).height (); var width = $(document).width (); $('#selectedImageFrame').remove(); copy.find('.userimage_overlay').remove (); $(copy).attr('id', 'template_choose_picture') $(copy).css({ position: 'absolute', left: left, top: top, zIndex: 101, margin: 0 }); copy.find('.template_imagearea_overlay').attr('onclick', ''); copy.find('div.template_textstring').css ({ border: '4px solid #44445c', backgroundColor: '#878794' }); copy.find('div.userimagecontainer').css ( { opacity: 0.3 }); $('body').append("
") $('body').append(copy); $('#change_pic_bg').click ( function () { $('#change_pic_bg').remove (); $('#change_text_infotext_visible').remove (); $('#template_choose_picture').remove (); }); var infotext = $('#change_text_infotext').clone (); infotext.attr('id', 'change_text_infotext_visible') var pos = $('#template_header').offset (); infotext.css({ position: 'absolute', left: pos.left, top: pos.top, zIndex: 101, display: 'block' }); $('body').append(infotext); $.scrollTo ( $('#change_text_infotext_visible') ); } function cardChoosePictureChange () { // Remove text: $('div.edit_text').remove (); // Maybe only one picture? if ($('div.userimagecontainer').length == 1) { cardChooseImage(0); return; } var copy = $('#templatecontent').clone (); var elm_pos = $('#templatecontent').offset(); var left = elm_pos.left; var top = elm_pos.top; var height = $(document).height (); var width = $(document).width (); $('#selectedImageFrame').remove(); $(copy).attr('id', 'template_choose_picture') $(copy).css({ position: 'absolute', left: left, top: top, zIndex: 101, margin: 0 }); copy.find('.template_imagearea_overlay').attr('onclick', 'cardChooseImageWrapper(this, event);'); copy.find('div.template_textstring').remove (); $('body').append("
") $('body').append(copy); $('#change_pic_bg').click ( function () { $('#change_pic_bg').remove (); $('#change_picture_infotext_visible').remove (); $('#template_choose_picture').remove (); }); var infotext = $('#change_picture_infotext').clone (); infotext.attr('id', 'change_picture_infotext_visible') var pos = $('#template_header').offset (); infotext.css({ position: 'absolute', left: pos.left, top: pos.top, zIndex: 101, display: 'block' }); $('#change_picture_infotext_visible').scrollTo (); $('body').append(infotext); } function updateMonths() { jQuery.getJSON ('/sections/cardscalendars/ajax/get_current_month.php', {template: current_template_uuid}, function (data) { if (data.error) { document.location.reload (); return; } setMonthCovered(data.month); }); } function setMonthCovered(page) { month = document.getElementById('month_' + (page)); if (month) { month.src = '/design/DEFAULT/graphics/calendar/calight-green.png'; // month.style.backgroundColor = 'green'; } } imageLoadNum = 0; function loadTemplateImage(source, numImage, reloadimage) { if (typeof(numimage) == 'undefined' || numimage == false) { numimage = currentImage; } if (typeof(reloadimage) == "undefined") { reloadimage = true; } else { reloadimage = false; } loadedstatus[numImage] = 0; errorSwitch[numImage] = 0; loadTemplateImg(numImage, reloadimage, source); } function loadTemplateImg(numImage, reloadimage, source) { // alert('loadTemplateImg: ' + numImage + 'loaded status ' + loadedstatus[numImage]); if (typeof(numImage) == 'undefined') { numimage = currentImage; } if (loadedstatus[numImage] == 0) { image = document.createElement('img'); image.numimage = numImage; if (safari) { image.setAttribute("reloadimage", reloadimage); } else { image.reloadimage = reloadimage; } if (safari) { image.setAttribute('onload', 'loadedTemplateImage(this,'+numImage+')'); } else { image.onload = loadedTemplateImage; } image.setAttribute('onerror', 'errorTemplateImage(this);'); // Have to add a random var, so IE7 refresh the image random = Math.floor(Math.random() * 55555555); image.src = source + "&random=" + random; loadedstatus[numimage] = 1; } return true; } function increaseNumberOfCopies() { number = document.getElementById('numberofcopies'); if (number) { num = parseInt(number.value); number.value = num + 1; } } function decreaseNumberOfCopies() { number = document.getElementById('numberofcopies'); if (number) { num = parseInt(number.value); if (num > 1) number.value = num - 1; } } function cardChooseImageWrapper(obj, evt) { stopBubble(evt); var re = $(obj).parent().attr('id').match(/layer_(\d+)/); numimage = re[1]; cardChooseImage(numimage); } function cardChooseImage(numimage) { if (loadingimage) { alert('Vennligst vent til bildet er lastet før du velger et nytt bilde'); return 0; } $('div.edit_text').remove (); // Close other stuff: $('#change_pic_bg').remove (); $('#change_picture_infotext_visible').remove (); $('#template_choose_picture').remove (); if (typeof(numimage) != 'undefined') { currentImage = numimage; } selectImage(currentImage); if (window.location.href.match(/calendarsv2/)) { createWizard(); $.get('ajax_wizard.php', {page: "cardchooseimage", numimage: currentImage}, wizardPageComplete); } else { stopProgressBar(); OpenPopup("/sections/cardscalendars/ajax/chooseimage.php?page=cardchooseimage&numimage=" + currentImage + "&template=" + current_template_uuid, null, true); } } function templateChoosePreviewImage () { OpenPopup("/sections/cardscalendars/ajax/chooseimage.php?page=previewimage", null, true); } function cardChooseText(textnum) { if (typeof(textnum) != 'undefined') { activetext = textnum; } else { activetext = 0; } var textelm = $('div.template_textstring').eq(activetext); $('div.edit_text').remove (); $('#change_pic_bg').remove (); $('#change_text_infotext_visible').remove (); $('#template_choose_picture').remove (); $.getJSON('/sections/cardscalendars/ajax/edit_single_text.php', { activetext: activetext, template: current_template_uuid}, function (data) { if (data.session_timeout) { sessionTimedOut(); return; } else if (data.error) { document.location.reload (); return; } var pos = textelm.offset (); var width = textelm.width (); var height = textelm.height (); var elm = $(data.dialog); $('body').append(elm); var left = pos.left + ( (width/2) - $(elm).width()/2 ); elm.css ( { position: 'absolute', top: pos.top + height+10, zIndex: 101 }); // For some reason, this need to be set after other settings is set: elm.css('left',pos.left + ( (width/2) - $(elm).width()/2 )); // Add color picker activateColorPicker(); $(document).click( function () { onCloseTextEdit(); }); $('.edit_text').click ( function (e) { e.stopPropagation(); }); // Scroll to show the text: $.scrollTo( '.edit_text '); }); //OpenPopup("/sections/cardscalendars/ajax/edit_text.php?activetext=" + activetext + "&template=" + current_template_uuid, "activateColorPicker()"); } function activateColorPicker() { $('.colorPicker').colorPicker(); } function cardAddText(close) { if (typeof(close) != 'undefined') { close = 1; } else { close = 0; } warningtext = jQuery('#tooLongTextDiv'); warningtext.css('display', 'none'); var fieldCounter = 0; var done = false; while (done == false) { errorinput = jQuery('#yourtext_' + fieldCounter); if (errorinput.length > 0) { bgcolor = jQuery('#fontcolor_' + fieldCounter); var bgcolor = getBackgroundColor(bgcolor.val()); errorinput.css('backgroundColor', bgcolor); } else { done = true; } fieldCounter += 1; } jQuery.getJSON("/sections/cardscalendars/ajax/set_text.php?template=" + current_template_uuid, jQuery("#textform").serialize(), function (data) { console.log(data); if (data.status == "ERROR") { var number = data.stringnum; var text = data.text; errorinput = jQuery('#yourtext_' + number); if (errorinput) errorinput.css("background-color", '#ff8282'); warningtext = jQuery('#tooLongTextDiv'); warningtext.html(text); warningtext.css("display", ""); $('#textloader').remove (); textelm.css('opacity', 1); } else if (data.error) { document.location.reload (); } else if (data.redirect) { document.location.href = data.redirect; return; } else { reloadTextStrings(); if (close == 1) { ClosePopup(); } } }); } function reloadTextStrings() { var num = 0; while (jQuery('#textarea_' + num).length > 0) { textstrings = jQuery('#textarea_' + num); if (navigator.userAgent.match(/MSIE (5.5|6.0)/)) { bgimage = textstrings.css("filter"); var re = bgimage.match(/(TextString.php\?partnum=\d+&stringnum=\d+)/); url = re[1]; var d = new Date(); localtime = d.getTime(); textstrings.css("filter", 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + url + '&time=' + localtime + '" , sizingMethod="scale")'); // alert(textstrings.style.filter); } else { bgimage = textstrings.css("background-image"); var re = bgimage.match(/(TextString.php\?partnum=\d+&stringnum=\d+)/); url = re[1]; var d = new Date(); localtime = d.getTime(); textstrings.css('background-image', 'url(/sections/cardscalendars/' + url + '&uuid=' + current_template_uuid + '&time=' + localtime + ')'); } num = num + 1; } } function updateText(text) { textarea = document.getElementById('textarea'); if (textarea) { bg = textarea.style.backgroundImage; // alert(bg); start = bg.indexOf('text='); // alert(start); end = bg.substr(bg.indexOf('text=')).indexOf('&') + start; newstring = bg.substr(0,start) + bg.substr(end+1); newstring = newstring.substr(4); newstring = newstring.substr(0, newstring.length-1); newstring = newstring.replace(" ", "+"); textarea.style.backgroundImage = 'url("' + newstring.substr(0,newstring.length-1) + "&text=" + text + '")'; closeWizard(); } } function getKeyCode(e) { var keynum; var numcheck; if(window.event) // IE { keynum = e.keyCode } else if(e.which) // Netscape/Firefox/Opera { keynum = e.which } return keynum; } var imageIsNull = 0; function imageGetSize (numimage, refresh) { if (document.getElementById('tempimageid').width != 0) { var tempimage = document.getElementById('tempimageid'); var image = document.getElementById('img_' + currentImage); image.style.height = tempimage.height + "px"; image.style.width = tempimage.width + "px"; image.style.cursor = 'pointer'; image.idx = currentImage; image.onclick = function () { selectImage(this.idx); } loading = document.getElementById('divLoading'); loadingimage = false; if (loading) { loading.parentNode.removeChild(loading); } imageIsNull = 0; document.body.removeChild(tempimage); adjustImage('true', numimage, true); return 0; } switch (imageIsNull) { case 0: // Wait some, then check again: timer = setTimeout("imageIsNull=1;imageGetSize("+numimage+");", 2000); //sleep for 500 ms // alert('Setting timer etc'); break; case 1: imageIsNull = 0; // alert('Not setting timer'); break; } return 0; } function loadedTemplateImage(object, numImage) { // alert(loadedstatus); if (typeof(numimage) == "object") { numImage = this.numimage; } if (typeof(numImage) == 'undefined') { numImage = this.numimage; } if (typeof(numImage) == 'undefined') { numImage = currentImage; } loadedstatus[numImage] = 2; var image = document.getElementById('img_' + numImage); imageContainer = document.getElementById('userimage_' + numImage); imageContainer.style.border = 'none'; imageContainer.style.backgroundColor = "transparent"; if (!image) { imageContainer.innerHTML = ''; var image = document.getElementById('img_' + numImage); } if (safari) { this.src = object.src; // If safari, we create a temp image: } if (NTLF_CONFIG.portal.is_prophoto) { image.onload = function () { checkImageQuality(numImage); } } image.numimage = numImage; image.src = this.src; if (this.reloadimage) { image.style.height = this.height + "px"; image.style.width = this.width + "px"; image.style.cursor = 'pointer'; image.idx = currentImage; image.onclick = function () { selectImage(this.idx); } loading = document.getElementById('divLoading'); loadingimage = false; if (loading) { loading.parentNode.removeChild(loading); } } else { loading = document.getElementById('divLoading'); loadingimage = false; if (loading) { loading.parentNode.removeChild(loading); } } return true; } function hideForm(formid) { form = document.getElementById(formid); if (form) { inputs = document.getElementsByTagName('input'); for (var i = 0; i < inputs.length; i++) { inputs[i].style.display = 'none'; } } } function showForm(formid) { form = document.getElementById(formid); if (form) { inputs = document.getElementsByTagName('input'); for (var i = 0; i < inputs.length; i++) { inputs[i].style.display = ''; } } } var currbar = 0; var progressrunning = false; function ProgressBar() { if (progressrunning == false) return; if (!document.getElementById('formarea')) return false; barelement = document.getElementById('formarea'); var width = 100; var height = 13; var barwidth = 10; if (currbar == 10) currbar = 0; barpos = currbar*barwidth; pdiv = document.getElementById('progressdiv'); if (!pdiv) { pdiv = document.createElement('div'); pdiv.setAttribute('id', 'progressdiv'); pdiv.style.width = width + 'px'; pdiv.style.height = height + 'px'; pdiv.style.position = 'relative'; pdiv.style.border = '1px solid black'; barelement.appendChild(pdiv); } bardiv = document.getElementById('bardiv'); if (!bardiv) { bardiv = document.createElement('div'); bardiv.setAttribute('id', 'bardiv'); bardiv.style.height = height + 'px'; bardiv.style.width = barwidth + 'px'; bardiv.style.backgroundColor = 'black'; bardiv.style.position = 'absolute'; bardiv.style.left = barpos + 'px'; pdiv.appendChild(bardiv); } else bardiv.style.left = barpos + 'px'; currbar = currbar+1; setTimeout("ProgressBar()", 500); } function removeProgressBar() { pdiv = document.getElementById('progressdiv'); if (pdiv) { pdiv.parentNode.removeChild(pdiv); } } var loadedstatus = new Array(); var errorSwitch = new Array(); currLoading = 0; function errorTemplateImage(obj) { numImage = obj.numimage; if (typeof(numImage) == 'undefined') { numImage = currentImage; } timer = setTimeout("retryLoad(" + numImage + ", '" + obj.src + "');", 2000); //sleep for 500 ms } function retryLoad(num, src) { clearTimeout(timer); errorSwitch[numImage]=0; loadedstatus[numImage] = 0; loadTemplateImg(numImage, true, src); } var imageloaded = 0; imgstatus = new Array(); imgtable = new Array(); imgloadtable = new Array(); imageCount = 0; function preLoadImages() { // Wait for browser to catch stuff: for (i=0;i sratio) { debug('width'); diff = dwidth/swidth; width = dwidth; height = diff*sheight; } else { debug('height'); diff = dheight/sheight; height = dheight; width = diff*swidth; } debug(width + " " + height); return [width, height]; } function fitIn(swidth, sheight, dwidth, dheight) { if (typeof(dwidth) == 'undefined') var dwidth = 90; if (typeof(dheight) == 'undefined') var dheight = 70; var dratio = dwidth/dheight; var sratio = swidth/sheight; if (dratio < sratio) { debug('width'); diff = dwidth/swidth; width = dwidth; height = diff*sheight; } else { debug('height'); diff = dheight/sheight; height = dheight; width = diff*swidth; } debug(width + " " + height); return [width, height]; } function getImageBoxSize(i) { var image = $('#image_' + i); size = fitIn(image.width(), image.height()); image.css('width', size[0] + 'px'); image.css('height', size[1] + 'px'); } // FIXME oldimage = new Array(); function isImageUsed(imgnum, partnum, img) { usedImages[imgnum]++; if (typeof(oldimage[partnum][img]) != "undefined") usedImages[oldimage[partnum][img]]--; for (var i in usedImages) { if (usedImages[i] == 0) { jQuery('#imageused_' + i).css('display', 'none'); } else { if (jQuery('#imageused_' + i).length > 0) { jQuery('#imageused_' + i).css('display', ''); } } } } function setUserimageBackground(filename, num) { if (typeof (num) != 'undefined') { currentImage = num; selectImage(currentImage); } var imagenum = currentImage; $.getJSON('/sections/cardscalendars/ajax/set_data.php', {template: current_template_uuid, imagenum: currentImage, background: filename}, function (data) { var rotation = data['background_rotation'] + '/'; var effect = data['effect'] + '/'; $('#userimage_' + imagenum).css( { backgroundImage: 'url(/design/DEFAULT/graphics/templateimagebackgrounds/' + rotation + effect + data['background'] + ')', backgroundSize: 'cover' }); updatePackagePreview (); }); } function loadedImage(object,i) { // alert(object.src); imgstatus[i] = 2; // alert('image loaded'); var image = $('#image_' + i); if (image) { size = fillIn(object.width, object.height); image.css('width', size[0] + 'px'); image.css('height', size[1] + 'px'); image.attr('src', object.src); image.css('left', (50/2)-(size[0]/2) + 'px'); image.css('top', (50/2)-(size[1]/2) + 'px'); image.css('border', 'none'); $(image).addClass('prophotopicture'); // Parent offset: var parentDiv = $('#image_parent_' + i); var re = object.src.match(/(photoid=([0-9]+)|uuid\=([A-f\-0-9]+))/); var imgid = re[3]; image.attr('photoid', imgid); jQuery("#image_" + i ).draggable({ helper: "clone", appendTo: "body" }); //new SubsDraggable('image_' + i, {revert: true, dragelement:getDragElement}); image.css('cursor', 'move'); // Need a second try on fit in for safari if (safari) { getImageBoxSize(i); } } else { imgstatus[i] = 0; } imageloaded++; loadImages(); return true; } function debug(message) { // document.getElementById('debugdiv').innerHTML += message + "
"; } function scaleImage(imageid) { image = document.getElementById(imageid) if (image) { dstwidth = 85; dstheight = 70; orgwidth = stripPt(image.width); orgheight = stripPx(image.height); fitratio = dstwidth/dstheight; orgratio = orgwidth/orgheight; if (fitratio > orgratio) { diff = orgwidth/dstwidth; height = orgheight*diff; width = dstwidth; } else { diff = orgheight/dstheight; width = orgwidth*diff; height = dstheight; } return width; } } function imageLoadError(i) { // alert('imageloaderror'); imgstatus[i] = 0; setTimeout("loadImages()", 2000); } function loadImage(src) { var tryimage = new Image(); tryimage.onload = loadedImage; tryimage.onerror = imageLoadError; tryimage.src=src; return true; } function stripPt(value) { if (value == "") return 0; return parseFloat(value.substring(0, value.length - 2)); } var picker; var pickerTarget; var pickerExample; function selectText(textnum) { // Hide all first: var num = 0; while ($('#toolbar_' + num).length > 0) { textarea = $('#toolbar_' + num); textarea.css('display', 'none'); $('#toolbar_hidden_' + num).css('display', ''); num = num+1; } // Select current one: $('#toolbar_hidden_' + textnum).css('display', 'none'); $('#toolbar_' + textnum).css('display', ''); } function getBackgroundColor(color) { var r = Hex2Dec(color.substring(1,3)); var g = Hex2Dec(color.substring(3,5)); var b = Hex2Dec(color.substring(5,7)); if ((r+g+b)/3 < 127) { var bgcolor = "white"; } else { var bgcolor = "black"; } return bgcolor; } function updateColorAndClose(color) { picker.hide(); picker = null; bgcolor = getBackgroundColor(color); $('#yourtext_' + pickerTarget).css('background-color', bgcolor); $('#yourtext_' + pickerTarget).css('color', color); $('#fontcolor_' + pickerTarget).val(color); $('#smallfontcolor_' + pickerTarget).css('background-color', color); doUpdateTextString(currentString, {fontcolor: color}); } function onChangeFontZoom(obj, stringNum) { if (typeof(stringNum) == "undefined") { stringNum = currentString; } doUpdateTextString(stringNum, {fontzoom: $(obj).val()}); } function chooseFont(font, image, evt) { jQuery("#fontchooser").remove(); jQuery('#fontfamily_' + currentString).val(font); jQuery('#fontImage_' + currentString).attr('src', image); doUpdateTextString(currentString, {font: font}); stopBubble(evt) } function closeStringToolbarItems() { jQuery('#fontchooser').remove(); jQuery('#fontZoomer').remove(); jQuery('#colorPalette').remove(); } currentString = 0; function photogiftFontChooser(id, stringnum, e) { if ($('#fontchooser').length > 0) { return; } closeStringToolbarItems(); obj = document.getElementById(id); currentString = stringnum; fonts = new Array(); fonts[0] = '
'; fonts[1] = '
'; fonts[2] = '
'; fonts[3] = '
'; fonts[4] = '
'; fonts[5] = '
'; fonts[6] = '
'; fonts[7] = '
'; fonts[8] = '
'; fonts[9] = '
'; fonts[10] = '
'; fonts[11] = '
'; fonts[12] = '
'; var starty = getY(obj) + obj.height; var startx = getX(obj); var fontchooser = document.createElement('div'); fontchooser.style.position = 'absolute'; fontchooser.style.top = starty + 0 + 'px'; fontchooser.style.left = startx + 'px'; fontchooser.style.border = '1px solid black'; fontchooser.style.zIndex = 101; fontchooser.style.backgroundColor = 'white'; fontchooser.id = 'fontchooser'; for (i=0;i 0) { return; } closeStringToolbarItems(); obj = document.getElementById(id); currentString = stringnum; fonts = new Array(); fonts[0] = '
'; fonts[1] = '
'; fonts[2] = '
'; fonts[3] = '
'; fonts[4] = '
'; fonts[5] = '
'; fonts[6] = '
'; fonts[7] = '
'; fonts[8] = '
'; fonts[9] = '
'; fonts[10] = '
'; fonts[11] = '
'; fonts[12] = '
'; var starty = getY(obj) + obj.height; var startx = getX(obj); var fontchooser = document.createElement('div'); fontchooser.style.position = 'absolute'; fontchooser.style.top = starty + 5 + 'px'; fontchooser.style.left = startx + 'px'; fontchooser.style.border = '10px solid black'; fontchooser.style.zIndex = 101; fontchooser.style.backgroundColor = 'white'; fontchooser.id = 'fontchooser'; for (i=0;i 0) { return; } closeStringToolbarItems(); obj = document.getElementById(id); currentString = stringnum; var sizes = new Array(); sizes[0] = "
" sizes[1] = "
" sizes[2] = "
" sizes[3] = "
" sizes[4] = "
" var starty = getY(obj) + 12; var startx = getX(obj); var fontchooser = document.createElement('div'); fontchooser.style.position = 'absolute'; fontchooser.style.top = starty + 7 + 'px'; fontchooser.style.left = startx + 'px'; fontchooser.style.border = '10px solid black'; fontchooser.style.backgroundColor = 'white'; fontchooser.id = 'fontZoomer'; for (i=0;i