/* updated */ if (typeof hideInlineMPU == "undefined") { var cssId = 'storypromocss'; // you could encode the css path itself to generate id.. if (!document.getElementById(cssId)) { var head = document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.id = cssId; link.rel = 'stylesheet'; link.type = 'text/css'; link.href = 'http://www.cnnewmedia.co.uk/storypromo/css/storypromo.css'; link.media = 'all'; head.appendChild(link); } var jsonValues = {"par":"6","title":"More business news:","values":[{"title":"Andrew Tinkler tells court he learned of his Stobart Group sacking from media reports","link":"http:\/\/www.in-cumbria.com\/news\/Andrew-Tinkler-tells-court-he-learned-of-his-Stobart-Group-sacking-from-media-reports-692d8e89-5ce4-44a0-a1c7-cfd7b4ed0b48-ds","image":"cd0ebe27-07b1-42e0-aa6b-e73bf63e79ed","imageCrop":[]},{"title":"Lakes Gin to be stocked at Co-op nationwide","link":"http:\/\/www.in-cumbria.com\/news\/Lakes-Gin-to-be-stocked-at-Co-op-nationwide-6ccfd8f4-86ce-42f7-95b0-0072b8b68921-ds","image":"fef2df85-acd3-494f-aeec-37915c997686","imageCrop":[]},{"title":"Eight-fold increase in Chinese visitors for Cumbrian hotel group","link":"http:\/\/www.in-cumbria.com\/news\/Eight-fold-increase-in-Chinese-visitors-for-Cumbrian-hotel-group-65700541-7286-4ab3-acda-5baef578d058-ds","image":"4398b886-7faa-4ef9-b3a1-8ec6a5b70b97","imageCrop":[]},{"title":"Winners revealed at in-Cumbria Business Awards 2018","link":"http:\/\/www.in-cumbria.com\/news\/Winners-revealed-at-in-Cumbria-Business-Awards-2018-8345f01a-056b-4da2-b999-4efd58240b80-ds","image":"7e5bfcce-0462-453f-8ca7-1fcf3662c5ea","imageCrop":[]}]}; var insertAfter = jsonValues.par; var promotitlediv = document.getElementById("storypromotitle"); promotitlediv.innerHTML = jsonValues.title; var promodiv = document.getElementById("storypromo"); var promoarticleslist = document.getElementById("storypromoarticleslist"); var storyPromoSliderDiv = document.createElement("div"); storyPromoSliderDiv.setAttribute("id", "storypromo-slider"); promodiv.appendChild(storyPromoSliderDiv); storyPromoSliderDiv.setAttribute("class", "owl-carousel owl-theme"); console.log("Values length is " + jsonValues.values.length); if (jsonValues.values.length == 0) promodiv.style.display = "none"; else { for (x = 0; x < jsonValues.values.length; x++) { var listitem = document.createElement("div") listitem.setAttribute("class", "item storypromo"); var linkdiv = document.createElement("a"); linkdiv.setAttribute("href", jsonValues.values[x].link); linkdiv.setAttribute("title", jsonValues.values[x].title); var linkImageDiv = document.createElement("div"); linkImageDiv.setAttribute("class", "storypromoImage"); var linkImage = document.createElement("img"); if ("targetX0" in jsonValues.values[x].imageCrop) cropString = "targetX0=" + jsonValues.values[x].imageCrop["targetX0"] + "_targetX1=" + jsonValues.values[x].imageCrop["targetX1"] + "_targetY0=" + jsonValues.values[x].imageCrop["targetY0"] + "_targetY1=" + jsonValues.values[x].imageCrop["targetY1"] + "_"; else cropString = "" linkImage.setAttribute("data-src", "http://www.in-cumbria.com/portalsuite/image/" + jsonValues.values[x].image + "/mainMediaSize=226x169_" + cropString + "type=image_publish=true_role=1_image.jpg"); linkImage.setAttribute("class", "lazyOwl"); linkImageDiv.appendChild(linkImage); linkdiv.append(linkImageDiv); var linkTextNode = document.createTextNode(jsonValues.values[x].title) ; linkdiv.append(linkTextNode); listitem.appendChild(linkdiv); storyPromoSliderDiv.appendChild(listitem); } if (jsonValues.values.length > 0) { promodiv.style.display = "block"; promodiv.style.clear = "both"; var articleElement = document.getElementsByClassName("article_story"); var paragraphtags = articleElement[0].getElementsByTagName("p") if (paragraphtags.length > insertAfter) articleElement[0].insertBefore(promodiv, paragraphtags[insertAfter]); else articleElement[0].insertBefore(promodiv, paragraphtags[paragraphtags.length]); } } jQuery(document).ready(function() { var storypromoslider = jQuery("#storypromo-slider"); storypromoslider.owlCarousel({ navigation : false, autoPlay: 7000, lazyLoad: true, itemsTablet: [800, 3], itemsMobile: [600, 2], items: 4 }); // Custom Navigation Events jQuery(".next").click(function(){ owl.trigger('owl.next'); }) jQuery(".prev").click(function(){ owl.trigger('owl.prev'); }) jQuery(".play").click(function(){ owl.trigger('owl.play',1000); //owl.play event accept autoPlay speed as second parameter }) jQuery(".stop").click(function(){ owl.trigger('owl.stop'); }) }); var styleText = "#storypromo-slider .storypromo {margin: 0 10px}; " + "div.storypromoAddress {font-weight: bold; font-size:1rem} " + "div.storypromoPrice {font-weight: bold; font-size:0.9rem} " + ".storypromoImage img.lazyOwl {position: absolute;top: 0;left: 0;/* bottom: 0; *//* right: 0; */ height: 100%;/* display: block !important; */max-width: none;}" + ".storypromoImage {display: block; max-height: 100%; padding: 75% 0 0 0; height: 0; overflow: hidden; position: relative; width: auto; }"; var styleNode = document.createElement("style"); styleNode.type = "text/css"; styleNode.appendChild(document.createTextNode(styleText)); document.getElementsByTagName('head')[0].appendChild(styleNode); } else{ document.getElementById("storypromo").style.display = "none"; }