Skip to content

Instantly share code, notes, and snippets.

@lakenen
Last active August 29, 2015 14:04
Show Gist options
  • Save lakenen/e230550bbf6fc050eb67 to your computer and use it in GitHub Desktop.
Save lakenen/e230550bbf6fc050eb67 to your computer and use it in GitHub Desktop.
Offset first page in viewer.js LAYOUT_PRESENTATION_TWO_PAGE
Crocodoc.addDataProvider('page-offset', function (scope) {
return {
get: function (type, key) {
var $p, dp = scope.getDataProvider(type);
if (type === 'metadata') {
$p = dp.get(type);
return $p.then(function (data) {
data.numpages += 1;
var page,
exceptions = data.dimensions.exceptions,
newExceptions = {};
for (page in exceptions) {
newExceptions[parseInt(page, 10) + 1] = exceptions[page];
}
data.dimensions.exceptions = newExceptions;
return data;
}).promise({
abort: $p.abort
});
} else if (type === 'page-svg' || type === 'page-text') {
key -= 1;
if (key === 0) {
return $.Deferred().resolve('').promise({
abort: function () {}
});
}
return dp.get(type, key);
} else if (type === 'page-img') {
key -= 1;
if (key === 0) {
return $.Deferred().resolve(new Image()).promise({
abort: function () {}
});
}
return dp.get(type, key);
}
}
};
});
.crocodoc-page:first-child {
visibility: hidden !important;
}
var viewer = Crocodoc.createViewer('.container', {
url: '...',
dataProviders: {
metadata: 'page-offset',
'page-svg': 'page-offset',
'page-text': 'page-offset',
'page-img': 'page-offset'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment