Commit 73e7dcd5 authored by Lingnan Wu's avatar Lingnan Wu

change the javascript base on the file_name_list.

parent b059a35a
...@@ -58,11 +58,26 @@ absolute_url = "%s" % context.absolute_url()\n ...@@ -58,11 +58,26 @@ absolute_url = "%s" % context.absolute_url()\n
\n \n
return """\n return """\n
\n \n
var slide_total_pages=1\n
var slide_current_page=""\n var slide_current_page=""\n
var slide_current_page_number=0\n
var current_page_is_img=true\n
img_file_name_list=[]\n
text_file_name_list=[]\n
\n \n
function goToNewSlide(relative_path){\n function goToNewSlide(relative_path){\n
slide_current_page=relative_path;\n slide_current_page=relative_path;\n
for (var j=0; j<img_file_name_list.length; j++) {\n
if (img_file_name_list[j].match(slide_current_page)){\n
slide_current_page_number=j;\n
current_page_is_img=true; \n
}\n
}\n
for (var j=0; j<text_file_name_list.length; j++) {\n
if (text_file_name_list[j].match(slide_current_page)){\n
slide_current_page_number=j;\n
current_page_is_img=false; \n
}\n
}\n
$.ajax({\n $.ajax({\n
url: %(absolute_url)s+"/"+relative_path,\n url: %(absolute_url)s+"/"+relative_path,\n
type: \'get\',\n type: \'get\',\n
...@@ -72,7 +87,45 @@ function goToNewSlide(relative_path){\n ...@@ -72,7 +87,45 @@ function goToNewSlide(relative_path){\n
} \n } \n
});\n });\n
renderNavigation();\n renderNavigation();\n
resetPageSelector();\n $("#slide_selection_index").val(slide_current_page_number+1);\n
}\n
\n
function getFileNameList(){\n
var file_name_list=[];\n
$.ajax({\n
url: %(absolute_url)s+"/"+"getPresentationFileNameList",\n
type: \'get\',\n
async: false,\n
success: function(data) {\n
file_name_list=$.parseJSON(data);\n
} \n
});\n
return file_name_list;\n
}\n
\n
function getImgFileNameList(file_name_list){\n
var img_list=[];\n
var img_list_without_first=[];\n
var img_first=[];\n
for (var i=0; i<file_name_list.length; i++) {\n
if(file_name_list[i].indexOf(".impr.")!=-1)\n
img_first.push(file_name_list[i]); \n
else if(file_name_list[i].indexOf("img")!=-1)\n
img_list_without_first.push(file_name_list[i]);\n
}\n
img_list_without_first.sort();\n
img_list=img_first.concat(img_list_without_first)\n
return img_list;\n
}\n
\n
function getTextFileNameList(file_name_list){\n
var text_list=[];\n
for (var i=0; i<file_name_list.length; i++) {\n
if(file_name_list[i].indexOf("text")!=-1)\n
text_list.push(file_name_list[i]);\n
}\n
text_list.sort();\n
return text_list;\n
}\n }\n
\n \n
function resetNavigation(name,id_a,id_img,class_default,class_hide){\n function resetNavigation(name,id_a,id_img,class_default,class_hide){\n
...@@ -102,62 +155,38 @@ function renderNavigation(){\n ...@@ -102,62 +155,38 @@ function renderNavigation(){\n
resetNavigation("Graphics","graphics_slide","graphics_slide_img","graphics","graphics hidden");\n resetNavigation("Graphics","graphics_slide","graphics_slide_img","graphics","graphics hidden");\n
}\n }\n
\n \n
function resetPageSelector(){\n function redirectPresentationPage(slide_total_pages){\n
$("#slides_total_number").text(slide_total_pages);\n next_page_number = $("#slide_selection_index").val()\n
$("#slide_selection_index").keyup(function(event) {\n
if (event.keyCode==13) {\n
redirectPresentationPage()\n
}\n
});\n
if(slide_current_page.indexOf("text")==-1){\n
if(parseInt(slide_current_page.replace(".html","").replace("img","")))\n
$("#slide_selection_index").val(parseInt(slide_current_page.replace(".html","").replace("img",""))+1);\n
else\n
$("#slide_selection_index").val(1);\n
}\n
else\n
if(parseInt(slide_current_page.replace(".html","").replace("text","")))\n
$("#slide_selection_index").val(parseInt(slide_current_page.replace(".html","").replace("text",""))+1);\n
else\n
$("#slide_selection_index").val(1);\n
}\n
\n
function redirectPresentationPage(){\n
//Graphic pages\n //Graphic pages\n
if(slide_current_page.indexOf("text")==-1){\n if(current_page_is_img){\n
if(slide_total_pages!=1)\n //if entered number bigger than total number, go to last page, else incorrect number go to first page\n
{\n if( next_page_number>1 && next_page_number<slide_total_pages){\n
//if entered number bigger than total number, go to last page, else incorrect number go to first page\n real_page_number=next_page_number-1;\n
if( $("#slide_selection_index").val()>1 && $("#slide_selection_index").val()<slide_total_pages){\n goToNewSlide(img_file_name_list[real_page_number]);\n
real_page_number=$("#slide_selection_index").val()-1;\n }\n
goToNewSlide("img"+real_page_number+".html");\n else if(next_page_number>=slide_total_pages){\n
}\n real_page_number=slide_total_pages-1\n
else if($("#slide_selection_index").val()>=slide_total_pages){\n goToNewSlide(img_file_name_list[real_page_number]);\n
real_page_number=slide_total_pages-1\n }\n
goToNewSlide("img"+real_page_number+".html");\n else{\n
}\n goToNewSlide(img_file_name_list[0]);\n
else{\n
goToNewSlide("asPresentationHTML");\n
}\n
}\n }\n
else\n
goToNewSlide("asPresentationHTML");\n
}\n }\n
//Text pages\n //Text pages\n
else{\n else{\n
//if entered number bigger than total number, go to last page, else incorrect number go to first page\n //if entered number bigger than total number, go to last page, else incorrect number go to first page\n
if( $("#slide_selection_index").val()>1 && $("#slide_selection_index").val()<slide_total_pages){\n if( next_page_number>1 && next_page_number<slide_total_pages){\n
real_page_number=$("#slide_selection_index").val()-1;\n real_page_number=next_page_number-1;\n
goToNewSlide("text"+real_page_number+".html");\n goToNewSlide(text_file_name_list[real_page_number]);\n
}\n }\n
else if($("#slide_selection_index").val()>=slide_total_pages){\n else if(next_page_number>=slide_total_pages){\n
real_page_number=slide_total_pages-1\n real_page_number=slide_total_pages-1\n
goToNewSlide("text"+real_page_number+".html");\n goToNewSlide(text_file_name_list[real_page_number]);\n
}\n }\n
else{\n else{\n
goToNewSlide("text0.html");\n goToNewSlide(text_file_name_list[0]);\n
}\n }\n
} \n }\n
}\n }\n
\n \n
function preventEnterKeyInGlobal(){\n function preventEnterKeyInGlobal(){\n
...@@ -177,13 +206,17 @@ function preventEnterKeyInGlobal(){\n ...@@ -177,13 +206,17 @@ function preventEnterKeyInGlobal(){\n
}\n }\n
\n \n
$(document).ready(function() {\n $(document).ready(function() {\n
goToNewSlide("asPresentationHTML");\n file_name_list=getFileNameList();\n
var last_page_href=$("a:contains(\'Last page\')").attr("href");\n img_file_name_list=getImgFileNameList(file_name_list);\n
if(last_page_href)\n text_file_name_list=getTextFileNameList(file_name_list);\n
slide_total_pages=parseInt(last_page_href.replace(".html","").replace("img",""))+1;\n slide_total_pages=file_name_list.length/2;\n
else\n $("#slides_total_number").text(slide_total_pages);\n
slide_total_pages=1;\n $("#slide_selection_index").keyup(function(event) {\n
resetPageSelector();\n if (event.keyCode==13) {\n
redirectPresentationPage(slide_total_pages)\n
}\n
});\n
goToNewSlide(img_file_name_list[0]);\n
preventEnterKeyInGlobal();\n preventEnterKeyInGlobal();\n
});\n });\n
\n \n
......
1270 1271
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment