/* testing a fix to enterprise */ /* loading Unbound settings with account id: 3465, i_id:0 */ Unbound_browserClassesAA = {"shortName":null,"brand":null,"useragent":"claudebot","classes":{"":1},"png_compatible":1,"touchDevice":0}; /* $backend_connector_filename_minified = /var/www/html/connector/connector_unbound_primo.min.js */ /* not cached or minified */ /* su connector version: latest */ /* including file: /var/www/html/syndeticsunbound/connector/syndeticsunbound_connector.js */ LibraryThingConnector = { loglevel: 1, metadata: null, metadataSource: null, errors: [], stats : { enrichments_shown : [], errors: [], enrichments_count : 0 }, sessions:{}, enrichments_count: 0, enrichments_shown : [], metadataTypes: [ 'title', 'author', 'isbns', 'upc', 'issns', 'itemInfo', 'accession', 'coverurl', ], SEARCHRESULT_LIGHTBOX_WIDTH: 700, SEARCHRESULT_LIGHTBOX_HEIGHT: 700, utils: {}, widgets: { stackMap: {}, shouldWatchForUrlChange: true // triggers bdw js to link }, isbn_identifiers : {}, // standard identifiers returned from widgets upc_identifiers : {}, // UPC standard identifiers returned from widgets issn_identifiers : {}, // ISSN standard identifiers returned from widgets bestidentifiersAA : { isbnA: [], upcA: [] }, // returned from LT widgets for syndeticsNoData browser : { classesAA: {} }, // browser type classes timing: { // timing, included in stats init: {}, loads: {}, hover: { api: { lt: {}, pq: {} }, javascript: [] }, searchresults: { api: { lt: {}, pq: {} }, javascript: [] }, widgets: { lt: {}, pq: {} }, metadata: { }, content: [ ] }, }; // console fallback for IE8 or less // from: http://stackoverflow.com/questions/690251/what-happened-to-console-log-in-ie8 (function (fallback) { fallback = fallback || function () { }; // function to trap most of the console functions from the FireBug Console API. var trap = function () { // create an Array from the arguments Object var args = Array.prototype.slice.call(arguments); // console.raw captures the raw args, without converting toString console.raw.push(args); var message = args.join(' '); console.messages.push(message); fallback(message); }; // redefine console if (typeof console === 'undefined') { console = { messages: [], raw: [], dump: function() { return console.messages.join('\n'); }, log: trap, debug: trap, info: trap, warn: trap, error: trap, assert: trap, clear: function() { console.messages.length = 0; console.raw.length = 0 ; }, dir: trap, dirxml: trap, trace: trap, group: trap, groupCollapsed: trap, groupEnd: trap, time: trap, timeEnd: trap, timeStamp: trap, profile: trap, profileEnd: trap, count: trap, exception: trap, table: trap }; } })(null); // to define a fallback function, replace null with the name of the function (ex: alert) LibraryThingConnector.info = function (msg, level) { level = level || 1; if (typeof LibraryThingConnector.loglevel !== "undefined" && level >= LibraryThingConnector.loglevel) { try { console.info(msg); } catch(err) {} } }; LibraryThingConnector.log = function (msg, level) { level = level || 1; if (typeof LibraryThingConnector.loglevel !== "undefined" && level >= LibraryThingConnector.loglevel) { try { console.info(msg); } catch(err) {} } }; LibraryThingConnector.debug = function (msg, level) { level = level || 1; if (typeof LibraryThingConnector.loglevel !== "undefined" && level >= LibraryThingConnector.loglevel) { try { console.debug(msg); } catch(err) {} } }; LibraryThingConnector.warn = function (msg, level) { level = level || 1; if (level >= LibraryThingConnector.loglevel) { console.warn(msg); } }; LibraryThingConnector.error = function (msg, level) { level = level || 1; if (level >= LibraryThingConnector.loglevel) { console.error(msg); } }; /* ported from syndetics widget_connector */ if( typeof $syndetics === "undefined" ) { $syndetics = {}; // $syndetics.jQuery loaded by initiator setup } $syndetics.callback = function() {}; // stub // wrapper for opening unbound lightbox called by syndetics unbound widgets LibraryThingConnector.syndetics_open_unbound_lightbox = function (url, clicked_link, title) { LibraryThingConnector.debug('open_unbound_lightbox to url: ' + url); if( !title ) { var title = LibraryThingConnector.utils.jQuery(clicked_link) .closest('div.unbound_element') .children('h3.unbound_header') .text(); if (!title) { title = "Syndetics Unbound"; } } if( LibraryThingConnector.backend.name == 'eds' ) { window.LibraryThingConnector.openLightbox(url, {'title': title}); } else { LibraryThingConnector.openLightbox(url, {'title': title}); } return; }; $syndetics.open_unbound_lightbox = LibraryThingConnector.syndetics_open_unbound_lightbox; LibraryThingConnector.get_all_upcs = function(html) { if( typeof html === 'undefined' || html === null || html == '') { return false; } LibraryThingConnector.debug('get_all_upcs'); try { LibraryThingConnector.debug(html); var upcs = html.match(/\D(([0-9]{12}))\D/g) || []; return LibraryThingConnector.utils.jQuery.unique(LibraryThingConnector.utils.jQuery.grep( LibraryThingConnector.utils.jQuery.map( upcs, function (upc) { return upc.substring(1, upc.length - 1); } ), LibraryThingConnector.valid_upc ) ).sort(); } catch(err) {} }; LibraryThingConnector.get_all_issns = function (html) { if( typeof html === 'undefined' || html === null || html == '') { return false; } LibraryThingConnector.debug('get_all_issns'); LibraryThingConnector.debug(html); var issns = html.match(/\D([0-9]{8}|[0-9]{7}[xX])\D/g) || []; return LibraryThingConnector.utils.jQuery.unique( LibraryThingConnector.utils.jQuery.grep( LibraryThingConnector.utils.jQuery.map( issns, function (issn) { return issn.substring(1, issn.length - 1); } ), LibraryThingConnector.valid_issn ) ).sort(); }; LibraryThingConnector.valid_isbn = function (isbn) { switch (isbn.length) { case 10: return LibraryThingConnector.valid_isbn10(isbn); case 13: return LibraryThingConnector.valid_isbn13(isbn); default: return false; } }; LibraryThingConnector.valid_isbn10 = function (isbn) { var total = 0; for (var i = 0; i < 10; i++) { var digit = isbn.charAt(i).toUpperCase(); if (digit == 'X') { total += 10; } else { total += parseInt(digit) * (10 - i); } } return total % 11 == 0; }; LibraryThingConnector.valid_isbn13 = function (isbn) { var total = 0; for (var i = 0; i < 13; i++) { var digit = parseInt(isbn.charAt(i)); if (i % 2 == 0) { total += digit; } else { total += digit * 3; } } return total % 10 == 0; }; LibraryThingConnector.valid_upc = function (upc) { var total = 0; for (var i = 0; i < 12; i++) { var digit = parseInt(upc.charAt(i)); if (i % 2 == 0) { total += digit * 3; } else { total += digit; } } return total % 10 == 0; }; LibraryThingConnector.valid_issn = function (issn) { issn = issn.replace(/[^\dX]/gi, ''); if (issn.length != 8) { return false; } var chars = issn.split(''); if (chars[7].toUpperCase() == 'X') { chars[7] = 10; } var sum = 0; for (var i = 0; i < chars.length; i++) { sum += ((8 - i) * parseInt(chars[i])); } ; return ((sum % 11) == 0); }; LibraryThingConnector.attachInitOnDomLoaded = function (func) { if (typeof(window.Unbound_loaded) == "undefined") { if (document.addEventListener) { if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive" ) { func(); } else { document.addEventListener("DOMContentLoaded", func, false); } } else if (window.addEventListener) { window.addEventListener("load", func, false); } else if (window.attachEvent) { window.attachEvent("onload", func); } } window.Unbound_loaded = 1; }; if(typeof LibraryThingConnector.inited === 'undefined') { LibraryThingConnector.inited = false; } if(typeof LibraryThingConnector.lightbox_inited === 'undefined') { LibraryThingConnector.lightbox_inited = false; } if( typeof LibraryThingConnector.unboundInitCalledB === 'undefined') { LibraryThingConnector.unboundInitCalledB = false; } /** * intiialize LibraryThingConnector within lightbox context, does subset of LibraryThingConnector.init() */ LibraryThingConnector.init_lightbox = function() { if (LibraryThingConnector.lightbox_inited ) { LibraryThingConnector.debug('lightbox js already inited'); return; } LibraryThingConnector.info('init_lightbox'); // collect information from lightbox url for stats purposes var query_hash = LibraryThingConnector.utils.parse_queries(); // for determine stats type var enrichment_type = query_hash['type']; if( !enrichment_type ) { enrichment_type = query_hash['enrichment_type']; } if( !enrichment_type ) { enrichment_type = query_hash['enhancement']; if( typeof enrichment_type !== "undefined" ) { enrichment_type = enrichment_type.replace('unbound_',''); } } // set metadata so it can be recorded in stats var metadata = { 'isbns': query_hash['su_isbns'], 'title' : query_hash['su_title'], 'author' : query_hash['su_author'], 'itemInfo' : query_hash['su_itemInfo'], 'catalog_url' : query_hash['su_catalog_url'] }; LibraryThingConnector.setMetadata(metadata, 'lightbox'); LibraryThingConnector.globals.enrichment_opened = query_hash['type']; LibraryThingConnector.initContainerQueries(); // enrichment-specific stats collection LibraryThingConnector.attachTagBrowseHandlers(); LibraryThingConnector.attachBookProfileHandlers(); LibraryThingConnector.attachAwardsBrowserHandlers(); LibraryThingConnector.attachLookInsideBrowserHandlers(); // LibraryThingConnector.attachScrollHandler(); // LibraryThingConnector.attachBeforeUnLoadHandler(); LibraryThingConnector.attachHashChangeHandler(); // Harvest identifiers (for building hovers) LibraryThingConnector.harvestIdentifiers('body', LibraryThingConnector.globals.enrichment_opened); LibraryThingConnector.requestLTAPI(); LibraryThingConnector.requestSyndeticsAPI(); // for author lightbox LibraryThingConnector.insertAuthorImage(); // add in hover div HTML LibraryThingConnector.debug('adding hoverDiv into body for lightbox'); LibraryThingConnector.addHoverToBody(); // // add in hovers LibraryThingConnector.attachHoverToCovers('body'); // // add in expand see more in .unbound_truncate LibraryThingConnector.attachExpands('body'); //LibraryThingConnector.addExpands('.unbound_award_text',50,'more',''); //UNBOUND 1725- This line was commented out when the award display was switched from icons to lines of text. // LibraryThingConnector.addExpands('.unbound_award_text',50,LibraryThingConnector.translationstringsA.readmore,''); LibraryThingConnector.addFooterHtml(); LibraryThingConnector.attachLibrarianPowerHandlers(); if ( typeof LibraryThingConnector.backend.init_lightbox !== 'undefined' ) { LibraryThingConnector.info('running LibraryThingConnector.backend.init_lightbox hook'); LibraryThingConnector.backend.init_lightbox(); } if ( typeof LibraryThingConnector.backend.unboundLoaded !== 'undefined' ) { LibraryThingConnector.info('running LibraryThingConnector.backend.unboundLoaded hook'); LibraryThingConnector.backend.unboundLoaded(); } LibraryThingConnector.lightbox_inited = true; }; LibraryThingConnector.addFooterHtml = function() { if(LibraryThingConnector.footerHTML) { LibraryThingConnector.info('addFooterHtml'); if( LibraryThingConnector.utils.jQuery('.unbound_lightbox_content').length) { LibraryThingConnector.utils.jQuery('.unbound_lightbox_content').append(LibraryThingConnector.footerHTML); } else { LibraryThingConnector.utils.jQuery('body').append(LibraryThingConnector.footerHTML); } } }; /* shim for existing LTFL backend code that requires LibraryThingConnector.widgets.run() method */ LibraryThingConnector.widgets.run = function(isbn,containingDivId) { LibraryThingConnector.info('widgets.run called. running .init'); LibraryThingConnector.init_variables(); LibraryThingConnector.init(); }; /* shim for catalogs that call old LTFL function directly */ function LT_get_widget_logic() { if ( LibraryThingConnector.inited ) { LibraryThingConnector.info('LT_get_widget_logic called, already inited, not re-running'); } else { LibraryThingConnector.info('LT_get_widget_logic called. running .init'); LibraryThingConnector.init_variables(); LibraryThingConnector.init(); } } if( typeof LibraryThingConnector.backend === "undefined" ) { LibraryThingConnector.backend = {}; LibraryThingConnector.backend.widgets = {}; LibraryThingConnector.backend.widgets.run = function(isbn,containingDiv) { LibraryThingConnector.debug('backend.widgets.run: isbn: ' + isbn + ' containingDiv: ' + containingDiv); LibraryThingConnector.backends.enterprise.widgets.run(isbn,containingDiv); LibraryThingConnector.setMetadata(LibraryThingConnector.metadata,'backend'); }; } LibraryThingConnector.syndeticsNoData = function() { LibraryThingConnector.info('syndeticsNoData:'); if ( LibraryThingConnector.syndeticsNoDataCalledB) { LibraryThingConnector.info('syndetics already retried, not calling again'); // make sure page stats gets called in this case LibraryThingConnector.statsRecordLPQ = true; LibraryThingConnector.recordPageStats(); return; } LibraryThingConnector.syndeticsNoDataCalledB = true; if( typeof LibraryThingConnector.bestidentifiersAA !== 'undefined' && (LibraryThingConnector.bestidentifiersAA.isbnA.length || LibraryThingConnector.bestidentifiersAA.upcA.length ) && LibraryThingConnector.workcode) { LibraryThingConnector.info('got bestidentifiersAA from LT widgets, reloading syndetics widgets'); LibraryThingConnector.stats.syndeticsNoData = 1; // record in stats var _metadata = LibraryThingConnector.metadata; _metadata.isbns = LibraryThingConnector.bestidentifiersAA.isbnA; _metadata.upcs = LibraryThingConnector.bestidentifiersAA.upcA; LibraryThingConnector.setMetadata(_metadata, 'ltwidgets'); LibraryThingConnector.loadSyndeticsWidgets(); } else { LibraryThingConnector.retrySyndeticsB = true; LibraryThingConnector.info('LT widgets not yet loaded, setting flag to reload syndetics when they do'); } }; // called by custom Enterprise js to start up Unbound and LTFL doLibraryThingConnector = function(isbn,elementName) { if (LibraryThingConnector.enrichments_disabledB) { LibraryThingConnector.info('enrichments_disabledB is true so not initing') return; } if(!LibraryThingConnector.backend.onModalPage()) { LibraryThingConnector.info('doLibraryThingConnector onModalPage is false, just setting metadata'); LibraryThingConnector.containingEl = LibraryThingConnector.utils.jQuery('#'+elementName).get(0); LibraryThingConnector.containingDivId = elementName; LibraryThingConnector.setMetadata(LibraryThingConnector.metadata,'backend'); return; } if( !elementName ) { LibraryThingConnector.info('no elementName passed into doLibraryThingConnector, getting from backend'); modalPanelAA = LibraryThingConnector.backend.getModalPanel(); if ( modalPanelAA ) { isbn = modalPanelAA['isbn']; elementName = modalPanelAA['id']; } } LibraryThingConnector.info('doLibraryThingConnector modalPage'); LibraryThingConnector.init_variables(); // re-init variales // force full pagetype LibraryThingConnector.pagetype = 'full'; // LibraryThingConnector.inited = false; // LibraryThingConnector.pagetype = 'full'; // TODO from backend // LibraryThingConnector.pageStatsRecordedB = false; // LibraryThingConnector.LTFLWidgetsLoadedB = false; // LibraryThingConnector.unboundContentAddedCalledB = false; // LibraryThingConnector.SyndeticsWidgetsLoadedB = false; LibraryThingConnector.shouldLoadSyndeticsWidgets = true; // force loading of syndetics widgets delete LibraryThingConnector.ISBNS; LibraryThingConnector.info('doLibraryThingConnector with isbn: ' + isbn + 'elementName: ' + elementName); var ranB = LibraryThingConnector.backends.enterprise.widgets.run(isbn,elementName); if( ranB ) { LibraryThingConnector.containingEl = LibraryThingConnector.utils.jQuery('#'+elementName).get(0); LibraryThingConnector.containingDivId = elementName; LibraryThingConnector.setMetadata(LibraryThingConnector.metadata,'backend'); LibraryThingConnector.init(); } }; /* legacy code for book display widgets */ LibraryThingConnector.widgets.watchForUrlChange = function () { LibraryThingConnector.debug('watchForUrlChange'); if (typeof window.onpageshow != 'undefined' && LibraryThingConnector.browser.classesAA['ipad']) // for ipads, refresh the page if we're coming back from a fwd/back cache event { window.onpageshow = function (event) { if (event.persisted) { window.location.reload() } }; } LibraryThingConnector.widgets.urlChangeTimer = setInterval(function () { // LibraryThingConnector.log("checking for url change"); var curHash = ''; try { curHash = window.top.location.hash; } catch (err) { LibraryThingConnector.log('unable to check current window.top hash', 10); LibraryThingConnector.log(err, 10); } //LibraryThingConnector.log(curHash); if (curHash.match(/LTGoto/)) { var hashAndKey = curHash.split(':'); if (hashAndKey.length > 1 && LibraryThingConnector.widgets.shouldWatchForUrlChange) { LibraryThingConnector.log('found haskAndKey, setting to _ and adding to history.pushState'); // add to browser history in case we're coming from an iframe link that has to use window.location.replace -- that removes the current page from history // change hash to mean do nothing if( LibraryThingConnector.browser.brand == 'chrome') { LibraryThingConnector.log('not changing hash to _ for chrome'); } else { LibraryThingConnector.log('changing hash to _'); window.top.location.hash = '_'; } var raw_page_url = window.top.location.href.split('#')[0]; if( history && history.pushState ) { history.pushState(null, raw_page_url, raw_page_url); // note, don't include the hash b/c that would cause the page to go right back to LTGoto } else { // IE does not support history.pushState. But....it doesn't seem to break the back button, either. } LibraryThingConnector.widgets.shouldWatchForUrlChange = false; var cacheKey = hashAndKey[1]; LibraryThingConnector.log('checking for url to go to at key:' + cacheKey); var LTGotoUrl = LibraryThingConnector.LTFL_BASE_URL + 'get_url.php?key=' + cacheKey; LibraryThingConnector.utils.requestContent(LTGotoUrl); } } }, 100); }; LibraryThingConnector.reinit = function() { LibraryThingConnector.info('reinit'); LibraryThingConnector.init_variables(); LibraryThingConnector.init(); }; LibraryThingConnector.init_variables = function() { LibraryThingConnector.info('re-init variables'); // LibraryThingConnector.megaDivHTML = ''; // LibraryThingConnector.hoverDivHTML = ''; // LibraryThingConnector.megadiv_id = ''; var _current_megadiv_id = LibraryThingConnector.utils.jQuery('.unbound_mega').attr('id'); var _current_footer = LibraryThingConnector.utils.jQuery('.unbound_mega_footer'); // TODO see if we can just hide the old one if ( LibraryThingConnector.backend.name == 'summon' || LibraryThingConnector.backend.name == 'accessit' || LibraryThingConnector.backend.name == 'soutron' || LibraryThingConnector.backend.name == 'summon2' ) { // detach existing hovers var existing_hovers = LibraryThingConnector.utils.jQuery('.unbound_mega').next('.unbound_hover'); if( existing_hovers ) { LibraryThingConnector.info('detaching existing unbound_hover next to megadiv'); LibraryThingConnector.utils.jQuery(existing_hovers).detach(); } if ( LibraryThingConnector.backend.name == 'summon2') { LibraryThingConnector.utils.jQuery(_current_footer).detach(); } // remove old megadiv, needs !important bc regular unbound.css does so LibraryThingConnector.debug('removing old megadiv'); LibraryThingConnector.utils.jQuery('#'+_current_megadiv_id).remove(); LibraryThingConnector.hoverAddedB = false; // reset this so that addHoverToBody knows it needs to re-do } var startTime = new Date().getTime(); if( LibraryThingConnector.utils.jQuery('.unbound_mega').length ) { LibraryThingConnector.info('renaming old megadiv id'); LibraryThingConnector.utils.jQuery('.unbound_mega').each(function(n) { LibraryThingConnector.utils.jQuery(this).attr('id', startTime); }); } LibraryThingConnector.inited = false; LibraryThingConnector.megaDivInsertedB = false; LibraryThingConnector.metadataExtractedB = false; LibraryThingConnector.LTFLWidgetsLoadedB = false; LibraryThingConnector.loadingLTFLWidgetsB = false; LibraryThingConnector.loadingSyndeticsWidgetsB = false; LibraryThingConnector.contentReadyB = false; LibraryThingConnector.SyndeticsWidgetsLoadedB = false; LibraryThingConnector.syndeticsNoDataCalledB = false; LibraryThingConnector.workcode = 0; LibraryThingConnector.pagetype = null; LibraryThingConnector.isbn_identifiers = {}; LibraryThingConnector.upc_identifiers = {}; LibraryThingConnector.issn_identifiers = {}; LibraryThingConnector.ISBNS = []; LibraryThingConnector.bestidentifiersAA = { isbnA : [], upcA: [] }; LibraryThingConnector.pageStatsRecordedB = false; LibraryThingConnector.statsRecordLTB = false; LibraryThingConnector.statsRecordLPQ = false; LibraryThingConnector.searchStatsRecordedB = false; LibraryThingConnector.searchStatsRecordLTB = false; LibraryThingConnector.searchStatsRecordLPQ = false; LibraryThingConnector.contentReady_Intervalh = null; LibraryThingConnector.BDW_loadedB = false; LibraryThingConnector.contentReady_tries = 0; LibraryThingConnector.contentReady_max_tries = 500; LibraryThingConnector.unboundContentAddedCalledB = false; LibraryThingConnector.containingDivId = null; LibraryThingConnector.catalog_language_raw = null; LibraryThingConnector.catalog_language = null; LibraryThingConnector.catalog_language_code = null; LibraryThingConnector._hoverElement = {}; // need to reset this so that getHover() gets a new #unbound_hover LibraryThingConnector.containingEl = null; LibraryThingConnector.init_abortedB = false; LibraryThingConnector.AISearchLoadedB = false; LibraryThingConnector.contentReadyInterval = 500; // ms to retry extracting metadata and inserting mega div if content not ready LibraryThingConnector.metadata = null; LibraryThingConnector.timing = { // timing, included in stats init: {}, loads: {}, hover: { api: { lt: {}, pq: {} }, javascript: [] }, searchresults: { api: { lt: {}, pq: {} }, javascript: [] }, widgets: { lt: {}, pq: {} }, metadata: { }, content: [ ] }; var currentTime = new Date().getTime(); LibraryThingConnector.su_session = Math.random().toString(24); LibraryThingConnector.stats = { enrichments_shown : [], enrichments_count: 0, errors: [] }; // houses enrichment/load/lightbox statistics LibraryThingConnector.errors = []; LibraryThingConnector.globals = { }; // container for globals if( typeof LibraryThingConnector.sessions !== 'undefined') { LibraryThingConnector.sessions[LibraryThingConnector.su_session] = {}; } if ( typeof LibraryThingConnector.backend.init_variables !== 'undefined' ) { LibraryThingConnector.info('running backend init_variables hook'); LibraryThingConnector.backend.init_variables(); } } /** * initialize LibraryThingConnector * called for regular in-catalog enhancements */ LibraryThingConnector.init = function () { if (LibraryThingConnector.inited ) { return; } LibraryThingConnector.loadBDW(); try { LibraryThingConnector.clearDebugPanel(); } catch (e) { LibraryThingConnector.info(e); } if (LibraryThingConnector.enrichments_disabledB) { // run unboundInit in this case as well if (typeof unboundInit !== 'undefined' && typeof unboundInit == 'function' && !LibraryThingConnector.unboundInitCalledB) { LibraryThingConnector.info('found unboundInit function, running'); LibraryThingConnector.unboundInitCalledB = true; unboundInit(); return; } LibraryThingConnector.info('enrichments_disabledB is true so not initing') return; } // LibraryThingConnector.debug('connector: init started'); // allow backend to detect content or URL changes and respond appropriately (e.g. reload unbound content for newly clicked page/url) if(!LibraryThingConnector.contentChangedHandlerAddedB && LibraryThingConnector.backend && LibraryThingConnector.backend.contentChanged ) { LibraryThingConnector.info('url: ' + location.href); LibraryThingConnector.contentChangedHandlerAddedB = true; LibraryThingConnector.backend.contentChanged(); } if ( LibraryThingConnector.init_abortedB ) { // LibraryThingConnector.debug('init aborted'); return; } if (1) { // check for aisearch html, if found, attach handler LibraryThingConnector.AISearchLoadedB = LibraryThingConnector.attachAISearchHandlers(); // check for URL hash, if found, launch aisearch lightbox if (0) { var hash_query = LibraryThingConnector.checkHashAISearch(); if (hash_query) { LibraryThingConnector.info('found hash_query: ' + hash_query); LibraryThingConnector.openAISearchLightbox(null, hash_query); } } } if( LibraryThingConnector.pagetype && LibraryThingConnector.backend.name != 'bibliovation' && LibraryThingConnector.backend.name != 'leganto') { LibraryThingConnector.info('pagetype already set to: ' + LibraryThingConnector.pagetype); } else { LibraryThingConnector.info('getting pagetype from backend'); LibraryThingConnector.pagetype = LibraryThingConnector.backend.pageTypeDetector(); } try { LibraryThingConnector.logDebugPanelCustomer(); } catch(e) { LibraryThingConnector.info(e); } LibraryThingConnector.info('pagetype returned as:' + LibraryThingConnector.pagetype); if( LibraryThingConnector.pagetype == '' && LibraryThingConnector.AISearchLoadedB ) { LibraryThingConnector.info('pagetype is empty, but aisearch loaded, allowing init to continue'); } if( LibraryThingConnector.backend.name == 'enterprise' && LibraryThingConnector.containingEl === null && LibraryThingConnector.lsa_id != 2110) { var isUnboundInfrastructureMigrationB = LibraryThingConnector.backend.isUnboundInfrastructureMigration(); if (isUnboundInfrastructureMigrationB === 0) { LibraryThingConnector.info('infra isUnboundInfrastructureMigrationB is OFF, aborting SU init'); return false; } else if (isUnboundInfrastructureMigrationB === 1) { LibraryThingConnector.info('infra isUnboundInfrastructureMigrationB is ON, allowing SU init to continue'); } if( LibraryThingConnector.backend.onModalPage() && LibraryThingConnector.pagetype == 'full') { if( LibraryThingConnector.backend.isUnboundInfrastructureMigration()) { LibraryThingConnector.info('enterprise: infra migration on modal detecting modal and running on it'); var enterprise_modalAA = LibraryThingConnector.backend.getModalPanel(); LibraryThingConnector.info(enterprise_modalAA); if (enterprise_modalAA.isbn && typeof enterprise_modalAA.isbn !== 'undefined') { LibraryThingConnector.info('metadata found, running with unbound'); LibraryThingConnector.backend.widgets.run(enterprise_modalAA.isbn,enterprise_modalAA.id); } } else { if( typeof LibraryThingConnector.backend.widgets.runUnboundFromModalPageB !== 'undefined' && LibraryThingConnector.backend.widgets.runUnboundFromModalPageB === true) { LibraryThingConnector.backend.widgets.runUnboundFromModalPageB = false; // reset LibraryThingConnector.info('onModalPage and init called for by enteprrise, running'); } else { LibraryThingConnector.info('onModalPage and init from enterprise aborted - awaiting callback from Enterprise js but loading BDW'); return; } } } else { LibraryThingConnector.info('Enterprise and not on modal page, allowing init to continue'); } } if( LibraryThingConnector.backend.name == 'iguana' && !LibraryThingConnector.metadata) { LibraryThingConnector.info('aborting .init for infor with no metadata set'); return; } // for new primo, don't run .init if metadata not set if( LibraryThingConnector.backend.name == 'primo' && LibraryThingConnector.backend.getPrimoVersion() == 'new' && LibraryThingConnector.pagetype != 'summary' && LibraryThingConnector.metadata === null) { LibraryThingConnector.info('aborting .init for primo with no metadata set'); return; } if( LibraryThingConnector.backend.name == 'summonoveralma' && !LibraryThingConnector.metadata && /discovery/.test(window.location.href) && LibraryThingConnector.pagetype != 'summary') { LibraryThingConnector.info('aborting .init for primo with no metadata set'); return; } if (typeof unboundInit !== 'undefined' && typeof unboundInit == 'function' && !LibraryThingConnector.unboundInitCalledB) { LibraryThingConnector.info('found unboundInit function, running'); LibraryThingConnector.unboundInitCalledB = true; unboundInit(); return; } var startTime = new Date().getTime(); LibraryThingConnector.timing.init.start = startTime; if( LibraryThingConnector.backend && LibraryThingConnector.backend.getContainingEl ) { LibraryThingConnector.debug('containingEl from backend'); LibraryThingConnector.containingEl = LibraryThingConnector.backend.getContainingEl(); LibraryThingConnector.debug(LibraryThingConnector.containingEl); } else if( typeof LibraryThingConnector.containingEl !== 'undefined') { LibraryThingConnector.info('containingEl already set, using that'); LibraryThingConnector.info(LibraryThingConnector.containingEl); } else { LibraryThingConnector.info('containingEl not set, using document.body'); LibraryThingConnector.containingEl = document.body; } if (typeof LibraryThingConnector.backend.contentReady_Intervalh !== 'undefined' ) { LibraryThingConnector.info('contentReady_Intervalh from backend'); LibraryThingConnector.contentReadyInterval = LibraryThingConnector.backend.contentReadyInterval; } if (typeof LibraryThingConnector.backend.contentReady_max_tries !== 'undefined' ) { LibraryThingConnector.info('contentReady_max_tries from backend'); LibraryThingConnector.contentReady_max_tries = LibraryThingConnector.backend.contentReady_max_tries; } if( LibraryThingConnector.backend && LibraryThingConnector.backend.contentReady ) { LibraryThingConnector.debug('init: checking with backend for contentReady'); LibraryThingConnector.contentReadyB = LibraryThingConnector.backend.contentReady(LibraryThingConnector.containingEl); } else // assume content is ready if backend does not support contentReady() method { LibraryThingConnector.contentReadyB = true; } if( !LibraryThingConnector.contentReadyB ) { // LibraryThingConnector.debug('content not ready, trying in ' + LibraryThingConnector.contentReadyInterval + 'ms'); if( LibraryThingConnector.backend.name == 'polaris' ) { LibraryThingConnector.contentReadyInterval = 1500; // ms to retry extracting metadata and inserting mega div if content not ready LibraryThingConnector.contentReady_max_tries = 500; } LibraryThingConnector.contentReady_Intervalh = setInterval(LibraryThingConnector.init,LibraryThingConnector.contentReadyInterval); LibraryThingConnector.inited = false; LibraryThingConnector.contentReady_tries++; if ( LibraryThingConnector.contentReady_tries > LibraryThingConnector.contentReady_max_tries) { LibraryThingConnector.warn('content never reported ready by backend, aborting'); LibraryThingConnector.init_abortedB = true; LibraryThingConnector.inited = true; clearInterval(LibraryThingConnector.contentReady_Intervalh); if( LibraryThingConnector.backend && LibraryThingConnector.backend.contentNeverReady ) { LibraryThingConnector.backend.contentNeverReady(); } } return; } else { LibraryThingConnector.info('backend reports content ready (or we assume it is if backend does not support contentReady method)'); LibraryThingConnector.loadBDW(); } if (typeof LibraryThingConnector.backend.detectLanguage !== 'undefined') { LibraryThingConnector.info('detecting language'); var language = LibraryThingConnector.backend.detectLanguage(); if ( language ) { LibraryThingConnector.info('language detected: ' + language); LibraryThingConnector.catalog_language_raw = language; var lang_key = language; if ( typeof LibraryThingConnector.languagestrings_to_codesAA[lang_key] != 'undefined' ) { LibraryThingConnector.catalog_language_code = LibraryThingConnector.languagestrings_to_codesAA[lang_key]; LibraryThingConnector.catalog_language = LibraryThingConnector.catalog_language_code; } else { LibraryThingConnector.warn('no language code found for raw language string: ' + language); } } else { LibraryThingConnector.catalog_language = 'eng'; LibraryThingConnector.catalog_language_raw = 'eng'; LibraryThingConnector.catalog_language_code = 'eng'; } } var searchDivRanB = false; if( LibraryThingConnector.pagetype == 'summary' ) { LibraryThingConnector.info('summary pagetype found'); if( typeof LibraryThingConnector.run_search_div !== 'undefined' && LibraryThingConnector.run_search_div) { LibraryThingConnector.info('running unbound on search results'); searchDivRanB = LibraryThingConnector.init_searchresults(); // NB only actually runs if the backend has implemented the required methods } } if( !LibraryThingConnector.eventListenersAddedB ) { LibraryThingConnector.info('adding event listeners'); LibraryThingConnector.addEventListeners(); LibraryThingConnector.eventListenersAddedB = true; } else { LibraryThingConnector.info('not re-adding event listeners'); } // check for existing unbound divs that are split out and mark them if (typeof LibraryThingConnector.backend.beforeInsertMegaDiv !== 'undefined') { LibraryThingConnector.info('found backend beforeInsertMegaDiv, calling'); LibraryThingConnector.backend.beforeInsertMegaDiv(); } // LibraryThingConnector.widgets.stackMap.paramsA = []; LibraryThingConnector.info('megaDiv insertion'); LibraryThingConnector.insertMegaDiv(LibraryThingConnector.megaDivHTML); if( typeof LibraryThingConnector.backend.afterInsertMegaDiv !== 'undefined' ) { LibraryThingConnector.info('found backend afterInsertMegaDiv, calling'); LibraryThingConnector.backend.afterInsertMegaDiv(); } LibraryThingConnector.debug('browser type'); LibraryThingConnector.debug(LibraryThingConnector.getBrowserType()); // Metadata Extraction // TODO decide if we want top level COiNS or not /* var metadataFromCoins = LibraryThingConnector.getMetadataFromCoins(document.body); if (metadataFromCoins) { LibraryThingConnector.log('metadata from coins'); LibraryThingConnector.setMetadata(metadataFromCoins, 'coins'); } */ LibraryThingConnector.salestoolB = false; //if we are on the syndeticsunbound demo default to fullpage if(/syndeticsunbound\/demo/.test(window.location.href)) { LibraryThingConnector.pagetype = 'full'; LibraryThingConnector.salestoolB = true; } if(/\/tests\/manual\/opacs/.test(window.location.href)) { LibraryThingConnector.pagetype = 'full'; } if( LibraryThingConnector.a_id == 22 ) { LibraryThingConnector.info('forcing pagetype of full for test account 22'); LibraryThingConnector.pagetype = 'full'; } var startTime = new Date().getTime(); if (LibraryThingConnector.backend && LibraryThingConnector.backend.extractMetadata) { var el = document.body; if ( LibraryThingConnector.containingEl && typeof LibraryThingConnector.containingEl !== "undefined") { el = LibraryThingConnector.containingEl; LibraryThingConnector.debug('extract metadata from containingEl'); LibraryThingConnector.debug(el); } var data = LibraryThingConnector.backend.extractMetadata(el); if( LibraryThingConnector.metadata && typeof LibraryThingConnector.metadata['upc'] == 'undefined') { LibraryThingConnector.info('no upc found in metadata, extracting from top level'); var upcs = LibraryThingConnector.get_all_upcs(el.innerHTML); data['upc'] = upcs; } if( LibraryThingConnector.metadata && typeof LibraryThingConnector.metadata['issns'] == 'undefined') { LibraryThingConnector.info('no issns found in metadata, extracting from top level'); var issns = LibraryThingConnector.get_all_issns(el.innerHTML); data['issns'] = issns; } if( LibraryThingConnector.metadata ) // can come in from backend { LibraryThingConnector.info('metadata directly from backend'); data = LibraryThingConnector.metadata; } if(typeof LibraryThingConnector.oaisbn !== 'undefined') { LibraryThingConnector.debug('using oaisbn: ' + LibraryThingConnector.oaisbn); data['isbns'] = ["" + LibraryThingConnector.oaisbn]; data['first_isbn'] = ["" + LibraryThingConnector.oaisbn]; } if (data) { LibraryThingConnector.debug('metadata from backend'); LibraryThingConnector.setMetadata(data, LibraryThingConnector.backend.name); } } else { LibraryThingConnector.warn('no backend found'); var isbns = LibraryThingConnector.utils.extract_ISBNs(document.body.innerHTML); if( isbns ) { var metadata = {}; metadata['isbns'] = isbns; LibraryThingConnector.setMetadata(metadata,'generic'); } } LibraryThingConnector.timing.metadata.total = new Date().getTime() - startTime; if (LibraryThingConnector.metadata) { // signal metadata is loaded LibraryThingConnector.info('metadata loaded'); LibraryThingConnector.info(LibraryThingConnector.metadata); // Load LTFL Widgets LibraryThingConnector.loadWidgets(); } else { LibraryThingConnector.info('metadata not loaded, not loading widgets'); } // clobber timeouts so page does not auto refresh if( typeof LibraryThingConnector.backend.clobberTimeout !== 'undefined' ) { LibraryThingConnector.info('clobbering timeout'); LibraryThingConnector.backend.clobberTimeout(); } // redefine $syndetics.unbound_lightbox_open method in case other syndetics content overwrite the $syndetics object setTimeout(function () { LibraryThingConnector.debug('redefining $syndetics.open_unbound_lightbox function'); // wrapper for opening unbound lightbox called by syndetics unbound widgets, ultimately to be removed in favor of the wrapper include in connector $syndetics.open_unbound_lightbox = LibraryThingConnector.syndetics_open_unbound_lightbox; }, 2000); LibraryThingConnector.initContainerQueries(); LibraryThingConnector.supportHandler(); // adds classes to megadiv and splitdiv to indicate various css feature support. LibraryThingConnector.inited = true; var endTime = new Date().getTime(); LibraryThingConnector.timing.init.total = endTime - startTime; LibraryThingConnector.timing.init.end = endTime; LibraryThingConnector.info('connector: init completed'); if( typeof LibraryThingConnector.backend.initCompleted !== 'undefined' ) { LibraryThingConnector.backend.initCompleted(); } if (!LibraryThingConnector.pageStatsRecordedB) { // make sure recordPageStats is run eventually setTimeout(function () { if ( !LibraryThingConnector.pageStatsRecordedB ) { // report error here, depending content script failed if (LibraryThingConnector.loadingSyndeticsWidgetsB && !LibraryThingConnector.statsRecordLPQ && !LibraryThingConnector.PQWidgetsLoadedB && !LibraryThingConnector.syndeticsNoDataCalledB && !LibraryThingConnector.init_abortedB) { LibraryThingConnector.info('pq stats not recorded'); LibraryThingConnector.errors.push(LibraryThingConnector.error_types.WidgetsPQFailed); } if (LibraryThingConnector.loadingLTFLWidgetsB && !LibraryThingConnector.statsRecordLTB && !LibraryThingConnector.LTFLWidgetsLoadedB && !LibraryThingConnector.init_abortedB) { LibraryThingConnector.info('lt stats not recorded'); LibraryThingConnector.errors.push(LibraryThingConnector.error_types.WidgetsLTFailed); } // now allow recording of page stats LibraryThingConnector.info('trying recordPageStats a final time'); LibraryThingConnector.statsRecordLPQ = true; LibraryThingConnector.statsRecordLTB = true; LibraryThingConnector.recordPageStats(); } }, 4000); } if( LibraryThingConnector.suDemoModeB ) { LibraryThingConnector.showDemoMode(); } }; LibraryThingConnector.init_searchresults = function() { LibraryThingConnector.info('init_searchresults'); LibraryThingConnector.metadata = {}; var searchresults = []; var isbn_identifiers = []; var upc_identifiers = []; var issn_identifiers = []; var supportsSearchResultsB = typeof LibraryThingConnector.backend.getSummaryChunks !== 'undefined' && typeof LibraryThingConnector.backend.getUnboundInsertNodeSummary !== 'undefined' && typeof LibraryThingConnector.backend.unboundInsertSummaryContent !== 'undefined'; if(supportsSearchResultsB) { LibraryThingConnector.logDebugPanelMetadata(); LibraryThingConnector.info('backend supports search results, getting results'); LibraryThingConnector.info('running getSummaryChunks'); var summaryChunks = LibraryThingConnector.backend.getSummaryChunks(); LibraryThingConnector.debug(summaryChunks); if( summaryChunks.length ) { LibraryThingConnector.info('found ' + summaryChunks.length + ' search results, running Unbound on them'); // TODO chunk requests var MAX_RESULTS = 15; LibraryThingConnector.utils.jQuery(summaryChunks).each( function(i,n ) { LibraryThingConnector.info('running Unbound on search result:'+i); LibraryThingConnector.info(n); // check if already run on this summaryChunk if( LibraryThingConnector.utils.jQuery(n).find('.unbound_searchresult').length ) { LibraryThingConnector.info('search-div already on this chunk, skipping'); return false; // stop jquery.each } // harvest identifiers var _html = LibraryThingConnector.utils.jQuery(n).html(); var _isbns = LibraryThingConnector.utils.extract_ISBNs(_html); var _upcs = LibraryThingConnector.get_all_upcs(_html); var _issns = LibraryThingConnector.get_all_issns(_html); var _metadata = LibraryThingConnector.backend.extractMetadata(n); // prefer backend's own isbns if we have if (typeof _metadata.isbns !== 'undefined') { LibraryThingConnector.info('using backend isbns from _metadata'); _isbns = _metadata.isbns; } // harvest metadata var isbn = null; var isbn13 = null; var upc = null; var issn = null; // if identifiers found, harvest if( _metadata ) { isbn13 = ''; isbn = _isbns[0]; if ( isbn ) { LibraryThingConnector.info('found isbns for chunk: ' + _isbns); isbn13 = LibraryThingConnector.utils.ISBN_convert10to13(isbn); isbn_identifiers.push(isbn13); } if( _upcs.length ) { upc = _upcs[0]; upc_identifiers.push(upc); } if( _issns.length ) { issn = _issns[0]; issn_identifiers.push(issn); } // can be used in lieu of identifier currentTime = new Date().getTime(); // only include keys for which we found data to cut down on request size var searchDivMetadataKeyA = ['isbns', 'title', 'author', 'upcs', 'issns','upc']; var encodeKeysFor = ['title', 'author'] var _result = {'id': currentTime}; LibraryThingConnector.utils.jQuery.each(searchDivMetadataKeyA, function (k, key) { var metadata_val = _metadata[key]; if (typeof metadata_val != 'undefined') { if( typeof metadata_val === 'string') { metadata_val = LibraryThingConnector.utils.stripControlChars(metadata_val); } if (typeof encodeKeysFor[key] != 'undefined') { _result[key] = encodeURIComponent(metadata_val); } else { _result[key] = metadata_val; } } }); // each metadata key _result['upcs'] = _result['upc']; // searchresults apis except upcs but metadata returns upc delete _result['upc']; LibraryThingConnector.info('final searchresult _result'); LibraryThingConnector.info(_result); searchresults.push(_result); // set up insertNode var insertNode = null; insertNode = LibraryThingConnector.backend.getUnboundInsertNodeSummary(n); LibraryThingConnector.info('insertNode'); LibraryThingConnector.info(insertNode); var summary_html = LibraryThingConnector.searchresults_summaryHTML; // transform into dom nodes var summary_node = summary_html; // no longer run parseHTML // set the identifier for it LibraryThingConnector.info('summary_node'); LibraryThingConnector.info(summary_node); if( insertNode ) { // put it in the right place and contaianer LibraryThingConnector.info('running unboundInsertSummaryContent'); LibraryThingConnector.backend.unboundInsertSummaryContent(summary_node, insertNode); // var id_attribute = ''; // if( isbn ) // { // LibraryThingConnector.debug('found isbn, using it'); // id_attribute = 'isbn:'+isbn13; // } // else // { var id_attribute = 'id:'+currentTime; // } var summary = LibraryThingConnector.utils.jQuery('.unbound_searchresult',insertNode); LibraryThingConnector.utils.jQuery(summary).data('id',id_attribute); LibraryThingConnector.utils.jQuery(summary).data('title',_metadata.title); LibraryThingConnector.utils.jQuery(summary).attr('data-title',_metadata.title); if( _result['upcs']) { LibraryThingConnector.utils.jQuery(summary).attr('data-upc',_result['upcs']); } if( _result['issn']) { LibraryThingConnector.utils.jQuery(summary).attr('data-issn',_result['issn']); } // also update attribute so it's findable by data-id in dom LibraryThingConnector.utils.jQuery(summary).attr('data-id',id_attribute); var id = LibraryThingConnector.utils.jQuery(summary).data('id'); LibraryThingConnector.info('id: ' + id); if( isbn13 ) { var isbn_attribute = 'isbn:'+isbn13; LibraryThingConnector.utils.jQuery(summary).data('isbn',isbn_attribute); // also update attribute so it's findable by data-id in dom LibraryThingConnector.utils.jQuery(summary).attr('data-isbn',isbn_attribute); } } } // metadata found else { LibraryThingConnector.info('no metadata found, marking as checked'); LibraryThingConnector.utils.jQuery(n).addClass('unbound_searchresult').addClass('unbound_searchresult_none'); } }); } // foreach search result // prepare identifiers LibraryThingConnector.info('adding identifiers from searchresults: isbn:'+isbn_identifiers.length+' upc:'+upc_identifiers.length+ ' issn:'+issn_identifiers.length) LibraryThingConnector.addIdentifiers('searchresults', 'isbn', isbn_identifiers); LibraryThingConnector.addIdentifiers('searchresults', 'upc',upc_identifiers); LibraryThingConnector.addIdentifiers('searchresults', 'issn',issn_identifiers); // request the data LibraryThingConnector.requestLTSearchResultsAPI(searchresults); LibraryThingConnector.requestSyndeticsSearchResultsAPI(searchresults); LibraryThingConnector.searchresults = searchresults; if( LibraryThingConnector.backend && LibraryThingConnector.backend.unboundContentAdded && !LibraryThingConnector.unboundContentAddedCalledB) { LibraryThingConnector.info('running backend.unboundContentAdded'); LibraryThingConnector.backend.unboundContentAdded(LibraryThingConnector.containingDivId); LibraryThingConnector.unboundContentAddedCalledB = true; } // make sure recordPageStats is run eventually setTimeout(function () { if (!LibraryThingConnector.searchStatsRecordLTB) { LibraryThingConnector.info('lt search page stats not recorded'); LibraryThingConnector.errors.push(LibraryThingConnector.error_types.WidgetsLTFailed); } if (!LibraryThingConnector.searchStatsRecordPQB) { LibraryThingConnector.info('pq search page stats not recorded'); LibraryThingConnector.errors.push(LibraryThingConnector.error_types.WidgetsPQFailed); } // now allow recording of page stats LibraryThingConnector.info('trying recordSearchPageStats a final time'); LibraryThingConnector.searchStatsRecordLPQ = true; LibraryThingConnector.searchStatsRecordLLT = true; LibraryThingConnector.recordSearchPageStats(); }, 4000); return true; } else { LibraryThingConnector.info('backend: ' + LibraryThingConnector.backend.name + ' does not support searchresults'); return false; } }; LibraryThingConnector.getBrowserType = function () { return LibraryThingConnector.browserClassesAA; }; LibraryThingConnector.handleHashChange = function (ev) { try { LibraryThingConnector.recordTime(ev); } catch (error) { console.error(error); } }; LibraryThingConnector.attachHashChangeHandler = function() { LibraryThingConnector.info('attachHashChangeHandler'); LibraryThingConnector.utils.jQuery(window).off('hashchange',LibraryThingConnector.handleHashChange).on('hashchange',LibraryThingConnector.handleHashChange); }; LibraryThingConnector.attachBeforeUnLoadHandler = function() { LibraryThingConnector.info('attachBeforeUnloadHandler'); window.onbeforeunload = function(ev) { return LibraryThingConnector.handleBeforeUnLoad(ev); } }; LibraryThingConnector.recordTime = function (ev) { if (LibraryThingConnector.backend.name == 'ebookcentral') { return; } try { LibraryThingConnector.info('recordTime'); if( typeof LibraryThingConnector.timing.init !== 'undefined' ) { var stats_key = 'timeonpage'; var endTime = new Date().getTime(); var totalTime = endTime - LibraryThingConnector.timing.init.start; var data = {'type':'timeonpage'}; data[stats_key] = totalTime; LibraryThingConnector.recordStats(data); } } catch (error) { console.info('recordTime error'); console.info(error); } }; LibraryThingConnector.handleBeforeUnLoad = function(ev) { try { LibraryThingConnector.recordTime(ev); } catch (error) { console.error(error); } }; LibraryThingConnector.attachScrollHandler = function() { LibraryThingConnector.info('attachScrollHandler'); LibraryThingConnector.utils.jQuery(document).off('scroll',LibraryThingConnector.scrollHandler).on('scroll',LibraryThingConnector.utils.jQuery.throttle(1200,LibraryThingConnector.scrollHandler)); }; LibraryThingConnector.scrollHandler = function() { LibraryThingConnector.info('unbound: scroll handler'); var currentTime = new Date().getTime(); if (typeof LibraryThingConnector.stats['seen'] == 'undefined') { LibraryThingConnector.stats['seen'] = {}; } var megadiv_el = LibraryThingConnector.getMegaDivEl(); LibraryThingConnector.stats['seen'][currentTime] = {}; LibraryThingConnector.stats['seen'][currentTime]['megadiv'] = LibraryThingConnector.utils.isInViewport(megadiv_el); if (LibraryThingConnector.enrichmentsShown()) { LibraryThingConnector.utils.jQuery.each(LibraryThingConnector.enrichmentsShown(), function (i, n) { var enrichment_el = LibraryThingConnector.utils.jQuery('.unbound_' + n).get(0); var enrichment_seen = LibraryThingConnector.utils.isInViewport(enrichment_el); LibraryThingConnector.stats['seen'][currentTime][n] = enrichment_seen; } ); } LibraryThingConnector.recordScrollStat(currentTime); }; LibraryThingConnector.recordScrollStat = function(currentTime) { LibraryThingConnector.info('recordScrollStat'); var stats_key = 'seen'; var data = { type:'scroll' }; data[stats_key] = LibraryThingConnector.stats.seen[currentTime]; LibraryThingConnector.recordStats(data); }; LibraryThingConnector.recordHoverStat = function(enrichment) { // not for ebc yet until we get integrated into ga if (LibraryThingConnector.backend.name == 'ebookcentral') { return; } LibraryThingConnector.info('recordHoverStat'); var stats_key = 'shown'; var data = { type:'hover', enrichment:enrichment }; data[stats_key] = 1; LibraryThingConnector.recordStats(data); }; LibraryThingConnector.attachScrollJumps = function() { if( LibraryThingConnector.backend.name == 'enterprise' || LibraryThingConnector.backend.name == 'atriuum' || LibraryThingConnector.backend.name == 'apollo' ) { LibraryThingConnector.info('not attaching scroll jumps'); return; } LibraryThingConnector.debug('attachScrollJumps'); var _sig = '.unbound_mega .unbound_nav a'; var scrolling_target_selector = 'body'; if ( typeof LibraryThingConnector.backend.getContainingDivId !== 'undefined') { LibraryThingConnector.containingDivId = LibraryThingConnector.backend.getContainingDivId(); LibraryThingConnector.info('containingDiv for scrollJumps from backend: ' + LibraryThingConnector.containingDivId); } if ( LibraryThingConnector.containingDivId ) { LibraryThingConnector.debug('srolling divid: ' + LibraryThingConnector.containingDivId + ' rather than body'); scrolling_target_selector = LibraryThingConnector.containingDivId; } LibraryThingConnector.utils.jQuery(scrolling_target_selector).not('.unbound_loaded').on('click', _sig, function(event) { var _hash = LibraryThingConnector.utils.jQuery(this).attr('href').replace('#',''); //Yams project if( LibraryThingConnector.backend.name == 'apollo' ) //because I can't figure out how to fork this; or rather how to fork and then minimize it appropriately. { var target = LibraryThingConnector.utils.jQuery('a[name=' + _hash + ']'); if (target.length) { LibraryThingConnector.utils.jQuery('html, body').stop().animate({ scrollTop: target.offset().top }, 1000); } if (event.preventDefault) { event.preventDefault(); } } else { var target = LibraryThingConnector.utils.jQuery('.unbound_mega a[name='+_hash+']'); if( target.length ) { LibraryThingConnector.utils.jQuery('html, body').stop().animate({ scrollTop: target.offset().top }, 1000); } if (event.preventDefault) { event.preventDefault(); } } return false; }); }; LibraryThingConnector.seeFullShelf = function(rows, columns, lsi_id, anchor) { LibraryThingConnector.debug('seeFullShelf'); var params = LibraryThingConnector.getParams(); LibraryThingConnector.debug(LibraryThingConnector.config); params['lsa_id'] = LibraryThingConnector.config.accountAA.lsom_lsa_id; if(Array.isArray(LibraryThingConnector.metadata['call_nums'])) { params['callnumber'] = LibraryThingConnector.metadata['call_nums'].join(','); } else { params['callnumber'] = LibraryThingConnector.metadata['call_nums']; } params['ss'] = 'ltfl_shelf_large'; if ( anchor ) { params['anchor'] = anchor; } if ( lsi_id ) { params['lsi_id'] = lsi_id; } params['sr'] = rows; params['sc'] = columns; params['product'] = 'unbound'; params['enrichment_type'] = 'shelf'; params['theme'] = 'grey'; // clean theme params['client'] = LibraryThingConnector.config.accountAA.syndetics_client; delete params['itemInfo']; delete params['container_widths']; delete params['container_widthAAS']; delete params['divs']; LibraryThingConnector.debug(params); var _lightbox_params = { title : LibraryThingConnector.translationstringsA.title_shelfbrowse } var url = LibraryThingConnector.LTFL_BASE_URL + 'shelfbrowse.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.debug('final seeFullShelf url: ' + url); LibraryThingConnector.openLightbox(url, _lightbox_params); }; LibraryThingConnector.seeAward = function(na_id) { var data = { type:'awards_award_clicked' }; LibraryThingConnector.recordStats(data); LibraryThingConnector.debug('seeMoreAwards'); var params = {}; params['workcode'] = LibraryThingConnector.workcode; params['type'] = 'award'; params['na_id'] = na_id; params['su_a_id'] = LibraryThingConnector.a_id; breadcrumb_url= LibraryThingConnector.BASE_URL + 'syndeticsunbound_lightbox.php?'; breadcrumb_url += LibraryThingConnector.utils.jQuery.param(params); // params['breadcrumb_back_url'] = breadcrumb_url; // var _lightbox_params = { title : LibraryThingConnector.translationstringsA.title_awards }; var url = LibraryThingConnector.BASE_URL + 'syndeticsunbound_lightbox.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.debug('final seeMoreAwards url: ' + url); LibraryThingConnector.openLightbox(url, _lightbox_params); }; /* ################################################## */ LibraryThingConnector.seeAuthorAuthorRec = function(workid,authorid, relative_request) { LibraryThingConnector.debug('seeAuthorAuthorRec'); var data = { type: 'lightbox_opened', 'similar.authorauthorrec.lightbox':1, }; relative_request = relative_request || false; LibraryThingConnector.recordStats(data); var params = LibraryThingConnector.getParams(); params['workcode'] = workid; params['version'] = LibraryThingConnector.version; params['authorid'] = authorid; params['type'] = 'authorauthorrec'; params['su_a_id'] = LibraryThingConnector.a_id; var _lightbox_params = { xtitle : LibraryThingConnector.translationstringsA.title_awards, title : 'About the Author' }; if (relative_request) { params['breadcrumb_back_url'] = relative_request; } params['su_catalog_url'] = encodeURIComponent(window.location.href); var url = LibraryThingConnector.BASE_URL + 'syndeticsunbound_lightbox.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.debug('final seeMoreAwards url: ' + url); if (relative_request) { LibraryThingConnector.goToURL(url); // TODO: change the lightbox title since we'd be calling this from within the lightbox } else { LibraryThingConnector.openLightbox(url, _lightbox_params); } }; LibraryThingConnector.lb_librarianpower_list = function(workid,listid,lslw_id) { if( LibraryThingConnector.context == 'lightbox') { LibraryThingConnector.info('lp lightbox from within lightbox - posting to top') window.top.parent.postMessage({"type":"lp_lightbox_open","workid":workid,"listid":listid,"lslw_id":lslw_id}, "*"); return; } LibraryThingConnector.debug('lb_librarianpower_list'); LibraryThingConnector.recordLightboxOpenedStat('lists'); if( lslw_id ) { LibraryThingConnector.info('recording ldw lb opened stat'); LibraryThingConnector.recordLightboxOpenedStat('bdw_listwidget'); } var params = { workcode: workid, listid : listid, type : 'librarianpower_list', page : 'list' }; var _lightbox_params = { title : LibraryThingConnector.translationstringsA.title_lists //title_lists="Librarian Recommends" } LibraryThingConnector.info('loading Lists at ' + LibraryThingConnector.LIBRARIAN_POWER_DOMAIN); var url = LibraryThingConnector.LIBRARIAN_POWER_DOMAIN + 'libpow_controller.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.openLightbox(url, _lightbox_params); }; LibraryThingConnector.lb_librarianpower_addtolist = function() { LibraryThingConnector.debug('lb_librarianpower_list'); var params = { type: 'librarianpower_addtolist', 'callnumber_resolved': LibraryThingConnector.callnumber_resolved, //page : 'list' }; var _lightbox_params = { title : 'Lists' } LibraryThingConnector.info('loading Lists at ' + LibraryThingConnector.LIBRARIAN_POWER_DOMAIN); var url = LibraryThingConnector.LIBRARIAN_POWER_DOMAIN + 'lp/'+LibraryThingConnector.a_id+'.'+LibraryThingConnector.i_id+'/catalogaddtolist?'; url += LibraryThingConnector.utils.jQuery.param(params); //alert(url); LibraryThingConnector.openLightbox(url, _lightbox_params); }; LibraryThingConnector.seeMoreSimilar = function() { LibraryThingConnector.debug('seeMoreSimilar'); var params = {}; params['workcode'] = LibraryThingConnector.workcode; params['type'] = 'similar'; LibraryThingConnector.globals.enrichment_opened = 'similar'; var _lightbox_params = { title : LibraryThingConnector.translationstringsA.title_similar } var url = LibraryThingConnector.BASE_URL + 'syndeticsunbound_lightbox.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.debug('final seeMoreSimilar url: ' + url); LibraryThingConnector.openLightbox(url, _lightbox_params); }; LibraryThingConnector.lb_librarianpower_seemorelists = function() { LibraryThingConnector.globals.enrichment_opened = 'lists'; var params = LibraryThingConnector.getParams(); // not sure if we even need this part for this function if( LibraryThingConnector.context == 'lightbox') { LibraryThingConnector.info('lp lightbox from within lightbox - posting to top'); var args = Object.assign({}, params, {"type":"lp_lightbox_open","page":"item"}) window.top.parent.postMessage(args, "*"); return; } LibraryThingConnector.debug('lb_librarianpower_list item'); LibraryThingConnector.recordLightboxOpenedStat('lists_item'); //params['workcode'] = LibraryThingConnector.workcode; params['type'] = 'librarianpower_list'; params['page'] = 'item'; var _lightbox_params = { title : LibraryThingConnector.translationstringsA.title_lists //title_lists="Librarian Recommends" } LibraryThingConnector.info('loading more Lists for item at ' + LibraryThingConnector.LIBRARIAN_POWER_DOMAIN); var url = LibraryThingConnector.LIBRARIAN_POWER_DOMAIN + 'libpow_controller.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.openLightbox(url, _lightbox_params); } LibraryThingConnector.lb_librarianpower_testpage = function() { LibraryThingConnector.debug('lb_librarianpower_list');/**/ var params = { type: 'librarianpower_addtolist', 'callnumber_resolved': LibraryThingConnector.callnumber_resolved, page : 'test_items' }; var _lightbox_params = { title : 'Lists', //TODO LAUREN: title : LibraryThingConnector.translationstringsA.title_lists //title_lists="Librarian Recommends" ?? } LibraryThingConnector.info('loading Lists at ' + LibraryThingConnector.LIBRARIAN_POWER_DOMAIN); var url = LibraryThingConnector.LIBRARIAN_POWER_DOMAIN + 'libpow_controller.php?'; //var url = LibraryThingConnector.BASE_URL + 'action_libpow_catalogaddtolist.php?'; url += LibraryThingConnector.utils.jQuery.param(params); //alert(url); LibraryThingConnector.openLightbox(url, _lightbox_params); }; LibraryThingConnector.lb_librarianpower_lists = function() { var url = '/librarianpower_lists.php'; var params = { type: 'librarianpower_lists' }; var params = { type: 'librarianpower_user', id: 1 }; var _lightbox_params = { title : 'Lists' } LibraryThingConnector.info('loading Lists at ' + LibraryThingConnector.LIBRARIAN_POWER_DOMAIN); var url = LibraryThingConnector.LIBRARIAN_POWER_DOMAIN + 'syndeticsunbound_lightbox.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.openLightbox(url, _lightbox_params); }; /* ################################################## */ LibraryThingConnector.seeMoreAwards_textonly = function() { var theLink = LibraryThingConnector.utils.jQuery('a.unbound_seeMoreAwards_textonly'); if( LibraryThingConnector.utils.jQuery('.unbound_books_textonly').hasClass('unbound_seemore_overflow_show') ) { LibraryThingConnector.utils.jQuery('.unbound_books_textonly').removeClass('unbound_seemore_overflow_show'); theLink.html( theLink.data('texton') ) } else { LibraryThingConnector.utils.jQuery('.unbound_books_textonly').addClass('unbound_seemore_overflow_show'); theLink.html( theLink.data('textoff') ) } return false; }; LibraryThingConnector.seeMoreAwards = function() { LibraryThingConnector.debug('seeMoreAwards'); var params = {}; params['workcode'] = LibraryThingConnector.workcode; params['type'] = 'awards'; var _lightbox_params = { title : LibraryThingConnector.translationstringsA.title_awards } var url = LibraryThingConnector.BASE_URL + 'syndeticsunbound_lightbox.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.debug('final seeMoreAwards url: ' + url); LibraryThingConnector.openLightbox(url, _lightbox_params); }; LibraryThingConnector.expandAllAwards = function(divAwardType) { LibraryThingConnector.info('syndeticsunbound_connector.js->expandAllAwards()'); var awardDiv=LibraryThingConnector.utils.jQuery('.'+divAwardType); var hiddenAwards= LibraryThingConnector.utils.jQuery('.unbound_hidden_award', awardDiv); var seeMore=LibraryThingConnector.utils.jQuery('.unbound_award_seemoreless', awardDiv); var seeLess=LibraryThingConnector.utils.jQuery('.unbound_award_seemoreless.ua_seeless', awardDiv); hiddenAwards.slideDown(); seeMore.hide(); seeLess.show(); }; LibraryThingConnector.collapseAwards = function(divAwardType) { LibraryThingConnector.info('syndeticsunbound_connector.js->expandAllAwards()'); var awardDiv=LibraryThingConnector.utils.jQuery('.'+divAwardType); var hiddenAwards= LibraryThingConnector.utils.jQuery('.unbound_hidden_award', awardDiv); var seeMore=LibraryThingConnector.utils.jQuery('.unbound_award_seemoreless', awardDiv); var seeLess=LibraryThingConnector.utils.jQuery('.unbound_award_seemoreless.ua_seeless', awardDiv); hiddenAwards.slideUp(); seeMore.show(); seeLess.hide(); }; LibraryThingConnector.seeMoreLTSeries = function() { alert('not made'); return false; } LibraryThingConnector.goToURL = function(url, target) { if (target === '_top') { window.top.location = url; } else if (target === '_parent') { parent.location = url; } else if (target != null) { window.open(url, target); } else { window.location.href = url; } }; // relative_request = true if you are calling this from within the ligthbox already. LibraryThingConnector.seeLTSeries = function(ck_id, relative_request) { var data = { type:'ltseries_series_clicked' }; relative_request = relative_request || false; LibraryThingConnector.recordStats(data); LibraryThingConnector.debug('seeMoreLTSeries'); var params = {}; params['workcode'] = LibraryThingConnector.workcode; params['ck_id'] = ck_id; params['version'] = LibraryThingConnector.version; params['type'] = 'ltseriesone'; params['su_a_id'] = LibraryThingConnector.a_id; params['itemdetailsA_lang'] = LibraryThingConnector.itemdetailsA_lang; params['itemdetailsA_media'] = LibraryThingConnector.itemdetailsA_media; if (relative_request) { params['breadcrumb_back_url'] = relative_request; } var _lightbox_params = { title : LibraryThingConnector.translationstringsA.title_ltseries }; var url = LibraryThingConnector.BASE_URL + 'syndeticsunbound_lightbox.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.debug('final seeMoreLTSeries url: ' + url); // relative // "https://athena.librarything.com/syndeticsunbound/syndeticsunbound_lightbox.php?workcode=0&ck_id=379351&type=ltseriesone&itemdetailsA_lang=&itemdetailsA_media=" // openlightbox // "https://athena.librarything.com/syndeticsunbound/syndeticsunbound_lightbox.php?workcode=2742161&ck_id=1102663&type=ltseriesone&itemdetailsA_lang=eng&itemdetailsA_media=1.1.2" //LibraryThing.lightbox.off(); if (relative_request) { LibraryThingConnector.goToURL(url); // TODO: change the lightbox title since we'd be calling this from within the lightbox } else { LibraryThingConnector.openLightbox(url, _lightbox_params); } location.replace }; // relative_request = true if you are calling this from within the ligthbox already. LibraryThingConnector.seeLTnewSeries = function(sg_id, relative_request,enrichment_type) { relative_request = relative_request || false; enrichment_type = enrichment_type || false; var data = { type: 'lightbox_opened' }; if ( enrichment_type ) { data[enrichment_type] = 1; } LibraryThingConnector.recordStats(data); LibraryThingConnector.debug('seeMoreLTSeries'); var params = {}; params['workcode'] = LibraryThingConnector.workcode; params['sg_id'] = sg_id; params['version'] = LibraryThingConnector.version; params['type'] = 'ltnewseriesone'; params['su_a_id'] = LibraryThingConnector.a_id; params['su_catalog_url'] = LibraryThingConnector.metadata.catalog_url; params['itemdetailsA_lang'] = LibraryThingConnector.itemdetailsA_lang; params['itemdetailsA_media'] = LibraryThingConnector.itemdetailsA_media; if (relative_request) { params['breadcrumb_back_url'] = relative_request; } var _lightbox_params = { title : LibraryThingConnector.translationstringsA.title_ltseries }; var url = LibraryThingConnector.BASE_URL + 'syndeticsunbound_lightbox.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.debug('final seeMoreLTSeries url: ' + url); // relative // "https://athena.librarything.com/syndeticsunbound/syndeticsunbound_lightbox.php?workcode=0&ck_id=379351&type=ltseriesone&itemdetailsA_lang=&itemdetailsA_media=" // openlightbox // "https://athena.librarything.com/syndeticsunbound/syndeticsunbound_lightbox.php?workcode=2742161&ck_id=1102663&type=ltseriesone&itemdetailsA_lang=eng&itemdetailsA_media=1.1.2" //LibraryThing.lightbox.off(); if (relative_request) { LibraryThingConnector.goToURL(url); // TODO: change the lightbox title since we'd be calling this from within the lightbox } else { LibraryThingConnector.openLightbox(url, _lightbox_params); } location.replace }; LibraryThingConnector.seeMoreReviews = function() { LibraryThingConnector.debug('seeMoreReviews'); var connnectorParams = LibraryThingConnector.getParams(); var params = {}; params['workcode'] = LibraryThingConnector.workcode; params['type'] = 'reviews'; params['product'] = 'unbound'; params['a_id'] = LibraryThingConnector.a_id; params['enrichment_type'] = 'reviews'; params['lstoken'] = LibraryThingConnector.lsa_id; if (LibraryThingConnector.a_id == 359 && LibraryThingConnector.metadata.scope[0] == 'nelson') { LibraryThingConnector.info('using Nelson 350 for reviews lsa_id'); params['lstoken'] = 350; } params['author'] = connnectorParams['author']; params['title'] = connnectorParams['title']; params['client'] = LibraryThingConnector.config.accountAA.syndetics_client; if( LibraryThingConnector.metadata['accession'] && LibraryThingConnector.utils.jQuery.isArray(LibraryThingConnector.metadata['accession'])) { params['accession'] = LibraryThingConnector.metadata['accession'][0]; } else if ( LibraryThingConnector.metadata['accession']) { params['accession'] = LibraryThingConnector.metadata['accession']; } if(typeof LibraryThingConnector.metadata.first_isbn !== 'undefined') { params['winning_isbn'] = LibraryThingConnector.metadata.first_isbn; } if(typeof LibraryThingConnector.isbns !== 'undefined') { params['isbn'] = LibraryThingConnector.isbns.join(); } var _lightbox_params = { title : LibraryThingConnector.translationstringsA.title_patronreviews } var url = LibraryThingConnector.LTFL_BASE_URL + 'reviews.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.debug('final seeMoreReviews url: ' + url); LibraryThingConnector.openLightbox(url, _lightbox_params); }; LibraryThingConnector.seeMoreSimilar = function() { LibraryThingConnector.debug('seeMoreSimilar'); var params = {}; params['workcode'] = LibraryThingConnector.workcode; params['type'] = 'similar'; LibraryThingConnector.globals.enrichment_opened = 'similar'; var _lightbox_params = { title : LibraryThingConnector.translationstringsA.title_similar } var url = LibraryThingConnector.BASE_URL + 'syndeticsunbound_lightbox.php?'; url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.debug('final seeMoreSimilar url: ' + url); LibraryThingConnector.openLightbox(url, _lightbox_params); }; LibraryThingConnector.openSyndeticsLightbox = function(title,params, args) { LibraryThingConnector.globals.enrichment_opened = params['enrichment_type']; //var url = LibraryThingConnector.SYNDETICS_DOMAIN + '/unbound_lightbox.php?su_catalog_language_code='+params['su_catalog_language_code']+'&enhancement='+params['enrichment_type']+'&id='+LibraryThingConnector.client+'&isbn='+params['isbn']+'&su_isbns='+params['su_isbns']+'&su_workcode='+params['workcode']+'&su_enrichment_type='+params['enrichment_type']+'&su_catalog_url'+'&su_a_id='+LibraryThingConnector.a_id+'&active_id=toc&su_catalog_url='+encodeURIComponent(window.location.href); var url = LibraryThingConnector.SYNDETICS_DOMAIN + '/unbound_lightbox.php?su_catalog_language_code='+params['su_catalog_language_code']+'&enhancement='+params['enrichment_type']+'&id='+LibraryThingConnector.client+'&isbn='+params['isbn']+'&su_isbns='+params['su_isbns']+'&itemdetailsA_lang='+LibraryThingConnector.itemdetailsA_lang+'&itemdetailsA_media='+LibraryThingConnector.itemdetailsA_media+'&su_workcode='+params['workcode']+'&su_enrichment_type='+params['enrichment_type']+'&su_catalog_url'+'&su_a_id='+LibraryThingConnector.a_id+'&active_id=toc&su_catalog_url='+encodeURIComponent(window.location.href)+'&su_i_id='+LibraryThingConnector.i_id+'&su_upcs='+encodeURIComponent(params['su_upc'])+'&upc='+encodeURIComponent(params['upc'])+'&su_issns='+encodeURIComponent(params['su_issn']); if ( typeof args != 'undefined') { LibraryThingConnector.info('including args ' + args); url += args; } // var url = LibraryThingConnector.SYNDETICS_DOMAIN + '/unbound_lightbox.php?'; // url += LibraryThingConnector.utils.jQuery.param(params); LibraryThingConnector.debug('final syndetics lightbox url: ' + url); LibraryThingConnector.openSearchResultLightbox(title,url); }; LibraryThingConnector.attachLightboxFocusHandler = function() { LibraryThingConnector.info('attachLightboxFocusHandler);') LibraryThingConnector.utils.jQuery(document).bind('focusin', function (ev) { if (LibraryThingConnector.utils.jQuery(ev.target).parents('#LT_LB').length === 0 ) { LibraryThingConnector.info('SU: focus moved out of lightbox, refocusing on lightbox'); /* TODO: ch - this is causing errors because it is an infinite loop of focus events. */ /* ch - reinstating this to handle a11y events properly while doing vega overview. 6-2023 */ LibraryThingConnector.utils.jQuery('#LT_LB_title').focus(); ev.preventDefault(); return false; } else { LibraryThingConnector.info('SU: focused into lightbox'); } }); }; LibraryThingConnector.detachLightboxFocusHandler = function() { LibraryThingConnector.info('detachLightboxFocusHandler'); LibraryThingConnector.utils.jQuery(document).unbind('focusin'); }; LibraryThingConnector.lightboxCallbackReady = function () { LibraryThingConnector.info('lightbox callbackReady'); // maintain focus within lightbox modal LibraryThingConnector.attachLightboxFocusHandler(); var LT_LB = LibraryThingConnector.utils.jQuery('#LT_LB').get(0); LibraryThingConnector.utils.jQuery(LT_LB).focus(); setTimeout(function () { // ENTER on lightbox close var LT_LB_close = LibraryThingConnector.utils.jQuery('#LT_LB_close').get(0); LibraryThingConnector.utils.jQuery('#LT_LB_close').click(function(ev) { LibraryThingConnector.detachLightboxFocusHandler(); }); LibraryThingConnector.utils.jQuery(document).keypress(function (ev) { var keycode = ev.keyCode || ev.which; if (ev.target == LT_LB_close && keycode == '13') { LibraryThingConnector.info('ENTER on lightbox close'); LibraryThing.lightbox.off(); LibraryThingConnector.detachLightboxFocusHandler(); // return focus to opening button var last_enrichment_opened = LibraryThingConnector.globals.enrichment_opened; LibraryThingConnector.info('returning focus to last enrichment btn opened:'+last_enrichment_opened); var content_selector = 'unbound_'+last_enrichment_opened; LibraryThingConnector.utils.jQuery('.'+content_selector).find('.unbound_seemore_link,.unbound_lightbox').focus(); } }); }, 2000); }; /** * wraps lt_lightbox code * @param url * @param params */ LibraryThingConnector.openLightbox = function (url, params, rawUrlB) { if( !params ) { params = { width: 300, height: 300 }; } if ( typeof rawUrlB == 'undefined' ) { rawUrlB = false; } LibraryThingConnector.debug('rawUrlB: ' + rawUrlB); // override these for sure. params.fullscreen = true; params.method = 'iframe'; params.modal = false; params.callbackReady = LibraryThingConnector.lightboxCallbackReady(); //params.title = params.title | 'Syndetics Unbound'; // if you don't supply the params object then it uses a default width and // then resizes vertically to fit the content. // pass through metadata so Connector within lightbox has access var urlparams = LibraryThingConnector.getParams(); // cull params we don't need // delete urlparams['itemInfo']; delete urlparams['container_widths']; delete urlparams['container_widthAAS']; delete urlparams['divs']; urlparams['workcode'] = LibraryThingConnector.workcode; urlparams['enrichment_type'] = LibraryThingConnector.globals.enrichment_type; urlparams['catalog_url'] = window.location.href; var urlparams_temp = {}; for (var key in urlparams) { if (!urlparams.hasOwnProperty(key)) continue; var val = urlparams[key]; if ( key.match(/su_/)) { urlparams_temp[key] = val; } else { urlparams_temp['su_'+key] = val; } } urlparams = urlparams_temp; /* LibraryThingConnector.utils.jQuery.each(urlparams, function(key, value) { urlparams['su_'+key] = value; delete urlparams[key]; }); */ LibraryThingConnector.debug('params for lightbox url:'); LibraryThingConnector.debug(urlparams); if( !rawUrlB ) { url += '&' + LibraryThingConnector.utils.jQuery.param(urlparams); } LibraryThingConnector.debug('openLightbox to url: ' + url); //$ = LibraryThingConnector.utils.jQuery; if( LibraryThingConnector.backend.name == 'eds' ) { // this runs from within iframe so we don't want window.top window.LibraryThing.lightbox.open(url, params); } else { LibraryThing.lightbox.open(url, params); } LibraryThingConnector.utils.jQuery('#LT_LB_title').focus(); }; LibraryThingConnector.megaDivHTML = ''; LibraryThingConnector.footerHTML = ''; LibraryThingConnector.hoverDivHTML = ''; LibraryThingConnector.megadiv_id = ''; LibraryThingConnector.megaDivInsertedB = false; LibraryThingConnector.metadataExtractedB = false; LibraryThingConnector.LTFLWidgetsLoadedB = false; LibraryThingConnector.loadingLTFLWidgetsB = false; LibraryThingConnector.loadingSyndeticsWidgetsB = false; LibraryThingConnector.retrySyndeticsB = false; LibraryThingConnector.syndeticsNoDataCalledB = false; LibraryThingConnector.contentReadyB = false; LibraryThingConnector.eventListenersAddedB = false; LibraryThingConnector.linkContext = {}; LibraryThingConnector.contentChangedHandlerAddedB = false; LibraryThingConnector.SyndeticsWidgetsLoadedB = false; LibraryThingConnector.shouldLoadSyndeticsWidgets = true; LibraryThingConnector.hoverData = {}; LibraryThingConnector.i_id = null; LibraryThingConnector.workcode = 0; LibraryThingConnector.pageStatsRecordedB = false; LibraryThingConnector.statsRecordLTB = false; LibraryThingConnector.statsRecordLPQ = false; LibraryThingConnector.searchStatsRecordedB = false; LibraryThingConnector.searchStatsRecordLTB = false; LibraryThingConnector.searchStatsRecordLPQ = false; LibraryThingConnector.contentReady_Intervalh = null; LibraryThingConnector.BDW_loadedB = false; LibraryThingConnector.contentReady_tries = 0; LibraryThingConnector.contentReady_max_tries = 50; LibraryThingConnector.unboundContentAddedCalledB = false; LibraryThingConnector.containingDivId = null; LibraryThingConnector.containingEl = null; LibraryThingConnector.init_abortedB = false; LibraryThingConnector.AISearchLoadedB = false; LibraryThingConnector.hoverAddedB = false; LibraryThingConnector.contentReadyInterval = 500; // ms to retry extracting metadata and inserting mega div if content not ready LibraryThingConnector.stats = { }; // houses enrichment/load/lightbox statistics LibraryThingConnector.errors = []; // errors LibraryThingConnector.globals = { }; // container for globals LibraryThingConnector.isMegaDivInserted = function () { return LibraryThingConnector.megaDivInsertedB; }; LibraryThingConnector.isMetadataExtracted = function () { return LibraryThingConnector.metadataExtractedB; }; LibraryThingConnector.areLTFLWidgetsLoaded = function() { return LibraryThingConnector.LTFLWidgetsLoadedB; }; LibraryThingConnector.areSyndeticsWidgetsLoaded = function() { return LibraryThingConnector.SyndeticsWidgetsLoadedB; }; LibraryThingConnector.insertMegaDiv = function (html) { LibraryThingConnector.info('inserting megadiv with html'); LibraryThingConnector.info(html); // check for existing syndeticsunbound megadiv var syndetics_unbound_div = LibraryThingConnector.utils.jQuery('#syndetics_unbound'); var insertNodeDetail = null; if ( syndetics_unbound_div.length ) { LibraryThingConnector.info('existing su megadiv found'); insertNodeDetail = LibraryThingConnector.utils.jQuery(syndetics_unbound_div).get(0); } else if(typeof LibraryThingConnector.metadata !== 'undefined' && LibraryThingConnector.metadata && typeof LibraryThingConnector.metadata.unbound_insertNode !== 'undefined' && LibraryThingConnector.utils.jQuery(LibraryThingConnector.metadata.unbound_insertNode).length > 0 ) { // a straight jquery selector rather than an #id insertNodeDetail = LibraryThingConnector.utils.jQuery(LibraryThingConnector.metadata.unbound_insertNode).get(0); } else if(typeof LibraryThingConnector.metadata !== 'undefined' && LibraryThingConnector.metadata && typeof LibraryThingConnector.metadata.unbound_insertNode !== 'undefined' && LibraryThingConnector.utils.jQuery("#" + LibraryThingConnector.metadata.unbound_insertNode).length > 0 ) { insertNodeDetail = LibraryThingConnector.utils.jQuery("#" + LibraryThingConnector.metadata.unbound_insertNode).get(0); } else { LibraryThingConnector.info('su megadiv from getinsertNodeFull'); insertNodeDetail = LibraryThingConnector.getInsertNodeFull(); } if (insertNodeDetail) { LibraryThingConnector.info('inserting mega div into element'); LibraryThingConnector.info(insertNodeDetail); LibraryThingConnector.utils.jQuery(insertNodeDetail).append(html); // set flag to say inserted LibraryThingConnector.megaDivInsertedB = true; LibraryThingConnector.addHoverToBody(); // Custom Event to say that MegaDiv is ready LibraryThingConnector.dispatchEvent('megaDivReadyEvent'); } else { // still add hover for split divs LibraryThingConnector.addHoverToBody(); LibraryThingConnector.info('no div found for insertNodeDetail'); } LibraryThingConnector.dispatchEvent('LibraryThingConnectorInitedEvent'); }; /** * handle custom events dispatching for IE and non-IE * @param eventName * @param data */ LibraryThingConnector.dispatchEvent = function (eventName, data) { LibraryThingConnector.utils.jQuery(document).trigger(eventName,data); }; LibraryThingConnector.addIdentifiers = function(element_class, identifier_type, identifiers) { LibraryThingConnector.info('addIdentifiers for identifier_type: '+identifier_type+' for element_class: ' + element_class); LibraryThingConnector.debug(identifiers); LibraryThingConnector.debug(identifier_type); if( identifier_type == 'isbn') { LibraryThingConnector.isbn_identifiers[element_class] = identifiers; } if( identifier_type == 'upc') { LibraryThingConnector.upc_identifiers[element_class] = identifiers; } if( identifier_type == 'issn') { LibraryThingConnector.issn_identifiers[element_class] = identifiers; } }; LibraryThingConnector.getIdentifiers = function (identifier_type) { LibraryThingConnector.info('getIdentifiers type:'+identifier_type); var all_identifiers = []; if( identifier_type == 'isbn') { LibraryThingConnector.utils.jQuery.each(LibraryThingConnector.isbn_identifiers, function (element_class, identifiers) { LibraryThingConnector.utils.jQuery.each(identifiers, function (i, identifier) { if( identifier != '') { LibraryThingConnector.debug('found identifier: '+identifier + ' for identifier_type:'+identifier_type); all_identifiers.push(identifier); } }); }); } else if(identifier_type == 'upc') { LibraryThingConnector.utils.jQuery.each(LibraryThingConnector.upc_identifiers, function (element_class, identifiers) { LibraryThingConnector.utils.jQuery.each(identifiers, function (i, identifier) { LibraryThingConnector.debug('found identifier: '+identifier + ' for identifier_type:'+identifier_type); all_identifiers.push(identifier); }); }); } else if(identifier_type == 'issn') { LibraryThingConnector.utils.jQuery.each(LibraryThingConnector.issn_identifiers, function (element_class, identifiers) { LibraryThingConnector.utils.jQuery.each(identifiers, function (i, identifier) { LibraryThingConnector.debug('found identifier: '+identifier + ' for identifier_type:'+identifier_type); all_identifiers.push(identifier); }); }); } LibraryThingConnector.info('getIdentifiers: returning '+all_identifiers.length + ' identifiers of type:'+identifier_type); return all_identifiers; }; LibraryThingConnector.harvestIdentifiers = function (element_selector, element_class) { // harvest idenifiers LibraryThingConnector.info('finding identifiers for element_selector: ' + element_selector); var isbn_identifiers = []; var upc_identifiers = []; var issn_identifiers = []; LibraryThingConnector.utils.jQuery(element_selector).find('[data-id]').each(function(i,n) { var id = LibraryThingConnector.utils.jQuery(n).data('id'); if( id ) { var identifier = LibraryThingConnector.extractIdentifierFromIdString(id); var identifier_type = LibraryThingConnector.extractIdentifierTypeFromIdString(id); LibraryThingConnector.debug('identifier: ' + identifier + ' identifier_type:'+identifier_type); if( identifier_type == 'isbn') { isbn_identifiers.push(identifier); } else if( identifier_type == 'upc') { upc_identifiers.push(identifier); } if( identifier_type == 'issn') { issn_identifiers.push(identifier); } } }); // Add the identifiers LibraryThingConnector.addIdentifiers(element_class, 'isbn', isbn_identifiers); LibraryThingConnector.addIdentifiers(element_class, 'upc', upc_identifiers); LibraryThingConnector.addIdentifiers(element_class, 'issn', issn_identifiers); }; LibraryThingConnector.utils.base64decode = function(element_content) { // from: https://scotch.io/tutorials/how-to-encode-and-decode-strings-with-base64-in-javascript var Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function (e) { var t = ""; var n, r, i, s, o, u, a; var f = 0; e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function (e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace(/[^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function (e) { e = e.replace(/rn/g, "n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function (e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } } return Base64.decode(element_content); }; LibraryThingConnector.useMegadiv = function(element_class) { var enrichment_type = LibraryThingConnector.extractEnrichmentTypeFromClass(element_class); var enrichment_class = 'unbound_'+enrichment_type; var enrichment_class_count = LibraryThingConnector.utils.jQuery('.' + enrichment_class).length; if( LibraryThingConnector.backend.name == 'enterprise' ) // preserve containingEl scope for enterprise modals { enrichment_class_count = LibraryThingConnector.utils.jQuery('.' + enrichment_class,LibraryThingConnector.containingEl).length; } var usemegadivB = true; if ( typeof LibraryThingConnector.config.settingsA.advancedA.usemegadiv !== 'undefined' && LibraryThingConnector.config.settingsA.advancedA.usemegadiv == 0) { usemegadivB = false; } if ( enrichment_class_count > 1) { usemegadivB = false; } if( LibraryThingConnector.utils.jQuery('.unbound_ltseries').length == 1 && LibraryThingConnector.utils.jQuery('.unbound_series').length == 1 ) { usemegadivB = false; } // force megadiv for biblionix/apollo if( LibraryThingConnector.backend.name == 'apollo' && enrichment_type != 'summary') { // except Summary usemegadivB = true; } return usemegadivB; }; LibraryThingConnector.getMegaDivEl = function() { var megadiv_el = LibraryThingConnector.utils.jQuery('#'+LibraryThingConnector.megadiv_id).get(0); if (megadiv_el ) { return megadiv_el; } return null; }; LibraryThingConnector.getEnrichmentElement = function(element_class) { var _unbound_element = null; LibraryThingConnector.debug('getEnrichmentElement: ' + element_class); var enrichment_type = LibraryThingConnector.extractEnrichmentTypeFromClass(element_class); // get the current megadiv which should have original megadiv_id, we need to scope content changes to that in case there are other megadivs showing var current_megadiv_el = LibraryThingConnector.getMegaDivEl(); if( typeof LibraryThingConnector.backend.currentMegaDiv !== 'undefined' ) { current_megadiv_el = LibraryThingConnector.backend.currentMegaDiv(); } // Get the main content div // check for split out element of this element_class var enrichment_class = 'unbound_'+enrichment_type; var enrichment_class_count = LibraryThingConnector.utils.jQuery('.' + enrichment_class, current_megadiv_el).length; var usemegadivB = LibraryThingConnector.useMegadiv(element_class); if( !usemegadivB) { // remove existing one, if megadiv is found if( current_megadiv_el ) { LibraryThingConnector.utils.jQuery('.' + enrichment_class, current_megadiv_el).remove(); } // hide SU nav LibraryThingConnector.info('hiding SU nav for ' + enrichment_class + ' of enrichment_type: ' + enrichment_type); LibraryThingConnector.utils.jQuery('.unbound_nav_item_'+enrichment_type,current_megadiv_el).css('display','none'); // adding content classes so found for hover harvesting if( enrichment_class == 'unbound_ltseries') { enrichment_class = 'unbound_series'; } LibraryThingConnector.utils.jQuery('.'+enrichment_class).addClass('unbound_content').addClass('unbound_splitdiv').addClass(enrichment_class+'_content').addClass('unbound_mega_aid_'+LibraryThingConnector.a_id).addClass(LibraryThingConnector.backend.name); LibraryThingConnector.utils.jQuery('.'+enrichment_class).attr('breakpoints', '420 480 560 693 700 768 960 1200'); _unbound_element = LibraryThingConnector.utils.jQuery('.'+enrichment_class); if( LibraryThingConnector.backend.name == 'apollo') { _unbound_element = LibraryThingConnector.utils.jQuery('.' + enrichment_class,LibraryThingConnector.containingEl); } // check for _header elements like .unbound_similar_header var header_class = enrichment_class + '_header'; if( LibraryThingConnector.utils.jQuery('.'+header_class).length && !LibraryThingConnector.utils.jQuery('h3.'+header_class).length) { LibraryThingConnector.info('found header class:'+header_class+', adding header h3'); LibraryThingConnector.utils.jQuery('.'+header_class).append('
'); } } else { _unbound_element = LibraryThingConnector.utils.jQuery('.'+element_class, current_megadiv_el).not('.unbound_loaded'); } return { '_unbound_element':_unbound_element, 'usemegadivB':usemegadivB }; }; LibraryThingConnector.updateEnrichmentsShown = function(element_class,_unbound_element) { var enrichment_type = LibraryThingConnector.extractEnrichmentTypeFromClass(element_class); LibraryThingConnector.stats.page_loaded = 1; if (typeof LibraryThingConnector.stats.enrichments_count == 'undefined') { LibraryThingConnector.stats.enrichments_count = 0; } if (!element_class.match(/nav_item|header/)) // only for content elements { if (typeof LibraryThingConnector.stats.enrichments_shown == 'undefined') { LibraryThingConnector.stats.enrichments_shown = []; } LibraryThingConnector.stats.enrichments_shown.push(enrichment_type); LibraryThingConnector.stats.enrichments_count += 1; var count = _unbound_element.find('.unbound_cover').length; // counting covers; if (enrichment_type == 'patronreviews') { count = _unbound_element.find('.unbound_review').length; // counting reviews } /* This is basically not doing anything. Not everything has covers, and it only counts two reviews for the patron reviews, max. If we want the data, we should collect it on the PHP side. (The review count is, however, used to determined whether to show the reviews box for libraries that want it. So keep that.) */ LibraryThingConnector.stats[element_class] = { 'present': true, 'count': count }; if( enrichment_type == 'lists') { var count = LibraryThingConnector.utils.jQuery('.unbound_lists').find('.libpow_list_infobox').length; var listids = []; LibraryThingConnector.utils.jQuery('.unbound_lists').find('.libpow_list_infobox').each(function(i,n){ listids.push(LibraryThingConnector.utils.jQuery(n).data('listid')); }); LibraryThingConnector.stats[element_class] = { 'present': true, 'count': count, 'listids':listids, }; } } }; LibraryThingConnector.addRawContent = function(element_class, element_content) { var element_megadivAA = LibraryThingConnector.getEnrichmentElement(element_class); element_megadivAA['_unbound_element'].html(element_content); var _unbound_element = element_megadivAA['_unbound_element']; // record stats LibraryThingConnector.updateEnrichmentsShown(element_class,_unbound_element); return element_megadivAA; }; LibraryThingConnector.addContent = function (element_class, element_content) { LibraryThingConnector.info('addContent: '+element_class); var _unbound_element = null; var usemegadivB = LibraryThingConnector.useMegadiv(element_class); if( typeof element_content !== 'undefined' ) { if( !usemegadivB && element_class === 'unbound_ltseries_content') { LibraryThingConnector.info('addContent: using unbound_series for unbound_ltseries in splitdiv'); element_class = 'unbound_series_content'; } var content_decoded = LibraryThingConnector.utils.base64decode(element_content); // set the content if (content_decoded) { var element_megadivAA = LibraryThingConnector.addRawContent(element_class, content_decoded); _unbound_element = element_megadivAA['_unbound_element']; usemegadivB = element_megadivAA['usemegadivB']; } } LibraryThingConnector.debug('adding content for class: ' + element_class); var enrichment_type = LibraryThingConnector.extractEnrichmentTypeFromClass(element_class); var endTime = new Date().getTime(); if( !_unbound_element) { var element_megadivAA = LibraryThingConnector.getEnrichmentElement(element_class); _unbound_element = element_megadivAA['_unbound_element']; usemegadivB = LibraryThingConnector.useMegadiv(element_class); } // LibraryThingConnector.timing.content.push({enrichment_type:enrichment_type, end:endTime}); // show the element header? var current_megadiv_el = LibraryThingConnector.getMegaDivEl(); if ( usemegadivB ) { // show the Unbound Contents header var nav_selector = '.unbound_nav_item.unbound_nav_item_' + enrichment_type; var nav_selector_el = LibraryThingConnector.utils.jQuery(nav_selector); LibraryThingConnector.info('showing nav for selector: ' + nav_selector); if( LibraryThingConnector.backend.name === 'leganto' ) { LibraryThingConnector.info('Using leganto scroll fix'); nav_selector_el.on('click', function() { LibraryThingConnector.utils.jQuery('.item-view'). animate({ scrollTop: LibraryThingConnector.utils.jQuery("a[name=unbound_nav_"+enrichment_type+"]").offset().top }, 1000); }); } LibraryThingConnector.utils.jQuery(nav_selector,current_megadiv_el).not('.unbound_loaded').fadeIn(); var unbound_header = _unbound_element.parent('.unbound_element').find('.unbound_header'); LibraryThingConnector.info('showing header:'); LibraryThingConnector.info(unbound_header); unbound_header.fadeIn(); // show badge if any html prsent var unbound_badge = _unbound_element.find('.unbound_badge'); if( unbound_badge.html() != '' ) { unbound_badge.show(); } } else // show .unbound_header if found { var enrichment_type = LibraryThingConnector.extractEnrichmentTypeFromClass(element_class); var header_class = 'unbound_' + enrichment_type + '_header'; LibraryThingConnector.info('showing header '+header_class); // do not scope to megadiv: also catch split div headers LibraryThingConnector.utils.jQuery('h3.unbound_header.'+header_class).css('display','block'); } // Harvest identifiers (for building hovers) LibraryThingConnector.harvestIdentifiers('.'+element_class, element_class); // add in hovers LibraryThingConnector.attachHoverToCovers('.'+element_class); // add in expand see more in .unbound_truncate if (LibraryThingConnector.backend.name == 'enterprise' && LibraryThingConnector.backend.isUnboundInfrastructureMigration() && LibraryThingConnector.backend.delayExpandsAttaching()) { // needs to happen later, in backend } else { LibraryThingConnector.attachExpands('.'+element_class); } // lightbox opening LibraryThingConnector.attachLightboxHandler(_unbound_element); if( _unbound_element == 'unbound_author_content') { LibraryThingConnector.insertAuthorImage(); } /* turn off spotify support by turning off this loop (change true to false below) */ if (false && element_class == 'unbound_audiovideo_content') { LibraryThingConnector.audio = new Audio(); // do spotify lookups to provide previews var searchAlbums = function (query, element, trackOrAlbum) { trackOrAlbum = trackOrAlbum || 'track'; query = query.replace(/\[.*\]/i, ''); query = query.replace(/\(.*\)/i, ''); query = query.replace(/,.*/i, ''); query = query.replace(/\'/i, ''); $.ajax({ url: 'https://api.spotify.com/v1/search', data: { q: query, type: trackOrAlbum, limit: 1 }, success: function (response) { LibraryThingConnector.warn(response); try { if (trackOrAlbum == 'track' && response.tracks.items.length) { var track = response.tracks.items[0]; // use first response var _url = track.external_urls.spotify; var _preview_url = track.preview_url; var spotify = LibraryThingConnector.utils.jQuery(''); if (false && _url.length) { spotify.append(''); } if (_preview_url.length) { spotify.append(''); } element.append(spotify); } else if (response.albums.items.length) { var album = response.albums.items[0]; // use first response var _uri = encodeURIComponent(album.uri); var player = LibraryThingConnector.utils.jQuery(''); element.hide(); player.insertAfter(element); } } catch(err) { LibraryThingConnector.error(err); } } }); }; LibraryThingConnector.utils.jQuery('.unbound_track_list').each(function() { try { var that = LibraryThingConnector.utils.jQuery(this); var _artist = LibraryThingConnector.metadata.author || ''; var _album = LibraryThingConnector.metadata.title || ''; _album = _album.replace(/:.*/i, ''); var _searchString = _album; if (typeof _artist !== 'undefined' && _artist.trim().length && _artist !== 'undefined') { _searchString += '| ' + _artist; } searchAlbums(_searchString, that, 'album'); } catch(err) { LibraryThingConnector.error(err); } }); } // Show the content _unbound_element.show(); _unbound_element.parent('.unbound_element').fadeIn(); // show the mega contents area if there are more than 2 elements on the page now if(LibraryThingConnector.backend.name == 'atriuum' || LibraryThingConnector.backend.name == 'apollo') { var unbound_element_count = LibraryThingConnector.utils.jQuery('.unbound_element').not('.unbound_loaded').length; } else { var unbound_element_count = LibraryThingConnector.utils.jQuery('.unbound_element:visible').not('.unbound_loaded').length; } if ( unbound_element_count > LibraryThingConnector.MIN_UNBOUND_ELMENTS_FOR_NAV) { if( LibraryThingConnector.backend.name == 'atriuum' ) { LibraryThingConnector.info('not showing SU Contents header for atriuum'); LibraryThingConnector.utils.jQuery('.unbound_nav').hide(); LibraryThingConnector.utils.jQuery('.unbound_mega_header').show(); } if (LibraryThingConnector.backend.name == 'enterprise' && LibraryThingConnector.backend.onModalPage() ) { LibraryThingConnector.info('not showing SU Contents header for enterprise, only footer'); LibraryThingConnector.utils.jQuery('.unbound_mega_footer').show(); } else if( LibraryThingConnector.backend.name == 'polaris' && LibraryThingConnector.backend.isUnboundInfrastructureMigration()) { LibraryThingConnector.info('not showing unbound nav items for polaris infra'); } else { LibraryThingConnector.debug('minimum number of unbound elements found, showing nav items, header and footer'); LibraryThingConnector.utils.jQuery('.unbound_nav').show(); LibraryThingConnector.utils.jQuery('.unbound_mega_header').show(); LibraryThingConnector.utils.jQuery('.unbound_mega_footer').show(); } if( LibraryThingConnector.backend.name == 'primo' ) { LibraryThingConnector.info('not showing SU Contents header for primo'); LibraryThingConnector.utils.jQuery('.unbound_mega_header').hide(); LibraryThingConnector.utils.jQuery('.unbound_mega_footer').show(); } if( LibraryThingConnector.enrichmentsOn().indexOf('lists') > -1 && LibraryThingConnector.enrichmentsShown().length > 0) { LibraryThingConnector.utils.jQuery('.unbound_mega_footer').show(); } } else { if( LibraryThingConnector.enrichmentsOn().indexOf('lists') > -1 && LibraryThingConnector.enrichmentsShown().length > 0) { LibraryThingConnector.utils.jQuery('.unbound_mega_footer').show(); } else { LibraryThingConnector.utils.jQuery('.unbound_nav').hide(); LibraryThingConnector.utils.jQuery('.unbound_mega_header').hide(); LibraryThingConnector.utils.jQuery('.unbound_mega_footer').hide(); } } // mediatype alert box // prefer_ebooks if (LibraryThingConnector.add_eresource_message) { if (!LibraryThingConnector.utils.jQuery('#unbound_ebook_alert').length) { var ebook_alert_content = LibraryThingConnector.eresources_message_text; ebook_alert_content = ebook_alert_content.replace(/\(e\)/g, "") LibraryThingConnector.utils.jQuery('.unbound_nav').after('' + ebook_alert_content + '
BASE_URL | ' + LibraryThingConnector.BASE_URL + ' |
SYNDETICS_DOMAIN | ' + LibraryThingConnector.SYNDETICS_DOMAIN + ' |
LT_DOMAIN | ' + LibraryThingConnector.LT_DOMAIN + ' |
LTFL_BASE_URL | ' + LibraryThingConnector.LTFL_BASE_URL + ' |
LTFL_BASE_URL_RW | ' + LibraryThingConnector.LTFL_BASE_URL_RW + ' |
STATS_URL | ' + LibraryThingConnector.STATS_URL + ' |
LIBRARIAN_POWER_DOMAIN | ' + LibraryThingConnector.LIBRARIAN_POWER_DOMAIN + ' |
su_session | ' + LibraryThingConnector.su_session + ' |