Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ahwitz committed Dec 9, 2014
2 parents 400a804 + fad8975 commit adabf90
Show file tree
Hide file tree
Showing 16 changed files with 943 additions and 397 deletions.
8 changes: 3 additions & 5 deletions build/css/diva.css
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,18 @@
float: right;
}
.diva-link-popup {
font-size: 10pt;
background: #ffffff;
border: 1px solid #dddddd;
height: 28px;
width: 230px;
position: absolute;
padding: 5px;
padding: .6em;
z-index: 101;
-webkit-box-shadow: 2px 2px 4px 0 rgba(0, 0, 0, 0.5);
-moz-box-shadow: 2px 2px 4px 0 rgba(0, 0, 0, 0.5);
box-shadow: 2px 2px 4px 0 rgba(0, 0, 0, 0.5);
}
.diva-link-popup input {
width: 226px;
margin-top: 5px;
width: 15em;
}
.diva-link-popup input:focus {
outline: none;
Expand Down
2 changes: 1 addition & 1 deletion build/css/diva.min.css

Large diffs are not rendered by default.

316 changes: 200 additions & 116 deletions build/js/diva.js

Large diffs are not rendered by default.

229 changes: 116 additions & 113 deletions build/js/diva.min.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions build/js/plugins/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Allows you to highlight regions of a page image
init: function(divaSettings, divaInstance)
{
// initialize an empty highlights object.
divaSettings.parentSelector.data('highlights', {});
divaSettings.parentObject.data('highlights', {});

/*
When a new page is loaded, this method will be called with the
Expand All @@ -35,7 +35,7 @@ Allows you to highlight regions of a page image
*/
function _highlight(pageIdx, filename, pageSelector)
{
var highlightObj = divaSettings.parentSelector.data('highlights');
var highlightObj = divaSettings.parentObject.data('highlights');

if (typeof highlightObj === 'undefined')
return;
Expand Down Expand Up @@ -112,15 +112,15 @@ Allows you to highlight regions of a page image
parentObj.removeChild(descendents[j]);
}

divaSettings.parentSelector.data('highlights', {});
divaSettings.parentObject.data('highlights', {});
};

/*
Resets the highlights for a single page.
*/
divaInstance.removeHighlightsOnPage = function(pageIdx)
{
var highlightsObj = divaSettings.parentSelector.data('highlights');
var highlightsObj = divaSettings.parentObject.data('highlights');
if (highlightsObj.hasOwnProperty(pageIdx))
{
var pageId = divaInstance.getInstanceId() + 'page-' + pageIdx;
Expand Down Expand Up @@ -179,7 +179,7 @@ Allows you to highlight regions of a page image
}

var maxZoom = divaInstance.getMaxZoomLevel();
var highlightsObj = divaSettings.parentSelector.data('highlights');
var highlightsObj = divaSettings.parentObject.data('highlights');

highlightsObj[pageIdx] = {
'regions': regions, 'colour': colour, 'divClass': divClass
Expand All @@ -200,7 +200,7 @@ Allows you to highlight regions of a page image
},
destroy: function (divaSettings, divaInstance)
{
divaSettings.parentSelector.removeData('highlights');
divaSettings.parentObject.removeData('highlights');
},
pluginName: 'highlight',
titleText: 'Highlight regions of pages'
Expand Down
155 changes: 155 additions & 0 deletions build/js/plugins/pagealias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
Diva.JS pagealias plugin
Author: Andrew Horwitz
Lets pages be set up with custom aliases to allow for sections with different
numbering schemas.
Diva needs to be instantiated with one or both of the following settings:
1) a pageAliases dictionary attribute, structured as {(0-indexed page index):
(aliased page index)}. For example, a document with three forward pages may be
constructed as:
{0: 'i', 1: 'ii', 2: 'iii'}
This object does not need to have a complete list of possible page indices.
2) a pageAliasFunction function that takes in a 0-indexed integer value (the
original page index) and returns either the aliased page index or the boolean
value "false". For example, the default mapping from 0-index to 1-index may be
constructed as:
pageAliasFunction: function(originalPageIndex)
{
return originalPageIndex + 1;
}
This plugin is solely for cosmetic purposes; it will replace the "Page _ of XX"
counter and add functions that run in parallel with their non-aliased
equivalents instead of replacing them. When one of the aliased functions is
called, the plugin will first try to find the page alias in the pageAliases
attribute. If this fails, the plugin will then pass the original page index into
the pageAliasFunction function. If this function returns a boolean "false" (NOT
a number 0 or an undefined), the plugin will revert to the default page index.
The plugin may also be instantiated with the 'divaSettings.newTotalPages'
attribute, which will replace the "Page 1 of __" counter.
*/

