/* * markerStats v1.1 jQuery * * USAGE : * utiliser "isensStats.watchLinks();" pour mettre à jour l'écoute des liens. * * */ var options = { version: 1, page: 'Erreur', debug: false }; var markerStats = function(options) { $.extend(options); // variable stats this.stats = { version: options.version, page: options.page, lang: (navigator.systemLanguage) ? navigator.systemLanguage : navigator.language, ref: encodeURIComponent(document.referrer) }; var params = this.returnParams(this.stats); $.get( "/isens_marker.php"+params ); this.watchLinks(); }; markerStats.prototype.watchLinks = function() { $(document.body).find('a').each(function(index, link) { if( $(link).data('watched') ) return; var href = $(link)[0].href; var domain = document.location.host; var file = href.split('/')[href.split('/').length-1]; var ext = ( file.split('.').length > 1 ) ? file.split('.')[file.split('.').length-1] : null; // files if( (ext && ext.length<5) || (!href.match('javascript') && !href.match(domain)) ) { $(link).on('mousedown', function(event) { var params = this.returnParams(this.stats); var t = new Date().getTime(); var _href = ( href.split('mailto:').length > 1 ) ? href.split('mailto:')[1] : href; params += '&externe=1&page='+encodeURIComponent(_href)+'&time='+t; $.get( "/isens_marker.php"+params ); }.bind(this)); $(link).on('keydown', function(event) { if(event && event.key == 'enter ') $(link).trigger('mousedown'); }.bind(this)); } if( options.debug ) { $(link).on({ 'mouseenter': function() { // if lien contient javascript if( href.match('javascript') ) { console.log('script'); } // if lien externe else if(! href.match(domain) ) { console.log('external'); } // if fichier téléchargeable else if( ext && ext.length < 5 ) { console.log('file'); } // sinon else { console.log('internal'); } } }); } $(link).data("watched", true); }.bind(this)); }; markerStats.prototype.returnParams = function(stats) { var params = ''; var i = 0; $.each(stats, function(key, value) { if( i > 0 ) { params += '&'; } else { params += '?'; } params += key + '=' + value; i++; }); params += '&screen=' + screen.width + 'x' + screen.height + 'x' + screen.colorDepth; return params; }; // variable globale isensStats var isensStats; jQuery(document).ready(function() { isensStats = new markerStats({ version: '2', page: 'Accueil' }); });