/** * TOSOM PRIVACY WIDGET * handles loading and showing the privacy data for websites. * Allowed access to only registered domains. * * @author Tosom s.r.l. - Toniolo Marco * @version 1.2 * @since 2015-05-26 * @uses : jQuery > 1.7 * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * * X - X - X - X - X - X - X - X - X - X - X - X - X - X - X * !!! IMPORTANT !!! * this script MUST be inserted at the bottom of the page * before the closing tag ! * X - X - X - X - X - X - X - X - X - X - X - X - X - X - X * * * @changelog * 1.0 -> 1.2 * - added multilangual support, * - the lang setted into data-lang attr is used as pre-selector * - moved url to attribute * - moved css to attribute * * */ var IEDBG = false ; var ERR = false ; (function(window){ this.TSMPRV = { debug : false , data : false , xdr : false , url : "https://secure.tosom.it/widgets/privacy/" , css : "https://secure.tosom.it/widgets/privacy/style.css" , trace : function(m){ if(typeof window.console!="undefined"){ if( this.debug && typeof window.console != "undefiend" ){window.console.log(m) ;} } }, error : function(m){ if(typeof window.console!="undefined"){ if( this.debug && typeof window.console != "undefiend" ){window.console.error(m) ;} } }, info : function(m){ if(typeof window.console!="undefined"){ if( this.debug && typeof window.console != "undefiend" ){window.console.info(m) ;} } }, init:function(){ if(this.debug){ console.log("TSMELEMS:: Company Data Init"); } var tmp = false ; var box = false ; var w = h = 0 ; // Set the "data" object to store what's needed this.data = { links : false , JQ : "not-checked" , privacyLoaded : false , privacyText : "" , privacyOverlayID : false , privacyContentID : false , privacyTriggerCloseID : false } ; // LOOK FOR JQUERY AND IT's VERSION if( typeof jQuery == "undefined" ) { this.info("TOSOM PRIVACY: no jquery found on the page. Trying to add jquery to the page."); this.loadJQ(); return ; // WAIT FOR JQUERY TO LOAD UP } else { TSMPRV.data.JQ = "ok" ; } // LOOK FOR "privacy link" this.data.links = jQuery(".tsm-privacy") ; this.data.privacyOverlayID = "TSMPRV-PRIVACY-OVERLAY" ; this.data.privacyContentID = "TSMPRV-PRIVACY-CONTENT" ; this.data.privacyTriggerCloseID = "TSMPRV-PRIVACY-T-CLOSE" ; // START PRIVACY ROUTINES if( this.data.links.length > 0 ) { // ADD THE FONT tmp = document.createElement( "link" ) ; tmp.setAttribute( "rel" , "stylesheet") ; tmp.setAttribute( "type" , "text/css") ; tmp.setAttribute( "href" , "https://fonts.googleapis.com/css?family=Open+Sans") ; tmp.setAttribute( "media" , "all") ; jQuery("body").append( tmp ) ; tmp = false ; // ADD THE STYLES tmp = document.createElement( "link" ) ; tmp.setAttribute( "rel" , "stylesheet") ; tmp.setAttribute( "type" , "text/css") ; tmp.setAttribute( "href" , TSMPRV.css ) ; tmp.setAttribute( "media" , "all") ; jQuery("body").append( tmp ) ; tmp = false ; // CREATE THE OVERLAY tmp = document.createElement( "div" ) ; tmp.setAttribute( "style" , "width:1px;height:1px;" ) ; tmp.setAttribute( "id" , this.data.privacyOverlayID ) ; jQuery("body").append( tmp ) ; tmp = false ; // CREATE THE INNER BOX tmp = document.createElement( "div" ) ; tmp.setAttribute( "style" , "width:1px;height:1px;" ) ; tmp.setAttribute( "id" , this.data.privacyContentID ) ; jQuery("body").append( tmp ) ; tmp = false ; //CLEAN TMP // CREATE THE "X" CLOSING BUTTON tmp = document.createElement( "div" ) ; //tmp.setAttribute( "style" , "position:fixed;display:none;width:1px;height:1px;" ) ; tmp.setAttribute( "id" , this.data.privacyTriggerCloseID ) ; tmp.innerHTML = "×" ; jQuery("body").append( tmp ) ; // XXX JUST FOR TEST AND DEBUGGING IF NEEDED XXX // Enable a listener to check when the needed components are loaded // this.listener_pageAddNodes(); // ADDITIONAL STYLES THAT ONLY JS CAN HANDLE // ------------------------------------------------------------------ jQuery("#"+this.data.privacyOverlayID).css({opacity:0,display:"none"}); // Get the content Size tmp = this.fixContentSize(); jQuery("#"+this.data.privacyContentID).css({ width : tmp.w , height : tmp.h , marginLeft: tmp.l }) ; jQuery("#"+this.data.privacyTriggerCloseID ).css({ marginRight : tmp.x }); // ------------------------------------------------------------------ // APPLY OPEN EVENT TO ALL THE LINKS for( var tpi=0 ; tpi 200 ( 25*150 ) => 3.75 sec max wait time ! if( i>25 ) { TSMPRV.error("\n" +"+-------------------------------------------+\n" +"| TOSOM PRIVACY: Jquery loading error. |\n" +"| Privacy policy cannot load in the page. |\n" +"| Sorry, giving up. |\n" +"+-------------------------------------------+\n" ) ; return; } if( TSMPRV.data.JQ!="ok" ) // JQUERY ARE NOT OK { //TSMPRV.trace(" !ok ") ; if( TSMPRV.data.JQ == "loading" ) { //TSMPRV.trace(" LOADING ") ; if( typeof jQuery == "undefined" ) { //TSMPRV.trace(" LISTEN ") ; window.setTimeout( function(){ TSMPRV.loadJQ(++i) } , 150 ) ; } else { //TSMPRV.trace("TOSOM PRIVACY: jQuery loaded succesfully") ; // TSMPRV.trace(" DONE ") ; TSMPRV.data.JQ = "ok" ; jQuery.noConflict(); // RESTART TSMPRV.init(); } } else { //TSMPRV.trace("TOSOM PRIVACY: jQuery loading") ; tmp = document.createElement("script") ; tmp.setAttribute("type","text/javascript"); tmp.setAttribute("src","https://secure.bookingevolution.com/web/jquery/1.11.1/jquery-min.js"); document.body.appendChild(tmp) ; TSMPRV.data.JQ = "loading" ; window.setTimeout( function(){ TSMPRV.loadJQ(++i) } , 150 ) ; } } }, // XXX USED JUST FOR DEBUG XXX /*listener_pageAddNodes : function(i) { var u = jQuery("#"+TSMPRV.data.privacyOverlayID) ; var n = jQuery("#"+TSMPRV.data.privacyContentID) ; var o = jQuery("#"+TSMPRV.data.privacyTriggerCloseID) ; if(typeof i=="undefined"){i=0;} TSMPRV.trace("YAWEEEEEE "+i) ; if( !u.length || !n.length || !o.length ) { window.setTimeout( function(){ TSMPRV.listener_pageAddNodes(++i) ; } , 200 ) } },*/ fixContentSize : function() { var w=wt=h=ht=p1=p2=x=l=0 ; //var tmp = false ; //w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth ; //h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight ; w = jQuery(window).width() ; h = jQuery(window).height() ; w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth ; h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight ; // WIDTH CALCULATIONS wt = 750 ; if( w < 750 ) { wt = w-40 ; } // GET TRIGGER-CLOSE MARGIN //x = Math.ceil( (w-wt)/2 )+34; x = -1*( Math.floor( (wt)/2 )-10 ); //if( window.innerWidth<500 ) // According to media query max-width //{ x = -1*( Math.floor( (wt)/2 )); } // HEIGHT CALCULATIONS ht = h-60 ; //console.log(h+" / "+( window.innerHeight )+" => "+ht) // GET CONTENT LEFT MARGIN l = ( Math.ceil( w/2 ) - Math.ceil( wt/2 ) ) ; return {w:wt,h:ht,x:x,l:l} }, handlePrivacy : function(elem) { console.log("HANDLE") var lang = "" ; // GET LANG IF DEFINED if( typeof elem !="undefined" && elem ) { lang = elem.getAttribute("data-lang") ; if(!lang) { lang="" ;} } // CLEAN PREVIOUS DATA this.data.privacyLoaded = false ; this.data.privacyText = "" ; //this.trace(">>>>>>>>>>>>>>>>>>>>>>>>>>> "+lang); //this.trace("p load"); IEDBG = false ; // LOAD PRIVACY TEXT var ie9mode = false ; var tmp = false ; var tmp2 = false ; var UA = navigator.userAgent ; if( UA.match(/msie/i) ) { // GOT YOU IE !!! tmp = UA.split(";") ; for( var k=0 ; k ERROR!! { this.error("TOSOM PRIVACY: box count error"); return; } if( boxCont.length!=1 ) // BOX COUNT -> ERROR!! { this.error("TOSOM PRIVACY: box content count error"); return; } boxCont.html( this.data.privacyText ) ; // Bind lang triggers jQuery("#TSMPRV-PRIVACY-CONTENT ul#tsmprv-langsel li").click(function(){ var elem = jQuery(this) ; var lang = elem.attr("data-lang") ; // REMOVE SEL FROM ALL THE TEXTS AND MENu jQuery( "#TSMPRV-PRIVACY-CONTENT .tsmprv-text" ).removeClass("sel") ; jQuery("#TSMPRV-PRIVACY-CONTENT ul#tsmprv-langsel li").removeClass("sel") ; // Select current link/lang jQuery( "#TSMPRV-PRIVACY-CONTENT .tsmprv-text."+lang ).addClass("sel") ; elem.addClass("sel") ; }) box.css({display:"block",width:"100%",height:"100%"}); box.stop().animate({opacity:1},200); boxCont.css({display:"block"}); boxCont.stop().animate({opacity:1},200,function(){ tClose.css({display:"block"}) }); }, hidePrivacy : function() { //this.trace("TOSOM PRIVACY: hide"); var box = jQuery("#"+this.data.privacyOverlayID) ; var boxCont = jQuery("#"+this.data.privacyContentID) ; var tClose = jQuery("#"+this.data.privacyTriggerCloseID) ; box.stop().animate({opacity:0},200,function(){ box.css({display:"none"}) } ); boxCont.stop().animate({opacity:0},200,function(){ boxCont.css({display:"none"}) } ); tClose.css({display:"none"}) } } window.setTimeout( function(){TSMPRV.init();} , 500 ) ; })(window);