(function ($)
{
window.divaPlugins.push((function()
{
var settings = {};
var retval =
{
init: function(divaSettings, divaInstance)
{
if (divaSettings.pageAliases === undefined)
{
divaSettings.pageAliases = {};
}

if (divaSettings.pageAliasFunction === undefined)
{
divaSettings.pageAliasFunction = function(){return false;};
}

/*
Main function. Will return the first of these three that
resolves to boolean true:
-Explicit alias as defined in pageAliases
-Result of pageAliasFunction
-originalPageIndex + 1 (to simulate the original mapping)
Else the function will return false.
*/
divaInstance.getAliasForPageIndex = function(originalPageIndex)
{
return divaSettings.pageAliases[originalPageIndex] || divaSettings.pageAliasFunction(originalPageIndex) || originalPageIndex + 1;
};

/*
Returns the first page index found for a given aliased number or false if not found.
This may cause issues if a specific alias is found for multiple page indices; use getPageIndicesForAlias and reimplement functions as necessary if this is the case.
*/
divaInstance.getPageIndexForAlias = function(aliasedNumber)
{
for(var idx = 0; idx < divaSettings.numPages; idx++)
{
if(divaInstance.getAliasForPageIndex(idx) == aliasedNumber)
{
return idx;
}
}
return false;
};

//Returns array of page indices for a given aliased number. Returns an empty array if none are found.
divaInstance.getPageIndicesForAlias = function(aliasedNumber)
{
var indexArr = [];
for(var idx = 0; idx < divaSettings.numPages; idx++)
{
if(divaInstance.getAliasForPageIndex(idx) == aliasedNumber)
{
indexArr.push(idx);
}
}
return indexArr;
};


//Maps the current page index to getAliasForPageIndex
divaInstance.getCurrentAliasedPageIndex = function()
{
return divaInstance.getAliasForPageIndex(divaSettings.currentPageIndex);
};

//Wrapper for gotoPageByIndex, keeping the aliased numbers in mind
divaInstance.gotoPageByAliasedNumber = function(aliasedNumber, xAnchor, yAnchor)
{
return divaInstance.gotoPageByIndex(divaInstance.getPageIndexForAlias(aliasedNumber), xAnchor, yAnchor);
};

//this function overwrites updateCurrentPage from the main diva file to update page numbers on VisiblePAgeDidChange
updateCurrentAliasedPage = function ()
{
document.getElementById(this.getSettings().ID + 'current-page').textContent = this.getCurrentAliasedPageIndex();
};

//various changes that need to be made once viewer is loaded
initialChanges = function ()
{
//changes total pages value in GUI
var tempSettings = this.getSettings();
var newTotalPages = tempSettings.numPages;
if (tempSettings.newTotalPages !== undefined)
{
newTotalPages = tempSettings.newTotalPages;
}

else if (tempSettings.totalPageOffset !== undefined)
{
newTotalPages = newTotalPages + tempSettings.totalPageOffset;
}

//actually changes values
document.getElementById(this.getSettings().ID + 'num-pages').textContent = newTotalPages;
document.getElementById(this.getSettings().ID + 'current-page').textContent = this.getCurrentAliasedPageIndex();

//resubscribes our new update function
diva.Events.unsubscribe(["VisiblePageDidChange", tempSettings.toolbar.updateCurrentPage]);
diva.Events.subscribe("VisiblePageDidChange", updateCurrentAliasedPage);
};

diva.Events.subscribe("ViewerDidLoad", initialChanges);
},
pluginName: 'pagealias',
titleText: 'Re-aliases page indexes'
};
return retval;
})());
})(jQuery);
7 changes: 5 additions & 2 deletions build/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,24 +717,27 @@ var diva = (function() {
* @method unsubscribe
* @param handle {Array}
* @param completely {Boolean} - Unsubscribe all events for a given topic.
* @return success {Boolean}
*/
unsubscribe: function (handle, completely)
{
var t = handle[0],
i = cache[t].length;
var t = handle[0];

if (cache[t])
{
var i = cache[t].length;
while (i--)
{
if (cache[t][i] === handle[1])
{
cache[t].splice(i, 1);
if (completely)
delete cache[t];
return true;
}
}
}
return false;
},
/**
* diva.Events.unsubscribeAll
Expand Down
7 changes: 3 additions & 4 deletions source/css/diva.less
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,16 @@
}

.diva-link-popup {
font-size: 10pt;
background: @linkBg;
.frame(@linkFrame);
.size(28px, 230px);
position: absolute;
padding: 5px;
padding: .6em;
z-index: @fullscreenZIndex + 1;
.pretty-shadow;

input {
width: 226px;
margin-top: 5px;
width: 15em;
&:focus {
outline: none;
}
Expand Down
Loading

0 comments on commit adabf90

Please sign in to comment.