Commit 3ba03eb1 authored by Patrick Barroca's avatar Patrick Barroca 🐧

Merge branch 'hotline#89508_babeltheque' into 'hotline'

hotline #89508 : call babelio in HTTPS

See merge request afi/opacce!3140
parents c4856400 bc359166
- ticket #89508 : Babelthèque : compatibilité HTTPS
\ No newline at end of file
(function() { (function() {
var getJSQueryString = function(script) { var getJSQueryString = function(script) {
var var
scripts = document.getElementsByTagName('script'), scripts = document.getElementsByTagName('script'),
i, i,
curScript; curScript;
for (i = 0; i < scripts.length; ++i) { for (i = 0; i < scripts.length; ++i) {
curScript = scripts[i]; curScript = scripts[i];
if (curScript.src.match(script)) { if (curScript.src.match(script)) {
return (curScript.src.match(/\?(.*)/) || [undefined])[1]; return (curScript.src.match(/\?(.*)/) || [undefined])[1];
} }
} }
} }
var getJSParams = function(script) { var getJSParams = function(script) {
var var
qs = getJSQueryString(script), qs = getJSQueryString(script),
search = /([^&=]+)=?([^&]*)/g, search = /([^&=]+)=?([^&]*)/g,
urlParams = {}; urlParams = {};
while (match = search.exec(qs)) while (match = search.exec(qs))
urlParams[match[1]] = match[2]; urlParams[match[1]] = match[2];
return urlParams; return urlParams;
} }
var getJSParamNamed = function (script, name) { var getJSParamNamed = function (script, name) {
return getJSParams(script)[name]; return getJSParams(script)[name];
} }
var bwid = getJSParamNamed('babeltheque.js', 'bwid'); var bwid = getJSParamNamed('babeltheque.js', 'bwid');
window.loadBabelthequeScript = function(isbn) { window.loadBabelthequeScript = function(isbn) {
insertBabelthequeISBNTag(isbn); insertBabelthequeISBNTag(isbn);
$.getScript('http://www.babeltheque.com/bw_' + bwid +'.js'); $.getScript('https://www.babelio.com/bw_' + bwid +'.js');
} }
})(); })();
$.fn.babelthequeTag=function(info) { $.fn.babelthequeTag=function(info) {
return this.each(function() { return this.each(function() {
$(this).append('<div id="BW_'+info+'"></div>'); $(this).append('<div id="BW_'+info+'"></div>');
}); });
} }
var insertBabelthequeISBNTag = function(isbn) { var insertBabelthequeISBNTag = function(isbn) {
if (!$('input#BW_id_isbn').length) if (!$('input#BW_id_isbn').length)
$('body').append('<input type="hidden" id="BW_id_isbn" value="'+isbn+'"\>'); $('body').append('<input type="hidden" id="BW_id_isbn" value="'+isbn+'"\>');
} }
var blocNoticeAfterLoad = function (info, isbn, target) { var blocNoticeAfterLoad = function (info, isbn, target) {
if ("" == isbn) if ("" == isbn)
return; return;
var callback = $(window).attr(info + 'NoticeAfterLoad'); var callback = $(window).attr(info + 'NoticeAfterLoad');
if (undefined == callback) if (undefined == callback)
return; return;
callback(target); callback(target);
loadBabelthequeScript(isbn); loadBabelthequeScript(isbn);
} }
var tagsNoticeAfterLoad = function(target) { var tagsNoticeAfterLoad = function(target) {
target.prepend('<div id="BW_etiquettes"></div>'); target.prepend('<div id="BW_etiquettes"></div>');
} }
var avisNoticeAfterLoad = function(target) { var avisNoticeAfterLoad = function(target) {
var tr_critiques = target.find('table tr:nth-child(2)'); var tr_critiques = target.find('table tr:nth-child(2)');
if (!tr_critiques.find('ul').length) if (!tr_critiques.find('ul').length)
$('<ul></ul>').appendTo(tr_critiques); $('<ul></ul>').appendTo(tr_critiques);
var ul_critiques = tr_critiques.find('ul'); var ul_critiques = tr_critiques.find('ul');
$('<li class="notes_avis_babeltheque"><span id="BW_notes"></span><span id="BW_critiques"></span> <span id="BW_critiques_pro"></span></li>') $('<li class="notes_avis_babeltheque"><span id="BW_notes"></span><span id="BW_critiques"></span> <span id="BW_critiques_pro"></span></li>')
.appendTo(ul_critiques); .appendTo(ul_critiques);
} }
var videosNoticeAfterLoad = function(target) { var videosNoticeAfterLoad = function(target) {
target.find('td:contains("Aucune vidéo")').remove(); target.find('td:contains("Aucune vidéo")').remove();
target.prepend('<div id="BW_videos"></div>'); target.prepend('<div id="BW_videos"></div>');
} }
var resumeNoticeAfterLoad = function(target) { var resumeNoticeAfterLoad = function(target) {
target.find('td:contains("Aucune information")').remove(); target.find('td:contains("Aucune information")').remove();
target.babelthequeTag('citations'); target.babelthequeTag('citations');
} }
var babelthequeNoticeAfterLoad = function(target) { var babelthequeNoticeAfterLoad = function(target) {
target.empty().babelthequeTag('suggestions'); target.empty().babelthequeTag('suggestions');
} }
...@@ -964,18 +964,15 @@ class NoticeAjaxControllerExemplairesTest extends NoticeAjaxControllerExemplaire ...@@ -964,18 +964,15 @@ class NoticeAjaxControllerExemplairesTest extends NoticeAjaxControllerExemplaire
class NoticeAjaxControllerBabelthequeTest extends AbstractControllerTestCase { class NoticeAjaxControllerBabelthequeTest extends AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
Class_Notice::getLoader() $this->fixture('Class_Notice', ['id' => 157675,
->newInstanceWithId(157675) 'isbn' => '978-2-226-21993-0']);
->setIsbn('978-2-226-21993-0');
Class_AdminVar::getLoader() Class_AdminVar::set('BABELTHEQUE_JS', 'https://www.babelio.com/bw_85.js');
->newInstanceWithId('BABELTHEQUE_JS')
->setValeur('http://www.babeltheque.com/bw_85.js');
$this->dispatch('/opac/noticeajax/babeltheque?id_notice=N157675', true); $this->dispatch('/opac/noticeajax/babeltheque?id_notice=N157675', true);
} }
...@@ -983,7 +980,7 @@ class NoticeAjaxControllerBabelthequeTest extends AbstractControllerTestCase { ...@@ -983,7 +980,7 @@ class NoticeAjaxControllerBabelthequeTest extends AbstractControllerTestCase {
/** @test */ /** @test */
public function responseShouldContainsBabelthequeScript() { public function responseShouldContainsBabelthequeScript() {
$this->assertXPath('//script[@src="http://www.babeltheque.com/bw_85.js"]'); $this->assertXPath('//script[@src="https://www.babelio.com/bw_85.js"]');
} }
...@@ -1008,8 +1005,6 @@ class NoticeAjaxControllerBabelthequeTest extends AbstractControllerTestCase { ...@@ -1008,8 +1005,6 @@ class NoticeAjaxControllerBabelthequeTest extends AbstractControllerTestCase {
class NoticeAjaxControllerBabelthequeWithoutOptionTest extends AbstractControllerTestCase { class NoticeAjaxControllerBabelthequeWithoutOptionTest extends AbstractControllerTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment