/* change to trigger update to svn */ /*! * jQuery imagesLoaded plugin v2.1.0 * http://github.com/desandro/imagesloaded * * MIT License. by Paul Irish et al. */ ;(function($, undefined) { 'use strict'; var BLANK = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=='; $.fn.imagesLoaded = function( callback ) { var $this = this, deferred = $.isFunction($.Deferred) ? $.Deferred() : 0, hasNotify = $.isFunction(deferred.notify), $images = $this.find('img').add( $this.filter('img') ), loaded = [], proper = [], broken = []; if ($.isPlainObject(callback)) { $.each(callback, function (key, value) { if (key === 'callback') { callback = value; } else if (deferred) { deferred[key](value); } }); } function doneLoading() { var $proper = $(proper), $broken = $(broken); if ( deferred ) { if ( broken.length ) { deferred.reject( $images, $proper, $broken ); } else { deferred.resolve( $images ); } } if ( $.isFunction( callback ) ) { callback.call( $this, $images, $proper, $broken ); } } function imgLoaded( img, isBroken ) { if ( img.src === BLANK || $.inArray( img, loaded ) !== -1 ) { return; } loaded.push( img ); if ( isBroken ) { broken.push( img ); } else { proper.push( img ); } $.data( img, 'imagesLoaded', { isBroken: isBroken, src: img.src } ); if ( hasNotify ) { deferred.notifyWith( $(img), [ isBroken, $images, $(proper), $(broken) ] ); } if ( $images.length === loaded.length ){ setTimeout( doneLoading ); $images.unbind( '.imagesLoaded' ); } } if ( !$images.length ) { doneLoading(); } else { $images.bind( 'load.imagesLoaded error.imagesLoaded', function( event ){ imgLoaded( event.target, event.type === 'error' ); }).each( function( i, el ) { var src = el.src; var cached = $.data( el, 'imagesLoaded' ); if ( cached && cached.src === src ) { imgLoaded( el, cached.isBroken ); return; } if ( el.complete && el.naturalWidth !== undefined ) { imgLoaded( el, el.naturalWidth === 0 || el.naturalHeight === 0 ); return; } if ( el.readyState || el.complete ) { el.src = BLANK; el.src = src; } }); } return deferred ? deferred.promise( $this ) : $this; }; })(jQuery); var XRefs_subtype = XRefs.extend({ //local_ids: [], create_links: function(jq) { //var loc_ids = this.local_ids; jq.find("[data-type='link']").each(function(index, element) { var jq2 = $(element); var url = jq2.data("href"); var target = jq2.data("target"); if (target === undefined) { target="_self"; } jq2.replaceWith("" + jq2.html() + ""); /* if (!url.match(/^http/) { jq2.replaceWith("" + jq2.html() + ""); } if (!url.match(/^#/) || jQuery.inArray(url, loc_ids) >= 0) { return true; } */ }); }, init: function() { // load all the local ids into local_ids array /* this.local_ids = $('*[data-block_type^="id:"]').map(function() { return $(this).data('block_type').replace(/id:/, "#"); }).get(); */ this.create_links($("body")); } }); /* 2013-01-28: Well, unfortunately PX is running on a Windows server that doesn't support PHP (at least at the moment), so for the time being we'll have to store all of our footnotes and glossary terms in an array :-( */ /* 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 // 1013-01-28: Don't need this right now //stored_terms: {}, // For now, footnote data-term attributes will start with fn: show_definition: function(el) { var $jq = $(el); var index = $jq.data("term"); // this is the key for the database //var loc_terms = this.stored_terms; var type; // "Glossary" or "Footnote" var url; var entry; // 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, ''); //url = "asset/glossary/term.php"; } else { type = "Footnote"; q_index = match[1]; //url = "asset/footnote.php"; } 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": ['center',150] }); 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": ['center',150] }); return; /* The following is for ajax calls to the php script which we can't use right now */ // if we have already retrieved q_index then show it /* if (loc_terms[q_index]) { Standard_Dialog.open(loc_terms[q_index], {"title": type , "modal":false , "draggable":true , "buttons":"none" }); return; } $.post(url, { term: q_index }, function(result) { if (result.match(/^ERROR/) || result.match(/^EMPTY/)) { safe_log("show_definition: " + result); var error; if (type == "Footnote") { error = "Footnote not found"; } else { error = "No definition found for " + index; // original index } Standard_Dialog.open(error, {"title": type , "modal":false , "draggable":true , "buttons":"none" }); } else { var html; var mat = result.match(/(.*)::(.*)/); if (type == "Footnote") { html = mat[2]; } else { html = "" + mat[1] + ": " + mat[2]; } Standard_Dialog.open(html, {"title": type , "modal":false , "draggable":true , "buttons":"none" }); loc_terms[q_index] = html; } }); */ }, 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 add handlers individually here because we might have // footnotes in question text so we need to use delegate instead //$jq.click(function() { player.glossary.show_definition(this); }); }); } }); var Player_subtype2 = Player_subtype.extend({ initialize_sections: function() { // we are redefining the super below //this._super(); $("html").addClass("xbook_page"); // with the above we can take care of the following with css /* var $body = $("body"); $body.css("margin-left", "10px"); $body.css("line-height", "normal"); */ //reimport_css(); // 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; }); /* 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 */ /* Actually, we need these removed now to make it easier to add headers */ $('[data-type="rawhtml"]').each(function() { var raw_content = $(this).contents(); $(this).replaceWith(raw_content); }); /* hack to get ids on images */ $('img').each(function(index, element) { var $jq = $(element); var alt = $jq.attr('alt'); var match; if (alt !== undefined) { match = alt.match(/id:(.*)/); if (match !== null) { $jq.attr('alt',''); $jq.attr('id',match[1]); } } }); /* this is a hack to get IDs on spans that we are using to line-up margin text*/ $('[data-block_type^="mt-"]').each(function(index, element) { var jq = $(element); jq.attr('id', jq.data('block_type')); }); /* hack to get figure ids */ $('div[data-figure-id]').each(function(index, element) { var jq = $(element); jq.attr('id', jq.data('figure-id')); }); // add body class for handbook if ($("[data-block_type^='handbook']").length > 0) { $("body").addClass('hb'); } if($("h2").length > 0) { var $h2 = $("h2"); var h2_text = $h2.text(); var match; var new_header; if (match = h2_text.match(/\[(.*)\] (.*)/)) { new_header = "
| " + match[2] + " |
" + h2_text + "
" + h2_text + "
" + h2_text + "
" + h2_text + "