Skip to content

Instantly share code, notes, and snippets.

@valdo404
Created April 22, 2021 17:33
Show Gist options
  • Save valdo404/54a8cc5f9dcf18b64ee7af202b7055c2 to your computer and use it in GitHub Desktop.
Save valdo404/54a8cc5f9dcf18b64ee7af202b7055c2 to your computer and use it in GitHub Desktop.
/* =SENAT_ALIREAUSSI
----------------------------------------------------------------------------- */
var senat_alireaussi = {
url: "/themes/xml/alireaussi.xml",
mainSelector: "#box-documents .box-inner",
topSelector: "#box-documents",
list1: ".box .box-inner .list-documents:eq(0)",
list2: ".box .box-inner .list-documents:eq(1)",
territorySelector: ".box-docs-territory",
reportSelector: ".box-docs-reports",
themes: [],
templates: {
blocTerritoires: "<!-- START : box -->" +
"<div class='box box-type-03 box-docs-territory' id='box-documents'>" +
"<div class='box-top'><div><!----></div></div>" +
"<div class='box-inner'>" +
"<div class='border'>" +
"<div class='inner'>" +
"<h3 class='title title-02'>A lire ou &agrave; voir sur ce sujet</h3>" +
"<div class='link link-type-02'>" +
"<a href='{{theme}}'>Tous les documents sur ce sujet</a>" +
"</div>" +
"</div>" +
"</div>" +
"</div>" +
"<div class='box-btm'><div><!----></div></div>" +
"</div>" +
"<!-- END : box -->",
blocRapports: "<!-- START : box -->" +
"<div class='box box-type-02 box-docs-reports'>" +
"<div class='box-top'><div><!----></div></div>" +
"<div class='box-inner gradient-01'>" +
"<h3 class='title title-02'>A lire aussi</h3>" +
"</div>" +
"<div class='box-btm'><div><!----></div>" +
"</div>" +
"</div>" +
"<!-- END : box -->",
item: "<li> <img src='{{picto}}' alt=''><strong>{{date}} :</strong><a href='{{url}}'>{{title}}</a></li>",
list1: '<ul class="list-documents list-documents-02"></ul>',
list2: '<ul class="list-documents list-documents-02"></ul>',
listTer: '<ul class="list-documents list-documents-01"></ul>'
},
months: ['Janvier', 'F&eacute;vrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Ao&ucirc;t', 'Septembre', 'Octobre', 'Novembre', 'D&eacute;cembre'],
pictos: [{
from: '/images/picto_txt.gif',
to: '/fileadmin/templates/images/data/picto_document.png'
}, //{from:'',to:'/fileadmin/templates/images/data/picto_video.png'},
{
from: '/images/picto_rap.gif',
to: '/fileadmin/templates/images/data/picto_report.png'
}
],
//{from:'',to:'/fileadmin/templates/images/data/picto_video.png'},
//{from:'',to:'/fileadmin/templates/images/data/picto_question.png'},
//{from:'',to:'/fileadmin/templates/images/data/picto_folder.png'},
//{from:'',to:'/fileadmin/templates/images/data/picto_record.png'}
//SETUP
setup: function() {
$(this.list1).empty();
$(this.list2).empty();
$.ajax({
type: "GET",
url: senat_alireaussi.url,
dataType: "xml",
cache: true,
success: function(xml) {
var selector = '';
var nodes = Array();
var parsedNodes = Array();
var themes = Array();
for (var i = 0; i < senat_alireaussi.themes.length; i++) {
selector = "theme[id='" + senat_alireaussi.themes[i] + "']";
themes = jQuery(selector, xml);
for (var j = 0; j < themes.length; j++) {
themeNodes = jQuery("doc", themes[j])
for (k = 0; k < themeNodes.length; k++)
nodes.push(themeNodes[k]);
}
}
for (var i = 0; i < nodes.length; i++) {
var url = $("lien", nodes[i]).text();
var urlArray = parseUri(url);
var relativeUrl = urlArray.relative;
var picto = $("picto", nodes[i]).text();
var pictoArray = parseUri(picto);
var relativePicto = pictoArray.relative;
//var targetPicto = relativePicto;
var targetPicto = picto;
for (var j = 0; j < senat_alireaussi.pictos.length; j++) {
if (typeof (senat_alireaussi.pictos[j].from) != 'undefined' && senat_alireaussi.pictos[j].from == relativePicto) {
targetPicto = senat_alireaussi.pictos[j].to;
break;
}
}
var dateStr = $("date", nodes[i]).text();
var dateArray = dateStr.split('/');
var date = new Date();
date.setFullYear(dateArray[2]);
date.setMonth(dateArray[1] - 1);
date.setDate(dateArray[0]);
var formattedDate = date.getDate() + ' ' + senat_alireaussi.months[date.getMonth()].toLowerCase() + ' ' + date.getFullYear();
var title = $("titre", nodes[i]).text();
parsedNodes.push({
'url': url,
'picto': targetPicto,
'title': title,
'formattedDate': formattedDate,
'date': date
});
}
sortedNodes = parsedNodes.sort(parsedNodesSort);
if (sortedNodes.length > 0) {
if (jQuery(senat_alireaussi.territorySelector).length > 0) {
jQuery(senat_alireaussi.territorySelector).replaceWith($.tempest(senat_alireaussi.templates.blocTerritoires, {
theme: "/themes/tg1.html"
}));
jQuery(senat_alireaussi.territorySelector + ' .inner h3').after($.tempest(senat_alireaussi.templates.listTer, {}));
}
if (jQuery(senat_alireaussi.reportSelector).length > 0 && jQuery(senat_alireaussi.territorySelector).length == 0) {
jQuery(senat_alireaussi.reportSelector).replaceWith($.tempest(senat_alireaussi.templates.blocRapports, {}));
jQuery(senat_alireaussi.reportSelector + ' .box-inner h3').after($.tempest(senat_alireaussi.templates.list1, {}));
jQuery(senat_alireaussi.reportSelector + ' .box-inner h3').after($.tempest(senat_alireaussi.templates.list2, {}));
}
}
for (var i = 0;(i < 6 && sortedNodes.length != 0); i++) {
if (i < 3)
jQuery(senat_alireaussi.list1).append($.tempest(senat_alireaussi.templates.item, {
date: sortedNodes[i].formattedDate,
url: sortedNodes[i].url,
title: sortedNodes[i].title,
picto: sortedNodes[i].picto
}));
else
jQuery(senat_alireaussi.list2).append($.tempest(senat_alireaussi.templates.item, {
date: sortedNodes[i].formattedDate,
url: sortedNodes[i].url,
title: sortedNodes[i].title,
picto: sortedNodes[i].picto
}));
}
if (sortedNodes.length > 0) {
jQuery(senat_alireaussi.topSelector).show();
jQuery(senat_alireaussi.mainSelector).show();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
log(errorThrown);
}
});
}
};
function afficher_alire_aussi(themesDesc) {
$(document).ready(function() {
senat_alireaussi.themes = themesDesc.split(',');
senat_alireaussi.setup();
});
}
/* =SENAT_MONSENAT
----------------------------------------------------------------------------- */
function trim(str)
{
while ('' + str.charAt(0) == ' ') {
str = str.substring(1, str.length);
}
while ('' + str.charAt(str.length - 1) == ' ') {
str = str.substring(0, str.length - 1);
}
return str;
}
var senat_monsenat = {
ajaxUrl: '/ajax.php',
linkSelector: "#addMySenate",
addSelector: "#addMySenate",
titleSelectors: ["#primary h1.title-dosleg",
"div.title h1",
"div.title h2",
"#primary .content p:eq(0)",
"#primary #wysiwyg h1.titrelong",
"#primary #wysiwyg h1.titrelong",
"#main h1",
"#primary #wysiwyg .csc-default h1",
"#page #breadcrumb span",
"head title"],
pictureSelector: "#primary .content .media object param[name='flashvars']",
durationSelector: "#secondary p:eq(0)",
dateSelector: "#secondary p:eq(1)",
typeSelector: "#primary .content h3.title",
removeSelector: ".box-mycontent .list-disc .link-delete,.box-mycontent .list-picture .link-delete",
removeLiSelector: ".box-mycontent",
linkSetup: function() {
$(senat_monsenat.linkSelector).click(function() {
//titre
var title = jQuery(senat_monsenat.titleSelectors[0]);
for (var i = 1; i < senat_monsenat.titleSelectors.length; i++) {
var title = title.add(senat_monsenat.titleSelectors[i]);
}
var titleString = "";
if (title.length > 0) {
titleString = titleString + trim(jQuery(title[0]).text()) + " ";
}
/*for(var i=0;i<title[0].childNodes.length;i++) {
//console.log(i);
//console.log(title[0].childNodes.length);
console.log(title[0].childNodes[i].innerHTML);
if(title[0].childNodes[i].nodeName=="#text") {
titleString += title[0].childNodes[i].textContent + " ";
//console.log(titleString);
//console.log(title[0].childNodes[i].textContent);
//titleString = titleString + title[0].childNodes[i].textContent.trim() + " ";
}
}*/
var duration = jQuery(senat_monsenat.durationSelector);
var durationString = "";
if (duration.length > 0) {
for (var i = 0; i < duration[0].childNodes.length; i++) {
if (duration[0].childNodes[i].nodeName == "#text") {
durationString += duration[0].childNodes[i].textContent.trim() + " ";
}
}
}
var date = jQuery(senat_monsenat.dateSelector);
var dateString = "";
if (date.length > 0) {
for (var i = 0; i < date[0].childNodes.length; i++) {
if (date[0].childNodes[i].nodeName == "#text") {
dateString += date[0].childNodes[i].textContent.trim() + " ";
}
}
}
var type = jQuery(senat_monsenat.typeSelector);
var typeString = "";
if (type.length > 0) {
for (var i = 0; i < type[0].childNodes.length; i++) {
if (type[0].childNodes[i].nodeName == "#text") {
typeString += type[0].childNodes[i].textContent.trim() + " ";
}
}
}
var picture = jQuery(senat_monsenat.pictureSelector);
if (picture.length > 0) {
var pictureString = picture.attr("value").match(/&image=(.*)&/)[1];
}
//url
var url = jQuery(this).attr('href') +
'add.php?' + // 'url='+encodeURIComponent(window.location)+
'url=' + encodeURIComponent(window.location) + // '&title='+encodeURIComponent(titleString).trim()+
'&title=' + trim(encodeURIComponent(titleString)) + // '&date='+encodeURIComponent(dateString).trim()+
'&date=' + trim(encodeURIComponent(dateString)) + // '&duration='+encodeURIComponent(durationString).trim()+
'&duration=' + trim(encodeURIComponent(durationString)) + // '&type_label='+encodeURIComponent(typeString).trim()+
'&type_label=' + trim(encodeURIComponent(typeString)) + // '&picture='+encodeURIComponent(pictureString).trim();
'&picture=' + trim(encodeURIComponent(pictureString));
jQuery(this).attr('href', url);
jQuery(this).attr('target', '_blank');
return true;
});
},
removeSetup: function() {
$(senat_monsenat.removeSelector).click(function() {
//appel AJAX
var box = jQuery(this).parents("div.box")[0];
var line = jQuery(this).parents("li")[0];
var url = jQuery(this).parent().find("a:eq(0)").attr('href');
var boxId = box.id;
var lineId = /line-([0-9]*)/.exec(line.id)[1];
var firstBox = jQuery("div#" + boxId).parent().find(".box:eq(0)");
var firstBoxId = firstBox[0].id;
if (window.confirm('Souhaitez-vous supprimer ce favori ?')) {
$.ajax({
type: "GET",
url: senat_monsenat.ajaxUrl,
dataType: "json",
cache: true,
data: {
'action': 'delete',
'id': lineId,
'box': boxId,
'url': url
},
success: function(data) {
if (data.result == 'OK') {
jQuery("div#" + boxId + " li#line-" + lineId).remove();
if (typeof (data.removeBox) !== 'undefined' && data.removeBox == true) {
jQuery("div#" + boxId + ' .content').html(data.nothingLabel);
}
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
}
});
}
return false;
});
},
addSetup: function() {
$(senat_monsenat.addSelector).click(function() {
});
}
};
/* =SENAT_MONSENAT
----------------------------------------------------------------------------- */
var senat_social = {
linkSelector: ".list-bookmark-01 li a, ul.first li a[href*='mailto']",
titleSelector: "title",
linkSetup: function() {
$(senat_social.linkSelector).each(function() {
var title = jQuery(senat_social.titleSelector);
var titleString = "";
if (title.length > 0) {
for (var i = 0; i < title[0].childNodes.length; i++) {
if (title[0].childNodes[i].nodeName == "#text") {
titleString += title[0].childNodes[i].textContent.trim() + " ";
}
}
}
var url = encodeURIComponent(window.location);
var title = encodeURIComponent(titleString);
var targetUrl = jQuery(this).attr('href')
if (targetUrl.match(/mailto:/)) {
jQuery(this).attr('href', targetUrl.replace(/(subject=)&(body=)/, "$1" + title + "&$2" + url));
} else if (targetUrl.match(/facebook/)) {
jQuery(this).attr('href', targetUrl.replace(/(u=)&(t=)/, "$1" + url + "&$2" + title));
} else if (targetUrl.match(/twitter/)) {
jQuery(this).attr('href', targetUrl.replace(/(status=)/, "$1" + url));
} else if (targetUrl.match(/delicious/)) {
jQuery(this).attr('href', targetUrl.replace(/(url=)&(title=)/, "$1" + url + "&$2" + title));
} else if (targetUrl.match(/wikio/)) {
jQuery(this).attr('href', targetUrl.replace(/(url=)&(title=)/, "$1" + url + "&$2" + title));
} else if (targetUrl.match(/viadeo/)) {
jQuery(this).attr('href', targetUrl.replace(/(url=)&(title=)/, "$1" + url + "&$2" + title));
} else if (targetUrl.match(/linkedin/)) {
jQuery(this).attr('href', targetUrl.replace(/(url=)&(title=)/, "$1" + url + "&$2" + title));
} else if (targetUrl.match(/plus.google/)) {
jQuery(this).attr('href', targetUrl.replace(/(url=)/, "$1" + url));
}
jQuery(this).attr('target', '_blank');
jQuery("#liens_partage.options-01").attr('style', '');
jQuery("#presse_partage").attr('style', ''); /*GJ20120829-RT17507*/
return true;
});
}
};
var senat_mobile = {
detect: function() {
if (navigator.userAgent.match(/Android/i) && !navigator.userAgent.match(/Mobile/i))
return false;
else
return DetectSmartphone();
},
setup: function() {
if (senat_mobile.detect()) {
if ((window.location.pathname == "/") || (window.location.pathname == "/index.html")) {
jQuery("body").prepend(
"<div id='smartphoneAd'>" +
"Visitez notre site optimis&eacute;<BR>pour les t&eacute;l&eacute;phones mobiles<BR>" +
"<a href='http://m.senat.fr'>m.senat.fr</a>" +
"</div>");
}
}
}
};
/* =IE6_MAXWIDTH
----------------------------------------------------------------------------- */
function IE6_MaxWidth() {
if (jQuery.browser.msie && jQuery.browser.version < 7 && jQuery('#primary')[0]) {
jQuery('#layout.type-02 #primary img').each(function() {
if (this.clientWidth > 770) {
this.style.width = '770px';
}
});
jQuery('#layout.type-02 #primary .main-size-01 img').each(function() {
if (this.clientWidth > 580) {
this.style.width = '580px';
}
});
jQuery('#layout.type-02 #primary .box img').each(function() {
if (this.clientWidth > 738) {
this.style.width = '738px';
}
});
}
}
/* =INPUTLABEL
----------------------------------------------------------------------------- */
function inputLabel() {
var inputs = jQuery('.inside-label');
var setField = function(current) {
if (current.title != '') {
var title = current.title;
}
else if (current.title == ''
&& current.parentNode.getElementsByTagName('kbd')[0]) {
var title = current.parentNode.getElementsByTagName('kbd')[0].innerHTML;
}
current.value = title;
current.state = 0;
};
var init = function() {
inputs.each(function() {
jQuery(this).keypress(function() {
this.state = 1;
});
jQuery(this).focus(function() {
if (this.state != 1) {
this.value = '';
}
});
jQuery(this).blur(function() {
if (this.state == 0 || this.value == '') {
setField(this);
}
});
setField(this);
});
}();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment