//IE polyfills window.isIE=(window.navigator.userAgent.match('/MSIE|Trident/')!==null); if(typeof NodeList.prototype.forEach=='undefined') { NodeList.prototype.forEach = function (callback) { for(var i=0;i0) type=kentIco2Class[elt.innerHTML.trim()[0]+(elt.classList.contains('font2')?'2':(elt.classList.contains('font3')?'3':''))]; if(type==undefined || type=='') return false; file='/kent-ico/defs.svg'; if(isIE) { // IE not working if(document.querySelector('#svgDefs')===null) { $.ajax({ async:false, url:file, dataType:'html', processData:false, success:function (data) { $('head').append(data); } }); } file=''; } elt.innerHTML='' elt.classList.add('kent-ico-loaded'); if(!elt.classList.contains('kent-ico-'+type)) elt.classList.add('kent-ico-'+type); } } function changeIcon(elt,nVal,oVal) { /* elt: Element to change nVal : new icon name oVal : (optional) if defined, changed oVal for nVal or nVal for oVal, allowing to toggle between 2 icons */ if(!elt.matches('.kent-ico')) return false; //delete kent-ico from name if(!nVal.indexOf('kent-ico-')==0) nVal='kent-ico-'+nVal; if(oVal==undefined) { for(var i=elt.classList.length-1;i>=0;i--) if(elt.classList.item(i).indexOf('kent-ico-')==0) elt.classList.remove(elt.classList.item(i)); } else { if(!oVal.indexOf('kent-ico-')==0) oVal='kent-ico-'+oVal; if(!elt.classList.contains(oVal) && elt.classList.contains(nVal)) { var temp=nVal; nVal=oVal; oVal=temp; } elt.classList.remove(oVal); elt.classList.remove('kent-ico-loaded'); elt.classList.add(nVal); } elt.classList.add(nVal); transformIcon(elt); } window.addEventListener('load',function () { if(typeof jQuery !=='undefined') { $.fn.changeIcon = function (nVal,oVal) { return $(this).each(function () { changeIcon($(this)[0],nVal,oVal); }); } }; }); function watchDom() { //used to change icons to SVG function watchDOMChange(mutationList) { mutationList.forEach(function (mutation) { if(mutation.type=='childList') { mutation.addedNodes.forEach(function (elt) { if('#text,#comment,#document,#document-fragment'.split(',').indexOf(elt.nodeName)>=0 || elt.classList==undefined) return true; if(elt.classList.contains('kent-ico')) {transformIcon(elt);} elt.querySelectorAll('.kent-ico').forEach(transformIcon); }); } }); } var observer=new MutationObserver(watchDOMChange); observer.observe(document,{attributes:false,childList:true,subtree:true}); } //end WatchDOM //kent-ico font 2 svg conversion table var kentIco2Class=Array (); kentIco2Class['A']='home'; kentIco2Class['B']='talk'; kentIco2Class['C']='user'; kentIco2Class['D']='gear'; kentIco2Class['E']='help'; kentIco2Class['F']='email'; kentIco2Class['H']='ext'; kentIco2Class['L']='list-extended'; kentIco2Class['M']='list-diapo'; kentIco2Class['X']='star'; kentIco2Class['r']='download'; kentIco2Class['s']='search'; kentIco2Class['t']='trash'; kentIco2Class['u']='share'; kentIco2Class['w']='rss'; kentIco2Class['x']='print'; kentIco2Class['8']='lock'; kentIco2Class['9']='unlock'; kentIco2Class['Q2']='list-index'; kentIco2Class['U2']='burger'; kentIco2Class['g2']='visio'; kentIco2Class['j2']='filter'; kentIco2Class['i2']='upload'; kentIco2Class['p2']='stamp'; kentIco2Class['w2']='pen-off'; kentIco2Class['72']='info'; kentIco2Class['L2']='pen'; kentIco2Class['A3']='user'; kentIco2Class['B3']='user'; kentIco2Class['L3']='bullets'; watchDom(); function Newwindow(pageurl,namewin,param) { try { window.open(pageurl,namewin,param); } catch (err) { if(confirm("Impossible d'ouvrir la popup dans ce navigateur. Voulez-vous l'ouvrir à la place de la fenêtre principale ? Notez que si vous demandez à fermer cette popup, vous fermerez l'onglet courant.")) window.location=pageurl; } } // declare custom elements : type is array of elements to declare (knote), win is window where to declare them (iframe.contentWindow, for example) function kCustomElementsDeclare(type,win) { //using .top to check if instanceof Window, as it doesn't work on children windows (at least iframe Windows) if(type!==undefined && type.top instanceof Window) { win=type; type=undefined; } if(win===undefined || !(win.top instanceof Window)) win=window; if(type===undefined) type=['knote']; //all existing customElements else if(typeof type==='string') type=[type]; type=type.map(a=>a.toLowerCase()); //make type case-insensitive if(type.includes('knote')) { class KNote extends win.HTMLElement { constructor() { super(); const shadow=this.attachShadow({mode:'open'}); const counter=this.ownerDocument.createElement('span'); counter.setAttribute('class','counter'); counter.setAttribute('part','counter'); const note=this.ownerDocument.createElement('span'); note.setAttribute('class','text hide'); note.setAttribute('part','text'); const style=this.ownerDocument.createElement('style'); style.textContent=` :host {position:relative;} .counter {cursor:pointer;} .text {position:absolute;z-index:1;} .text.hide {display:none;} .text.right {right:100%;} `; shadow.appendChild(style); shadow.appendChild(counter); shadow.appendChild(note); } connectedCallback() { const This=this; setTimeout(function () { This.shadowRoot.querySelector('span:last-child').innerHTML=This.innerHTML; //This.innerHTML=''; let i=1; const format=This.getAttribute('format'); This.ownerDocument.querySelectorAll('k-note').forEach(elt=>{ if(elt.getAttribute('format')===format) {//only if same format if (format===null) elt.shadowRoot.querySelector('.counter').innerHTML=i++; else elt.shadowRoot.querySelector('.counter').innerHTML=format.replace(/\d+/,i++); } }); },0); This.shadowRoot.querySelector('.counter').addEventListener('click',function (e) { this.nextSibling.classList.toggle('hide'); //calculate size and position for current window size const ref=this.dataset.winSize; if(ref!=window.innerWidth && !this.nextSibling.matches('.hide')) { const rootPos=This.getBoundingClientRect(); this.nextSibling.style.width='auto'; this.nextSibling.classList.remove('right'); let pos=this.nextSibling.getBoundingClientRect(); //check height for one-liner const styles=getComputedStyle(this.nextSibling); const oneLineHeight=parseInt(styles.lineHeight)+parseInt(styles.paddingTop)+parseInt(styles.paddingBottom)+parseInt(styles.borderTopWidth)+parseInt(styles.borderBottomWidth); while (pos.width<(4*pos.height) && pos.width<(2*window.innerWidth/3) && pos.height>oneLineHeight) { this.nextSibling.style.width=Math.floor(pos.width+20)+'px' pos=this.nextSibling.getBoundingClientRect(); if(pos.left+pos.width>window.innerWidth && pos.left>(window.innerWidth-pos.left-rootPos.width)) //if out of window and more space on the left this.nextSibling.classList.add('right'); } this.dataset.winSize=window.innerWidth; } }); } } win.customElements.define('k-note',KNote); } } kCustomElementsDeclare();