/*
This is the standard template you should add to your book JS file before
customizing.
Uncomment any of the configuration options to change the default behavior (see
https://macmillanhighered.atlassian.net/wiki/display/MP/Player+Configuration+Options
for descriptions of the options).
*/
/**************************************
Set this to the DF book ID (Subtype)
**************************************/
xBookUtils.bookID = "krugmanapecon2e";
/*
You only need to set the disciplines if you are using the HTML Quiz
question delivery method, which only BSM ebooks and HTML Quizzes are at this
time (in other words, if this is a FW ebook then you don't need to do a thing).
Change the zeros to the discipline number for each tier on PX.
Discipline numbers:
History: 6696 (all tiers)
Composition: 6698 (all tiers)
Communication: 6700 (all tiers)
College Success: 6704 (all tiers)
If you do not know the discipline number for your book then ask your MP.
*/
xBookUtils.discipline = {
dev: 6712,
qa: 6712,
pr: 6712,
www: 6712
}
var Player_subtype = Player_manuscript_type.extend({
//cfg_removeRawHtmlDivs: "on",
cfg_showAnswer: "on",
//cfg_showAnswerAutoWrapThis: "off",
//cfg_Box_moveTitle: "all",
//cfg_Box_moveTitleExclude: "",
//cfg_Figures_targetDefault: "_blank",
cfg_Figures_resizeDivWidth: "off",
cfg_Figures_autoHtml: "on",
cfg_LH_autoHtml: "on",
cfg_LH_externalTargetDefault: "_pop",
cfg_LH_internalTargetDefault: "_pop",
cfg_LH_ebookTargetDefault: "_pop",
//cfg_LH_imageTargetDefault: "_blank",
//cfg_LH_useOpenContent: "on",
//cfg_LH_useLinksFile: "on",
//cfg_Glossary_hoverTerms: "on",
cfg_Glossary_useStickyDiv: "on",
//cfg_Glossary_hoverTermsNoClick: "",
initialize_sections: function() {
// Do not delete this
this._super();
// Anything that needs to be done before the page displays
// should be done here.
var bookid = "krugmanapecon2e";
var matches;
////// numbered ol mustly in Section Reviews
$("[data-block_type='numbered']").each(function(index, element) {
if ( $(this).attr('start') != null && $(this).attr('start') >= 1 ) {
var nstart = $(this).attr('start') -1; //alert('data-block_type:numbered start:' + nstart);
$(this).css('counter-reset','icounter ' + nstart);
}
});
/*///// numbered ol mustly in Section Reviews
$("[data-block_type='loweralpha']").each(function(index, element) {
if ( $(this).attr('start') != null && $(this).attr('start') >= 1 ) {
var nstart = $(this).attr('start') -1; //alert('data-block_type=loweralpha start:' + nstart);
$(this).css('counter-reset','icounter ' + nstart);
}
});*/
////// numbered tables that have image for table
$("[data-block_type='tab_numbered']").each(function(index, element) {
var $tab = $(element);
var tab_t;
var tab_no;
var tab_title; //if (tab_title.search(/!em!/) >0 ) {alert(tab_title);}
var tabsize = $tab.attr("data-layout-width");
if ( $(this).attr('data-type') == "table") {
var tab_no = $(this).attr('data-tno');
var tab_title = $(this).attr('data-ttitle'); //if (tab_title.search(/!em!/) >0 ) {alert(tab_title);}
// Comparison Shopping for !em!A Deadly indifference!/em! by Marshall Jevons
tab_title = tab_title.replace(/!em!/g,"");
tab_title = tab_title.replace(/!\/em!/g,"");
//tab_t = "
" + tab_no + "" + $(this).attr('data-ttitle') + "
"
tab_t = "" + tab_no + "
" + tab_title + "
"
} else { // table with image
var tab_t = $tab.find("img").attr('data-attr'); //alert("table data-attr:\n" + tab_t);
//3-1:TABLE 3-1 Factors That Shift Demand
//tab_t = tab_t.replace(/(\d+-\d+):?(TABLE \d+-\d+)? ?(.*)/,"$1$3
");
if (tab_t) {
tab_t = tab_t.replace(/(\d+[-\.]\d+):?(TABLE \d+-\d+)? ?(.*)/,"");
} else {
tab_no = $(this).attr('data-tno');
tab_title = $(this).attr('data-ttitle'); //if (tab_title.search(/!em!/) >0 ) {alert(tab_title);}
//tab_t = "" + tab_no + "
" + tab_title + "
"
tab_t = "" + tab_no + "
" + tab_title + "
"
}
} //alert(tab_t);
//$tab.before(tab_t);
$tab.prepend(tab_t);
});
}, // end initialize_sections //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
You will most likely not make any changes to the initialize
method unless you know exactly what you are doing :-)
*/
initialize: function(id) {
// Do not delete this
this._super(id);
this.xrefs = new XRefs_manuscript_subtype();
this.glossary = new Glossary_manuscript_subtype();
this.figures = new Figures_manuscript_subtype();
}, // end initialize //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
initialize2: function() {
// Do not delete this
this._super();
var link_handler = new LinkHandler();
// Anything that can be done after the page displays
// should be done here.
var matches;
// define imagesSmall, imagesMedium, ..., in chapter specific js files
$("[data-type='figure']").each(function(index, element) {
var $this = $(this);
var $thisFig = $(element);
var thisFigId = $thisFig.attr('data-figure-id'); //alert('date-type="figure"\nthisFigId:' + thisFigId);
thisFigId = thisFigId + ",";
var figSize = "medium";
if ($thisFig.attr('data-layout-width') != null) {
figSize = $thisFig.attr('data-layout-width');
}
var regexp = new RegExp (thisFigId, 'i');
//alert ( " -- checking " + thisFigId + "\nimagesSmall: " + imagesSmall + "\nimagesMedium: " + imagesMedium + "\nimagesLarge: " + imagesLarge + "\nimagesXlarge: " + imagesXlarge + "\nimagesXXlarge: " + imagesXXlarge);
if (typeof imagesSmall !== 'undefined' && imagesSmall.match(regexp) != null) {figSize = "small";}
if (typeof imagesMedium !== 'undefined' && imagesMedium.match(regexp) != null) {figSize = "medium";}
if (typeof imagesLarge !== 'undefined' && imagesLarge.match(regexp) != null) {figSize = "large";}
if (typeof imagesXlarge !== 'undefined' && imagesXlarge.match(regexp) != null) {figSize = "xlarge";}
if (typeof imagesXXlarge !== 'undefined' && imagesXXlarge.match(regexp) != null) {figSize = "xxlarge";}
if (typeof imagesXXXlarge !== 'undefined' && imagesXXXlarge.match(regexp) != null) {figSize = "xxxlarge";}
if (figSize.match(/(small|medium|large|xlarge|xxlarge|xxxlarge)/) ) {
$thisFig.attr('data-layout-width',figSize);
$thisFig.find("img").attr('data-layout-width',figSize); // img needs to be resized too
if ( figSize.match(/(medium|large)/) ) {
$this.attr("data-layout-align", "center");
}
//alert (" Re-size figure " + thisFigId + " to " + figSize );
}
// with xxlarge, can arrange image * fig_text be side-by-side. e.g. fig 3-3
if (figSize.match(/xxlarge/) && typeof layoutSidebyside !== 'undefined' && layoutSidebyside.match(regexp) != null) {
//$thisFig.attr('data-block_type,"fig_numbered_sbs");
//var figImgStyle = $(element).find("img").attr('style');
//figImgStyle = figImgStyle.replace(/$/,"width:400px;"); //alert (thisFigId +'=> figImgStyle:' + figImgStyle);
//$this.attr("class", "fig_numbered_leftright");
$this.attr("data-block_type", "fig_numbered_leftright");
//$this.attr("data-type", "figure_layoutleftright");
$this.attr("data-layout-align", "");
$this.attr("style","")
$(element).find("img").attr('class','fig_imgright');
$(element).find("div").attr('class','fig_txtleft'); // supposedly only one div in figure
//alert ("img attr: " + $(element).find("img").attr("class") + "\ndiv attr: " + $(element).find("div").attr("class"));
}
// fig_numbered get title
if ($thisFig.attr('data-block_type') == 'figure') {
thisFigId = $thisFig.attr('data-figure-id'); //alert("numbered figure:" + thisFigId);
var fig_t = $this.find('[data-type="figure_text"]').html();
matches = fig_t.match(/(.*?)<\/strong>.*/); //alert ("figure_text:\n" + fig_t);
fig_t = matches[1]; //alert ("fig_t:\n" + fig_t + "\n" + thisFigId);
var chno; var figno;
if (thisFigId.match(/_enrichment/)) {
matches = thisFigId.match(/_enrichment([abcdh])_fig-0?(\d+)/i); matches[1] = matches[1].toUpperCase();
chno = matches[1]; figno = matches[2];
fig_t = fig_t.replace(/FIGURE [ABCDH]?\.\d+/, ""); //alert('fig_t:'+ fig_t + '\nchno' + chno);
} else {
//matches = thisFigId.match(/mod0?(\d+A?)_fig[-_]0?(\d+)/i);
matches = thisFigId.match(/(app|mod)0?(\d+A?)_fig[-_]0?(\d+)/i);
chno = matches[2]; figno = matches[3];
}
//matches[2] = matches[2] + '.'; if (matches[2] == 'H.') {matches[2] = ""; } if (matches[2] == '1a.') {matches[2] = "A."; }
chno = chno + '.'; if (chno == 'H.') {chno = ""; } if (chno == '1a.') {chno = "A."; }
fig_t = "Figure " + chno + figno + " | " + fig_t + " |
"; //alert ("fig_t [re-formatted]:\n" + fig_t);
$thisFig.prepend(fig_t);
//alert("fig_numbered:" + thisFigId + "\nfig_t:" + fig_t);
}
// fig_unnumbered in module intro
if ($thisFig.attr('data-block_type') == 'un_figure') {
var bkurl = $(element).find("img").attr('src');
if (bkurl.match(/MO\d+\.jpg/)) {
//$(element).find("img").attr('src','');
$(element).find("img").css('opacity','0');
bkurl = "url\('" + bkurl + "'\)";
//alert ('module intro\n' + bkurl);
$(this).css('background-image', bkurl);
}
if ($thisFig.attr('data-layout-width') == 'small') { //alert('small un_figure');
$(element).find("div").each(function(index,element) {
if ( $(this).attr('data-type') == 'figure_text' ) { //alert($(this).attr('data-type'));
$(this).css('margin-top','-5px');
}
});
}
}
});
//// module intro: what you will learn list
//$("[data-block_type='rosebullet']").each(function(index, element) { alert('0');
$("ul").each(function(index, element) {
if ($(this).attr('data-block_type')!= null) {
var i = 0;
var type = $(this).attr('data-block_type');
var matches = type.match(/(violet|rose|green|orange|blue|red)bullet/);
if (matches[1].length > 0) { //alert(matches[1]);
var learnlist = $(this)[0].outerHTML; //alert('outerHTML:\n' + learnlist);
learnlist = learnlist.replace(/\n/g,""); //alert('learnlist:\n' + learnlist);
var matches = learnlist.match(//,'');
learnlist = learnlist.replace(/<\/ul>/,'
');
learnlist = learnlist.replace(/- \n?
]*>
/g,'
• ');
learnlist = learnlist.replace(/<\/div>\n?<\/li>/g,'');
while (matches = learnlist.match(/
/)) { //-------------
i = i + 1;
learnlist = learnlist.replace(/
/,'
');
}//--------------------------
if (i == 2) {learnlist = learnlist.replace(/<\/div>$/,'
'); }
//alert('new learnlist:\ni=' + i + '\n'+ learnlist );
$(this)[0].outerHTML = learnlist;
}
}
});
////// FYI box
$("[data-block_type='bx1-h']").each(function(index, element) {
var newhtml = $(this).html(); //alert('fyi box ' + index + '\n' + newhtml);
matches = newhtml.match(/(]*>[^<]*<\/h3>)/); //alert('matches[1]:' + matches[1]);
newhtml = newhtml.replace(/]*)>/, ''); //alert('hide h3\n' + newhtml);
$(this).prepend(matches[1]); //alert('matches[1]:' + matches[1]);
//$(this).html(newhtml);
});
////// fig in FYI
$('[data-block_type="un_figure"]').each(function(index, element) {
var fid;
if ($(this).attr('data-figure-id') != null) { fid = $(this).attr('data-figure-id');}
if (typeof fyifigs !== 'undefined' && fyifigs.match(fid+',') != null) {
if ($(this).parent().attr('data-type') == 'section') {
var html = '
' + $(this)[0].outerHTML + '
';
$(this)[0].outerHTML = html;
}
}
});
// termref in margintext definition: remove them
$('[data-block_type="mn1"]').each(function(index, element) {
var html = $(this).html();
html = html.replace(/data-type="termref"/g,'');
$(this).html(html);
});
// free response question 1 Rubric ** discard ** image became unclickable
$('[data-type="question"]').each(function(index, element) {
var fr1 = $(this).attr('id');
if ( fr1.match(/_fr_1$/) && frqboxid !== 'undefined' ) { //alert(fr1 + ' ' + frqboxid);
var frqhtml = '' + $('#'+frqboxid).html() + '
';
$(this).after(frqhtml);
$('#'+frqboxid).css('display','none');
}
});
// anderson chapter links: disable them
//Economics by Example Chapter 6
//Economics by Example Chapter 2
// brb: we can't do the following because it is disabling the go to page menu functionality in the Economics by Example content
/*
$("[data-type='section']").each(function(index,element) {
var href = window.location.href;
var ebe = new RegExp(/krugmanapecon2e_anderson/);
if (ebe.test(href)) {
var newhtml = $(this).html();
//alert('data-sec-id: ' + $(this).attr('data-sec-id') + '\nhref: ' + window.location.href + '\n' + newhtml);
newhtml = newhtml.replace(/Economics by Example (Chapter \d+)<\/span>/g,"$1");
newhtml = newhtml.replace(/Economics by Example (Chapter \d+)<\/a>/g,"$1");
$(this).html(newhtml);
}
});
*/
} // end initialize2
}); // end Player_subtype
// Do not delete this
player = new Player_subtype();