Skip to content

Instantly share code, notes, and snippets.

@lancehilliard
Created February 28, 2012 18:30
Show Gist options
  • Save lancehilliard/1934168 to your computer and use it in GitHub Desktop.
Save lancehilliard/1934168 to your computer and use it in GitHub Desktop.
ImageGear for .NET Online Demo (http://igdemos.accusoft.com/imageGearAspNet19/Demo/) "FileList" object
var FileList = {
currentPage: null,
fileList: [],
documentInfo: {},
get_fileCount: function() {
return FileList.fileList.length;
},
set_currentPage: function(newCurrentPage) {
if (FileList.currentPage !== null) {
if (FileList.currentPage.fileIndex === newCurrentPage.fileIndex && FileList.currentPage.pageIndex === newCurrentPage.pageIndex) {
// This is the same page, so we don't have to do anything.
return;
}
}
FileList.currentPage = newCurrentPage;
var file = this.fileList[FileList.currentPage.fileIndex];
viewer.openPage({ documentIdentifier: file.documentIdentifier, pageNumber: FileList.currentPage.pageIndex, fitType: ImageGear.Web.UI.FitType.FullWidth, artPage: file.getArtPage(FileList.currentPage.pageIndex) });
$('.currentThumbnailHighlight').removeClass('currentThumbnailHighlight');
var highlightSelector = '.thumbnailPage' + FileList.currentPage.pageIndex.toString();
var highlightControl = $(file.thumbnailRoot).find(highlightSelector);
var highlight = highlightControl.prev();
if (highlight.length === 0) {
highlight = $(file.thumbnailRoot).find('.ellipsis').find('.thumbnailHighlight');
}
highlight.addClass('currentThumbnailHighlight');
var position = highlight.parents('.thumbnailSingleSection').position();
var sectionHeight = 226;
var thumbnailArea = $('.thumbnailArea').get(0);
var areaHeight = thumbnailArea.clientHeight;
if (position.top + sectionHeight > areaHeight) {
thumbnailArea.scrollTop = thumbnailArea.scrollTop + position.top + sectionHeight - areaHeight;
}
if (position.top < 0) {
thumbnailArea.scrollTop = thumbnailArea.scrollTop + position.top;
}
},
get_currentPage: function() {
if (FileList.currentPage === null) {
FileList.currentPage = new Page();
}
return FileList.currentPage;
},
addFile: function(largeThumbnailControl) {
var documentIdentifier = largeThumbnailControl.get_currentState().documentIdentifier;
var thumbnailRoot = $(largeThumbnailControl.get_element()).parents('.thumbnailRoot').get(0);
FileList.fileList.push(new File(documentIdentifier, thumbnailRoot));
this.processDocumentInfo();
},
addDocumentInfo: function(pageView) {
var documentIdentifier = pageView.get_documentIdentifier();
this.documentInfo[documentIdentifier] = { pageCount: pageView.get_documentPageCount() };
var artPage, i;
for (i = 0; i < FileList.fileList.length; i++) {
if (FileList.fileList[i].documentIdentifier === documentIdentifier) {
artPage = FileList.fileList[i].getArtPage(pageView.get_pageNumber());
}
}
if (artPage !== pageView.get_artPage()) {
// The page view is using a different ArtPage, replace it with the one associated with this page.
// This happened because the server control created this viewer and gave it a new ArtPage.
pageView.set_artPage(artPage);
}
this.processDocumentInfo();
},
processDocumentInfo: function() {
var fileIndex;
var controlDomElement, control;
for (fileIndex = 0; fileIndex < this.fileList.length; fileIndex++) {
var file = this.fileList[fileIndex];
if (!file.pageCountIsKnown) {
var info = this.documentInfo[file.documentIdentifier];
if (info !== undefined) {
file.pageCount = info.pageCount;
file.pageCountIsKnown = true;
controlDomElement = $(file.thumbnailRoot).find('.thumbnailPage0').get(0);
controlDomElement.thumbnailFileIndex = fileIndex;
controlDomElement.thumbnailPageIndex = 0;
control = $find(controlDomElement.id);
control.add_mouseUp(onThumbnailMouseUp);
if (file.pageCount > 1) {
$(file.thumbnailRoot).addClass('multipageThumbnail');
controlDomElement = $(file.thumbnailRoot).find('.thumbnailPage1').get(0);
controlDomElement.thumbnailFileIndex = fileIndex;
controlDomElement.thumbnailPageIndex = 1;
control = $find(controlDomElement.id);
control.openPage({ documentIdentifier: file.documentIdentifier, pageNumber: controlDomElement.thumbnailPageIndex, artPage: file.getArtPage(controlDomElement.thumbnailPageIndex) });
control.add_mouseUp(onThumbnailMouseUp);
controlDomElement = $(file.thumbnailRoot).find('.thumbnailPage2').get(0);
controlDomElement.thumbnailFileIndex = fileIndex;
controlDomElement.thumbnailPageIndex = 2;
control = $find(controlDomElement.id);
control.openPage({ documentIdentifier: file.documentIdentifier, pageNumber: controlDomElement.thumbnailPageIndex, artPage: file.getArtPage(controlDomElement.thumbnailPageIndex) });
control.add_mouseUp(onThumbnailMouseUp);
controlDomElement = $(file.thumbnailRoot).find('.thumbnailPageN').get(0);
controlDomElement.thumbnailFileIndex = fileIndex;
controlDomElement.thumbnailPageIndex = file.pageCount - 1;
$(controlDomElement).addClass('thumbnailPage' + controlDomElement.thumbnailPageIndex.toString());
control = $find(controlDomElement.id);
control.openPage({ documentIdentifier: file.documentIdentifier, pageNumber: controlDomElement.thumbnailPageIndex, artPage: file.getArtPage(controlDomElement.thumbnailPageIndex) });
control.add_mouseUp(onThumbnailMouseUp);
}
}
}
}
},
get_file: function(fileIndex) {
return FileList.fileList[fileIndex];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment