Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
dde2cd0b
Commit
dde2cd0b
authored
Feb 25, 2013
by
Brian Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get chapter links to start working
parent
fa00ea44
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
95 deletions
+110
-95
common/static/js/pdfviewer.js
+80
-42
lms/djangoapps/staticbook/views.py
+0
-1
lms/templates/static_pdfbook.html
+30
-52
No files found.
common/static/js/pdfviewer.js
View file @
dde2cd0b
...
...
@@ -27,7 +27,20 @@ PDFJS.disableWorker = true;
var
pdfViewer
=
this
;
var
pdfDocument
=
null
;
var
url
=
options
[
'url'
];
var
url
=
null
;
if
(
options
.
url
)
{
url
=
options
.
url
;
}
var
chapter_urls
=
null
;
if
(
options
.
chapters
)
{
chapter_urls
=
options
.
chapters
;
}
var
chapterNum
=
1
;
if
(
options
.
chapterNum
)
{
chapterNum
=
options
.
chapterNum
;
// TODO: this should only be specified if there are
// chapters, and it should be in-bounds.
}
var
pageNum
=
1
;
if
(
options
.
pageNum
)
{
pageNum
=
options
.
pageNum
;
...
...
@@ -47,25 +60,25 @@ PDFJS.disableWorker = true;
var
setupText
=
function
setupText
(
textdiv
,
content
,
viewport
)
{
function
getPageNumberFromDest
(
dest
)
{
var
destPage
=
1
;
if
(
dest
instanceof
Array
)
{
var
destRef
=
dest
[
0
];
if
(
destRef
instanceof
Object
)
{
// we would need to look this up in the
// list of all pages that have been loaded,
// but we're trying to not have to load all the pages
// right now.
// destPage = this.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R'];
}
else
{
destPage
=
(
destRef
+
1
);
}
}
return
destPage
;
}
var
destPage
=
1
;
if
(
dest
instanceof
Array
)
{
var
destRef
=
dest
[
0
];
if
(
destRef
instanceof
Object
)
{
// we would need to look this up in the
// list of all pages that have been loaded,
// but we're trying to not have to load all the pages
// right now.
// destPage = this.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R'];
}
else
{
destPage
=
(
destRef
+
1
);
}
}
return
destPage
;
}
function
bindLink
(
link
,
dest
)
{
// get page number from dest:
destPage
=
getPageNumberFromDest
(
dest
);
// get page number from dest:
destPage
=
getPageNumberFromDest
(
dest
);
link
.
href
=
'#page='
+
destPage
;
link
.
onclick
=
function
pageViewSetupLinksOnclick
()
{
if
(
dest
&&
dest
instanceof
Array
)
...
...
@@ -135,10 +148,10 @@ PDFJS.disableWorker = true;
// Get page info from document, resize canvas accordingly, and render page
//
renderPage
=
function
(
num
)
{
// don't try to render a page that cannot be rendered
if
(
num
<
1
||
num
>
pdfDocument
.
numPages
)
{
return
;
}
// don't try to render a page that cannot be rendered
if
(
num
<
1
||
num
>
pdfDocument
.
numPages
)
{
return
;
}
// Update logging:
log_event
(
"book"
,
{
"type"
:
"gotopage"
,
"old"
:
pageNum
,
"new"
:
num
});
...
...
@@ -268,21 +281,25 @@ PDFJS.disableWorker = true;
// Asynchronously download PDF as an ArrayBuffer
//
loadUrl
=
function
pdfViewLoadUrl
(
url_to_load
)
{
PDFJS
.
getDocument
(
url
).
then
(
function
getDocument
(
_pdfDocument
)
{
pdfDocument
=
_pdfDocument
;
// display the current page with a default scale value:
parseScale
(
DEFAULT_SCALE_VALUE
);
},
function
getDocumentError
(
message
,
exception
)
{
// placeholder: don't expect errors :)
},
function
getDocumentProgress
(
progressData
)
{
// placeholder: not yet ready to display loading progress
});
};
loadUrl
(
url
);
PDFJS
.
getDocument
(
url_to_load
).
then
(
function
getDocument
(
_pdfDocument
)
{
pdfDocument
=
_pdfDocument
;
// display the current page with a default scale value:
currentScale
=
UNKNOWN_SCALE
;
parseScale
(
DEFAULT_SCALE_VALUE
);
},
function
getDocumentError
(
message
,
exception
)
{
// placeholder: don't expect errors :)
},
function
getDocumentProgress
(
progressData
)
{
// placeholder: not yet ready to display loading progress
});
};
loadChapterUrl
=
function
pdfViewLoadChapterUrl
(
chapter_index
)
{
var
chapter_url
=
chapter_urls
[
chapter_index
];
loadUrl
(
chapter_url
);
}
$
(
"#previous"
).
click
(
function
(
event
)
{
prevPage
();
...
...
@@ -303,12 +320,33 @@ PDFJS.disableWorker = true;
parseScale
(
this
.
value
);
});
$
(
'#pageNumber'
).
change
(
function
(
event
)
{
var
newPageVal
=
parseInt
(
this
.
value
);
if
(
newPageVal
)
{
renderPage
(
newPageVal
);
}
var
newPageVal
=
parseInt
(
this
.
value
);
if
(
newPageVal
)
{
renderPage
(
newPageVal
);
}
});
return
pdfViewer
;
// define navigation links for chapters:
if
(
chapter_urls
!=
null
)
{
var
loadChapterUrlHelper
=
function
(
i
)
{
return
function
(
event
)
{
loadChapterUrl
(
i
);
};
};
for
(
var
index
=
1
;
index
<=
chapter_urls
.
length
;
index
+=
1
)
{
$
(
"#pdfchapter-"
+
index
).
click
(
loadChapterUrlHelper
(
index
));
}
}
// finally, load the appropriate page
if
(
url
!=
null
)
{
loadUrl
(
url
);
}
else
{
loadChapterUrl
(
chapterNum
);
}
return
pdfViewer
;
}
})(
jQuery
);
lms/djangoapps/staticbook/views.py
View file @
dde2cd0b
...
...
@@ -66,5 +66,4 @@ def pdf_index(request, course_id, book_index, chapter=None, page=None):
'textbook'
:
textbook
,
'chapter'
:
chapter
,
'page'
:
page
,
'chapter'
:
chapter
,
'staff_access'
:
staff_access
})
lms/templates/static_pdfbook.html
View file @
dde2cd0b
...
...
@@ -17,45 +17,27 @@
<
%
block
name=
"js_extra"
>
<script
type=
"text/javascript"
>
%
if
'url'
in
textbook
:
var
url
=
"${textbook['url']}"
;
$
(
document
).
ready
(
function
()
{
$
(
'#outerContainer'
).
PDFViewer
(
{
%
if
page
is
not
None
:
'pageNum'
:
$
{
page
},
%
endif
'url'
:
url
});
var
options
=
{};
%
if
'url'
in
textbook
:
options
.
url
=
"${textbook['url']}"
;
%
endif
%
if
'chapters'
in
textbook
:
var
chptrs
=
[];
%
for
chap
in
textbook
[
'chapters'
]:
chptrs
.
push
(
"${chap['url']}"
);
%
endfor
options
.
chapters
=
chptrs
;
%
endif
%
if
chapter
is
not
None
:
options
.
chapterNum
:
$
{
chapter
};
%
endif
%
if
page
is
not
None
:
options
.
pageNum
:
$
{
page
};
%
endif
$
(
'#outerContainer'
).
PDFViewer
(
options
);
});
%
else
:
var
my_pdfviewer
=
null
;
function
load_url
(
url_to_load
,
page_to_load
)
{
// $('#outerContainer').PDFViewer( {
// 'pageNum' : page_to_load,
// 'url' : url_to_load
// });
my_pdfviewer
.
loadUrl
(
url_to_load
,
page_to_load
);
}
// since we have no url, we must rely on chapter display,
// so make sure we have a value.
var
url
=
"${ textbook['chapters'][chapter-1 if chapter is not None else 0]['url'] }"
;
$
(
document
).
ready
(
function
()
{
// load_url(url, ${page if page is not None else 1});
var
my_pdfviewer
=
$
(
'#outerContainer'
).
PDFViewer
(
{
'pageNum'
:
$
{
page
if
page
is
not
None
else
1
},
'url'
:
url
});
if
(
my_pdfviewer
)
{
}
}
);
%
endif
</script>
</
%
block>
...
...
@@ -121,25 +103,21 @@
%if 'chapters' in textbook:
<section
aria-label=
"Textbook Navigation"
class=
"book-sidebar"
>
<ul
id=
"pdfbooknav"
class=
"treeview-booknav"
>
<
%
def
name=
"print_entry(entry)"
>
<li>
<a
href=
"javascript:load_url(${entry.get('url')}, 1)"
>
<span
class=
"chapter"
>
${entry.get('title')}
</span>
</a>
</li>
<div
id=
"pdfbooknav"
class=
"treeview-booknav"
>
<
%
def
name=
"print_entry(entry, index_value)"
>
<div
id=
"pdfchapter-${index_value}"
>
<span
class=
"chapter"
>
${entry.get('title')}
</span>
</div>
</
%
def>
<
%
index =
0
%
>
% for entry in textbook['chapters']:
${print_entry(entry)}
<
%
index
+=
1
%
>
${print_entry(entry, index)}
% endfor
## Don't delete this empty list item. Without it, Jquery.TreeView won't
## render the last list item as expandable.
<li></li>
</ul>
</div>
</section>
%endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment