var Activity_subtype = Activity_manuscript_type.extend({
initialize: function() {
this._super();
}
});
var Figures_subtype = Figures.extend({
process_iframes: function(jq) {
if (jq == null) {
jq = $("body");
}
jq.find("[data-mmtype='iframe']").each(function(index, element) {
var jq = $(element);
var id = jq.attr("data-figure-id");
var src = jq.attr("data-mmsrc");
var attr = jq.attr("data-attr");
if (attr == null) attr = "";
attr = attr.split(/\s*,\s*/);
// get default width and height from the placeholder image
var params = new Object();
params.width = jq.width();
params.height = jq.height();
params.frameborder = "no";
params.scrolling = "no";
params.style = "margin:0px; padding:0px";
params.src = src.replace('%26','&');
// check if we disabled autoplay for brightcove links */
if (params.src.match(/brightcove/)) {
if (jq.attr('data-autoplay') === "false") {
params.src += "&autoStart=false";
}
}
for (var i = 0; i < attr.length; ++i) {
var a = attr[i].split(/\s*=\s*/);
params[a[0]] = a[1];
}
var pstring = "";
for (var i in params) {
pstring += ' ' + i + '="' + params[i] + '"';
}
jq.replaceWith('');
});
}
});
/* re-define Glossary.show_definition to use ajax to get the term def */
var Glossary_subtype = Glossary.extend({
// used to store terms we have already retrieved so subsequent
// attempts can pull from memory instead of making ajax call
stored_terms: {},
// For now, footnote data-term attributes will start with fn:
show_definition: function(el, event) {
var $jq = $(el);
var index = $jq.data("term"); // this is the key for the database
var type; // "Glossary" or "Footnote"
var url;
var entry;
var Xcoord = "center";
var Ycoord = "center";
if (event != undefined && event != null) {
Xcoord = event.pageX -225;
Ycoord = ((event.pageY)-$(document).scrollTop())+25;
}
// if there is no data-term attribute than use the text in the span
if (index === undefined || index === null || index.length < 1) {
index = $jq.text();
}
var q_index = index.toLowerCase();
var match = q_index.match(/fn:(.*)/);
if (match === null) {
type = "Glossary";
q_index = q_index.replace(/[^a-z0-9]/g, '');
}
else {
type = "Footnote";
q_index = match[1];
}
if (q_index === null || q_index.length < 1) {
safe_log("Glossary_subtype.show_definition: invalid index [" + index + "]");
return;
}
if (type == "Glossary") {
if(typeof xBookGlossaryTermsObj != 'undefined') {
entry = xBookGlossaryTermsObj[q_index];
}
}
else {
if(typeof xBookFootnotesObj != 'undefined') {
entry = xBookFootnotesObj[q_index];
}
}
if (entry === undefined) {
Standard_Dialog.open("Can't find entry", {
"title": type,
"modal": false,
"draggable": true,
"buttons": "none",
"position": [Xcoord, Ycoord]
});
safe_log("Glossary_subtype.show_definition: Can't find entry for " + q_index);
return;
}
Standard_Dialog.open(entry, {
"title": type,
"modal": false,
"draggable": true,
"buttons": "none",
"position": [Xcoord, Ycoord]
});
return;
},
init: function() {
// we don't call super here because we are over-writing this function, not
// extending it
$("span[data-type='termref']").each(function(index, element) {
var $jq = $(element);
var term = $jq.data('term');
var match = term.match(/fn:(.*)/);
if (match != null ) {
$jq.addClass("footnote");
}
// Don't do this here, use delegate in initialize2
//$jq.click(function() { player.glossary.show_definition(this); });
});
}
});
var Player_subtype = Player_manuscript_type.extend({
initialize_sections: function() {
// we are redefining the super below
//this._super();
// redefine this so it adds the id on the section div to the body
var player = this; // define this so it's available inside the below function
$("[data-type='section']").each(function(index, element) {
var jq = $(element);
// establish the section in the sections array; store its jq
var s = player.sections[player.sections.length] = new Object();
s.jq = jq;
// set the body id to the id of this section since we are wiping out the
// section id below
$("body").attr('id', jq.attr('id'));
// set the section's index
s.index = index;
jq.attr("data-section-index", index).attr("id", "digfir_section_" + index);
// extract the section's title and number
s.number = jq.find("h2").find("[data-type=number]").html();
s.title = jq.find("h2").find("[data-type=title]").html();
// process page queries for the section
player.activity.process_page_queries_for_section(jq);
++player.section_count;
});
// Add class to body if we are viewing page in supp window
(function() {
var $supp_iframe = $('#xBookSuppWinNavPageFrame', window.parent.document);
if ($supp_iframe.length != 0) {
$("body").addClass("xBookSuppWinNavPage");
}
})();
if($("h2").length > 0) {
var h2_text = $("h2").text();
if (h2_text.match(/Portrait: /)) {
$("h2").remove();
}
else if (h2_text.match(/Guided Reading Exercise/)) {
$("h2").remove();
}
else if (match = h2_text.match(/(Chapter Review): .*?/)) {
$("h2").html(match[1]);
}
/*
if (h2_text.match(/\d+\.\d+\.\d+ /)) {
$("body").addClass("sec_level_3");
h2_text = h2_text.replace(/\d+\.\d+\.\d+ /, "");
$("h2").html(h2_text);
}
else if (h2_text.match(/\d+\.\d+ /)) {
$("body").addClass("sec_level_2");
h2_text = h2_text.replace(/\d+\.\d+ /, "");
$("h2").html(h2_text);
}
if (h2_text.match(/DOCUMENTING THE AMERICAN PROMISE/) ||
h2_text.match(/HISTORICAL QUESTION/) ||
h2_text.match(/VISUALIZING HISTORY/)) {
$("body").addClass("DX_box");
}
else if (h2_text.match(/Selected Bibliography/)) {
$("body").addClass("sel_bib");
}
else if (h2_text.match(/TIMELINE/)) {
$("body").addClass("timeline");
}
else if (h2_text.match(/Additional Chapter Activities/)) {
$("body").addClass("ACA");
}
if (h2_text.match(/KEY TERMS/) ||
h2_text.match(/MAKING CONNECTIONS/) ||
h2_text.match(/LINKING TO THE PAST/) ||
h2_text.match(/REVIEW QUESTIONS/)) {
$("body").addClass("review");
// these are the only pages that will have questions and we
// need to put a wrapper div around the input buttons for styling
$('.question_action_div').find('input').each(function() {
var $input = $(this);
$input.wrap('
');
});
}
*/
}
if ($('[data-block_type^="document"]').length > 0) {
$("body").addClass('documents');
if ($('[data-block_type="document_proj"]').length > 0) {
$("body").addClass('documents_proj');
}
if ($('[data-block_type="document_proj_ite"]').length > 0) {
$("body").addClass('documents_proj_ite');
}
var $h2 = $("h2");
var h2_text = $h2.text();
var $h3 = $("h3:first");
var h3_text = $h3.text();
if (match = h2_text.match(/(Documents|Visual Sources): (.*)/)) {
$h2.html(match[1]);
$h2.after("" + match[2] + "
");
}
else if (match = h2_text.match(/(Document \d+\.\d+) (.*)/)) {
$h2.html(match[1]);
/*$h2.after("" + match[2] + "
");*/
}
else if (match = h2_text.match(/(Documents \d+\.\d+ and \d+\.\d+) (.*)/)) {
$h2.html(match[1]);
}
else if (h2_text.match(/Using the Evidence:/)) {
$h2.remove();
}
if (match = h3_text.match(/([^:]+)(: Two Views)/)) {
$h3.addClass('dual_docs');
}
else if (match = h3_text.match(/(.*)(.*)<\/em>(.*)/)) {
$h3.html(match[1] + "" + match[2] + "" + match[3]);
}
else if (match = h3_text.match(/(.*), (.*)<\/em>(.*)/)) {
$h3.html(match[1] + ", " + match[2] + "" + match[3]);
}
else if (match = h3_text.match(/(.*)\| (.*)<\/em>(.*)/)) {
$h3.html(match[1] + "| " + match[2] + "" + match[3]);
}
else if (match = h3_text.match(/(.*?)\|(.*)/)) {
$h3.html(match[1] + "|" + match[2]);
}
/*fix for ch16_15 ?maybe? */
else if (match = h3_text.match(/(.*)<\/em>(.*)/)) {
$h3.html("" + match[1] + "" + match[2]);
}
else if (match = h3_text.match(/(.*)(.*)<\/em>(.*)/)) {
$h3.html(match[1] + ", " + match[2] + "" + match[3]);
}
/*else if (match = h3_text.match(/(.*)(.*)<\/em>(.*)/)) {
$h3.html(match[1] + "" + match[2] + "" + match[3]);
}*/
}
/*add ids to body tags of back matter */
if ($('[data-block_type="gloss"]').length > 0) {
$("body").attr('id', 'glossary');
}
/*if ($('[data-block_type="credits"]').length > 0) {
$("body").attr('id', 'credits');
}
if ($('[data-block_type="index"]').length > 0) {
$("body").attr('id', 'index');
}
if ($('[data-block_type="appendix"]').length > 0) {
$("body").attr('id', 'appendix');
}*/
if ($('[data-block_type="preface"]').length > 0) {
$("body").attr('id', 'preface');
}
if ($('[data-block_type="credits"]').length > 0) {
$("body").attr('id', 'credits');
}
if ($('[data-block_type="acknowledgements"]').length > 0) {
$("body").attr('id', 'acknowledgements');
}
if ($('[data-block_type="about_authors"]').length > 0) {
$("body").attr('id', 'about_authors');
}
/*italicize titles and parts of key terms*/
if ($('[data-block_type="ital_title"]').length > 0) {
var $span = $("span:first");
var span_text = $span.text();
if (match = span_text.match(/The Dred Scott Decision/)) {
$span.html("The Dred Scott Decision");
}
else if (match = span_text.match(/Cuba Libre/)) {
$span.html("Cuba Libre");
}
/*$('[data-term="dredscottdecision"]').each(function() {
var term_content = $(this).contents();
$(this).replaceWith("Dred Scott decision");
});*/
}
if ($('[data-block_type="doc_proj"]').length > 0) {
$("body").addClass('doc_proj');
$h2 = $("h2:first");
var match = $h2.text().match(/(e-)?(Document Project )(\d+)/);
if (match !== null) {
if (match[1] !== undefined) {
$h2.html(match[1] + "" + match[2] + " " + match[3] + "");
}
else {
$h2.html("" + match[2] + " " + match[3] + "");
}
}
}
/* remove any rawhtml divs */
/* This isn't strictly necessary, I just don't like the fact that our
raw html code is wrapped in a div */
$('[data-type="rawhtml"]').each(function() {
var raw_content = $(this).contents();
$(this).replaceWith(raw_content);
});
// This is a hack until we get IDs added to the html.
// Add id attribute to paras
/*
$('p:has([data-block_type^="id:"])').each(function() {
var child = $(this).children('[data-block_type^="id:"]');
var id = child.data('block_type');
var match = id.match(/id:(.*)/);
if (match !== null) {
$(this).attr("id", match[1]);
}
child.remove();
});
*/
// Hack: add id attribute to figure div
// NOTICE: XSLT puts the same data-figure-id on both the and the
// wrapper around the
. Since we don't want them both to have
// the same id we must use add "div" to the selector.
/*
$('div[data-figure-id]').each(function(index, element) {
var jq = $(element);
jq.attr('id', jq.data('figure-id'));
});
*/
// Hack: add ids to boxes
/*
$('.id_holder').each(function() {
var $id_div = $(this);
var $box_div = $id_div.next();
$box_div.attr('id', $id_div.attr('id'));
$id_div.remove();
});
*/
/* remove width/height attributes from
s as they are not supported */
/* These attributes aren't supported in HTML5 and should be removed from the
html, especially if we didn't include them in the first place */
/* Again, this isn't necessary, I just bothers me :-) */
$("table").removeAttr("width").removeAttr("height");
$("[data-block_type='table_snap']").find("h3").each(function(index, element) {
var $h3 = $(element);
var h3_text = $h3.text();
match = h3_text.match(/Snapshot: (.*)/);
if (match !== null) {
$h3.html("Snapshot " + match[1] + "");
}
});
$("[data-block_type='portrait']").find("h3").each(function(index, element) {
var $h3 = $(element);
var h3_text = $h3.text();
match = h3_text.match(/Portrait: (.*)/);
if (match !== null) {
$h3.html("PORTRAIT " + match[1] + "");
}
});
/* We should probably fix this where it is originally happening instead
of hacking it here but I don't have time right now to look into it */
// Allow figure width to be set in pixels
$("[data-type='figure']").each(function(index, element) {
var $this = $(element);
var width = $this.data('layout-width') + "x";
//safe_log("width: " + width);
var match = width.match(/(\d+)/);
if (match !== null) {
//safe_log("changing width to " + match[1]);
$this.attr('style',"width:" + match[1] + "px");
var $img = $this.children("img");
$img.attr('style',"width:" + match[1] + "px; cursor: pointer");
}
});
},
initialize: function(id) {
/* We don't want to call super (Person.initialize) here:
- Player.initialize creates all the variables below, so if we are
extending a class (e.g. XRefs_subtype) then calling super creates the
original xrefs variable (in Player.initialize) and then we create it
again (below) which is just a waste of resources and...
- The bad thing about the above is that when the original xrefs is created
(Xrefs.init is called) it modifies the DOM so by the time we create our
extended xrefs variable we only have access to the modified DOM.
*/
//this._super();
this.manuscript_id = id;
// extract metadata (this might be already done by the activity-specific
// player, but that's OK; we'll just re-do it here, which is no problem.)
this.extract_activity_metadata();
// have to do variables first because that replaces the body html
this.variables = new Variables();
//this.figures = new Figures();
this.figures = new Figures_subtype();
//this.xrefs = new XRefs();
//this.xrefs = new XRefs_subtype();
this.xrefs = new XRefs_manuscript_subtype();
this.links = new Links();
//this.activity = new Activity();
this.activity = new Activity_subtype();
this.interactions = new Interactions();
this.tables = new Tables();
//this.glossary = new Glossary();
this.glossary = new Glossary_subtype();
// Prepare for activity functionality by getting ARGA data;
// that fn will call Initialize_ARGA_Session_Callback (see below)
var success = false;
if (window.Initialize_ARGA_Session != null) {
success = Initialize_ARGA_Session({
"fail_silently": (this.md.ARGA_fail_silently != "false"),
"retrieve_class_data": (this.md.ARGA_retrieve_class_data == 1 || this.md.ARGA_retrieve_class_data == "true" || this.md.ARGA_retrieve_class_data == true) ? 1 : 0,
"cancel_initialization_alert": true
});
}
if (!success) {
this.ARGA_running = false;
safe_log("running in non-ARGA mode");
// We need to initialize the player after a timeout (mimicking what would happen
// if ARGA was initialized and initialize2 was called on a callback) so that
// inherited players will be called in the proper order.
setTimeout("player.initialize2()", 1);
} else {
this.ARGA_running = true;
}
},
initialize2: function() {
this._super();
$('a').each(function() {
var $link = $(this);
var target = $link.attr('target');
if (target != undefined && /^bsi_/.test(target)) {
$link.attr('data-px-id', target);
$link.attr('target', '_self');
}
});
// any "doc" block_type should pop
$('[data-block_type^="doc:"]').each(function() {
var $jq = $(this);
var block_type = $jq.data("block_type");
var match = block_type.match(/doc:(.*)/);
$jq.replaceWith("" + $jq.html() + "");
});
// any "doc" block_type should pop
$('[data-block_type^="fig:"]').each(function() {
var $jq = $(this);
var block_type = $jq.data("block_type");
var match = block_type.match(/fig:(.*)/);
$jq.replaceWith("" + $jq.html() + "");
});
// All xrefs in "documents" pages should pop
if ($('body').hasClass('documents') || $('body').hasClass('doc_proj')) {
$('a').each(function() {
var $link = $(this);
var href = $link.attr('href');
if (/^[^\/]+_[a-z]+\d+_\d+\.html$/.test(href)) {
$link.attr('target', '_pop');
}
});
}
// Any xref to a page outside of the current chapter should pop
$("a").not("[name='_pop']").each(function() {
var $link = $(this);
var href = $link.attr('href');
var match = href.match(/^[^\/]+_([a-z]+)(\d+)_\d+\.html$/);
if (match != null) {
if (match[2] != xBookUtils.getChapter()) {
$link.attr('target', '_pop');
}
}
});
// link handler
// Handle clicks inside the manuscript div
$("#manuscript").delegate('a', 'click', function(event) {
var $clickedLink = $(this);
var linkHref = $clickedLink.attr('href');
var linkTarget = $clickedLink.attr('target');
var linkPxId = $clickedLink.data('px-id');
/*
var test = $clickedLink.data('test');
if (test === undefined) {
safe_log("link disabled temporarily");
event.stopImmediatePropagation();
return false;
}
// Bubble up
return true;
*/
// We can't have a link without an href
if (linkHref == undefined) {
return false;
}
// Check if link has been disabled
if (linkTarget == "_disable" || linkTarget == "_disabled") {
return false;
}
// External links
if (match = linkHref.match(/(..\/hewittlawson1e\/hewittlawson1e_ch\d+_\d+\.html)/)) {
// Check if we need to open this link in supp window
if (linkTarget == "_pop" || linkTarget == "_supp") {
xBookUtils.openSuppWin({url: linkHref});
return false;
}
// Otherwise let it bubble naturally
return true;
}
// External links
if (linkHref.search(/^[a-z]+:\/\//) != -1) {
// Check if we need to open this link in supp window
if (linkTarget == "_pop" || linkTarget == "_supp") {
xBookUtils.openSuppWin({url: linkHref});
return false;
}
// Otherwise let it bubble naturally
return true;
}
// If we made it here we have an internal link
// Check if link should open in supp window
if (linkTarget == "_pop" || linkTarget == "_supp") {
var suppWinLink;
// If this is a link to another page in the book then we
// need to pop it via the supp_win.html page
var re = new RegExp("^" + xBookUtils.getBookId() + "_[a-z]+\\d+_\\d+\\.html$");
if (linkHref.match(re) != null) {
suppWinLink = xBookUtils.getBaseUrl() + "asset/supp_win.html?bookid=" + xBookUtils.getBookId() + "&manuscript=" + linkHref + "&baseurl=" + xBookUtils.getBaseUrl();
xBookUtils.openSuppWin({url: suppWinLink, name: "xBookSuppWinNavPage", width: 875, height: 900});
}
// Otherwise, pop it in plain old regular supp window
else {
// make sure "asset/" is included in href
//safe_log("popping " + linkHref);
if (!/asset\//.test(linkHref)) {
linkHref = "asset/" + linkHref;
}
suppWinLink = xBookUtils.getBaseUrl() + linkHref;
xBookUtils.openSuppWin({url: suppWinLink});
}
return false;
}
// If we are in PX and have a data-px-id attribute, then
// use openContent to open new page
if (xBookUtils.inPX()) {
// brb - 2013110: openContent doesn't seem to be behaving properly
// for hewitt, so we are going to open all xrefs in the supp win
var pxSuppWinLink = xBookUtils.getBaseUrl() + "asset/supp_win.html?bookid=" + xBookUtils.getBookId() + "&manuscript=" + linkHref + "&baseurl=" + xBookUtils.getBaseUrl();
xBookUtils.openSuppWin({url: pxSuppWinLink, name: "xBookSuppWinNavPage", width: 875, height: 900});
return false;
/*
if (linkPxId != undefined) {
safe_log("openContent: " + linkPxId);
//event.stopImmediatePropagation();
top.PxPage.openContent({id: linkPxId});
}
else {
safe_log("Can't find PX ID for linkHref");
}
return false;
*/
}
// If we get here just treat it as a good old fashioned link
var linkURL = xBookUtils.getBaseUrl() + linkHref;
$clickedLink.attr('href', linkURL);
// Bubble up!
return true;
});
// anything that you want to do after *everything* has been set up
// should be done here.
// get glossary/footnote pop ups to display properly
$("#manuscript").delegate('span[data-type="termref"]', 'click', function(event) {
player.glossary.show_definition(this, event);
});
// scrolling link boxes
$("[data-block_type='link_box']").jScrollElement();
var self = this;
$("[data-block_type='mn1']").delegate("[data-block_type='answer']", 'click', function(event) {
var $jq = $(this);
if ($jq.text().match(/Show Answer/)) {
$jq.parent().next().show();
$jq.text("[Hide Answer]");
}
else if ($jq.text().match(/Hide Answer/)) {
$jq.parent().next().hide();
$jq.text("[Show Answer]");
}
});
// replace link s with after ARGA submit button is clicked
$("#manuscript").delegate('.question_submit_button', 'click', function() {
// grab all the link spans in the query text
var $links = $(this).closest('[data-type="question"]').find('.query_text').find('[data-type="link"]');
// replace each link span with
$links.replaceWith(function() {
var $this = $(this);
return '' + $this.html() + '';
});
});
$('.question_action_div').find('input').each(function() {
var $input = $(this);
$input.wrap('');
});
/* update event handler on figures to use OpenSupp */
$("[data-type='figure']").each(function(index, element) {
var jq = $(element);
//safe_log("click handler for " + jq.data("figure-id"));
var ijq = $("img", jq);
if (jq.attr("data-expandable") != "false") {
var match = jq.data("altsrc").match(/(.*)\/(.*)/);
if (match != null) {
ijq.unbind('click');
ijq.click(function(event) {
xBookUtilOpenSupp(match[1],match[2]);
});
// regular images have a child 'head'
jq.find("[data-block_type='head']").click(function() { return xBookUtilOpenSupp(match[1],match[2]); }).css("cursor", "pointer");
jq.find("[data-block_type='vs_num']").click(function() { return xBookUtilOpenSupp(match[1],match[2]); }).css("cursor", "pointer");
// map and visual activities have 'head' and 'title' siblings
/*
jq.siblings("[data-block_type='head']").click(function() { return OpenSupp(match[1],match[2]); }).css("cursor", "pointer");
jq.siblings("[data-block_type='title']").click(function() { return OpenSupp(match[1],match[2]); }).css("cursor", "pointer");
*/
}
}
});
// add handler for numbered figure links (and maps)
/*
$('[data-block_type^="fig:"]').each(function() {
var jq = $(this);
var start = jq.attr("data-block_type");
var match = start.match(/fig:(.*)\/(.*)/);
jq.click(function() { return xBookUtilOpenSupp(match[1],match[2]); });
});
*/
$('[data-mmsrc^="tables/"]').each(function() {
var jq = $(this);
var start = jq.attr("data-mmsrc");
var match = start.match(/(tables)\/(\d+_\d+\.html)/);
jq.click(function() { return xBookUtilOpenSupp(match[1],match[2]); }).css("cursor", "pointer");
});
// use the imagesLoaded plugin to adjust div wrapper width around images
// after they are loaded
$('#manuscript').imagesLoaded(adjustFigBorders);
// make sure we are at the anchor target if one was passed in with the URL
var page_url = window.location.href;
if (page_url.match(/#/)) {
var temp;
var target = "#" + window.location.href.substring(window.location.href.indexOf('#')+1);
//safe_log("target: " + target);
if ($(target).length > 0) {
safe_log("scrolling to target: " + target);
$(document).scrollTop( $(target).offset().top );
}
}
/*if ($("body.documents").length > 0) {
$h3 = $("h3:first");
safe_log("h3 text: " + $h3.text());
var match = $h3.text().match(/(.*?)\|(.*)/);
if (match !== null) {
$h3.html(matcwebsterfw_create_answer_boxesh[1] + "|" + match[2]);
}
}*/
// import wrapper specific functions
/*if (/digfir-published/.test(window.location.href)) {
var df_wrapper_script = document.createElement('script');
df_wrapper_script.setAttribute('type','text/javascript');
df_wrapper_script.setAttribute('src', "../../../wrapper/asset/wrapper_xbook.js");
document.getElementsByTagName("body")[0].appendChild(df_wrapper_script);
}*/
}
});
//player = new Player_subtype(); /* called at the end of this file */
function getLineHeight (elem) {
var addendum = "
x";
var h0 = elem.offsetHeight;
elem.innerHTML += addendum;
var h1 = elem.offsetHeight;
elem.innerHTML = elem.innerHTML.slice(0,-addendum.length);
return h1-h0;
}
function adjustFigBorders() {
$('[data-type="figure"], [data-block_type^="map"]').each(function(index, element) {
var jq = $(element);
var ijq = $("[data-mmtype]", jq); // the figure's main image will have a mmtype tag
var width = ijq.width();
// If we can't get the image width yet then just go with the defaults
if (width > 0) {
jq.css("width", width + "px");
}
else {
}
});
}
/* This pops open a supp window to display a file.
dir: (REQUIRED) directory where file is located under asset/
If file is in asset/ then pass '' or null or "asset".
If file is in parent of asset/ then pass 'root'.
file: (REQUIRED) name of file
win_name: (OPTIONAL) specify name of supp window
*/
function xBookUtilOpenSupp(dir, file, win_name) {
var suppWinPos = 10; // make this configurable?
var new_win_name = "xBookSuppWin";
// get URL of current xbook page
var curr_url = xBookUtilGetPageUrl();
// remove filename from URL
var match = curr_url.match(/(.*\/).*/);
var supp_url = match[1];
// create URL for supp window
if (dir === "root") {
supp_url += file;
}
else if (dir === null || dir === "" || dir === "asset") {
supp_url += "asset/" + file;
}
else {
supp_url += "asset/" + dir + "/" + file;
}
if (win_name !== undefined) {
new_win_name = win_name;
}
// TODO: make width/height variable?
var sw = window.open(supp_url, new_win_name, "top=" + suppWinPos + ",left=" + suppWinPos + ",width=780,height=600,resizable,scrollbars", true);
sw.focus();
// register pop up if we are in the wrapper iframe
// (this is not used in PX, so we will need to figure out how to automatically
// close the supp window if someone logs out of PX)
match = supp_url.match(/websterfw/);
if (match !== null) {
if (parent !== undefined && parent.iframe_wrapper !== undefined) {
parent.iframe_wrapper.registerWindow(sw);
}
}
}
/* If we are viewing an xbook page on PX then this will return the PX-specific
URL of the page. Otherwise it returns window.location.href */
function xBookUtilGetPageUrl() {
var elements = document.location.search.split('&');
// PX URL will have ContentUrl variable
var queryParts = $(elements).filter(function(index){ return this.toLowerCase().indexOf('contenturl=') > 0});
// Turns out that PX will not always have ContentUrl, it may just have "Url"
if (queryParts.length == 0) {
queryParts = $(elements).filter(function(index){ return this.toLowerCase().indexOf('url=') > 0});
}
// If we did not find ContentUrl (or Url) then return window href
if (queryParts.length == 0) {
var href_url = window.location.href;
href_url = href_url.replace(/\?.*/, "");
return href_url;
}
// get value of ContentUrl (or Url)
var url = queryParts[0].split('=')[1];
// decode the url
url = decodeURIComponent(url);
// apparently the url may now have args tacked onto the end of it
url = url.replace(/\?.*/, "");
return url;
}
function xBookUtilGetChapter() {
var url = window.location.href;
var match = url.match(/ch0?(\d+)_\d+\.html/);
if (match == null) {
return -1;
}
return match[1];
}
function LoadSection(file, target) {
var temp;
var curr_url = window.location.href;
//safe_log(curr_url);
var match = curr_url.match(/(.*\/).*/);
curr_url = match[1];
//safe_log(curr_url);
var new_url = curr_url + file + "#" + target;
//safe_log(new_url);
window.location.href = new_url;
}
player = new Player_subtype();