pdfjs版本替换
@@ -0,0 +1,128 @@
|
||||
let DEFAULT_URL = ''
|
||||
let url = decodeURIComponent(window.location.search)
|
||||
let attIdIndex = url.indexOf('&fileId=')
|
||||
let typeIndex = url.indexOf('?sarType=')
|
||||
let numberIndex = url.indexOf('&pageNumber=')
|
||||
let attId = ''
|
||||
let sarType = 'INLAND_STAND'
|
||||
let pageNumber = 1
|
||||
let pageCount = 1
|
||||
let fileId = ''
|
||||
let queryAttUrl = '/api/lawss/sarStandFile/queryConvertAtt'
|
||||
if (attIdIndex > -1) {
|
||||
attId = url.substring(attIdIndex + 8, url.length)
|
||||
pageNumber = url.substring(numberIndex + 12, attIdIndex)
|
||||
sarType = url.substring(typeIndex + 9, numberIndex)
|
||||
if (sarType === 'INLAND_LAWS' || sarType === 'FOREIGN_LAWS') {
|
||||
queryAttUrl = '/api/lawss/sarLawsFile/queryConvertAtt'
|
||||
} else if (sarType === 'BUSS') {
|
||||
queryAttUrl = '/api/lawss/sarBussStandFile/queryConvertAtt'
|
||||
}
|
||||
$.ajax({
|
||||
url: queryAttUrl,
|
||||
async: false,
|
||||
type: 'GET',
|
||||
data: {
|
||||
attId: attId
|
||||
},
|
||||
success: function (res) {
|
||||
// res = JSON.parse(res)
|
||||
if (res.data != null) {
|
||||
pageCount = res.data.pageCount
|
||||
if (res.data.fileOldName !== null && res.data.fileOldName !== undefined) {
|
||||
document.title = res.data.fileOldName + '-在线查看'
|
||||
}
|
||||
// $('#pageCount').html(res.data.pageCount)
|
||||
fileId = res.data.id
|
||||
getFileInfo()
|
||||
} else {
|
||||
alert('文档未转换成功或本地读取不到该文档')
|
||||
}
|
||||
},
|
||||
error: function (data) {
|
||||
alert('文档未转换成功或本地读取不到该文档')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// document.onkeydown = function () {
|
||||
// var e = window.event || arguments[0]
|
||||
// if (e.keyCode === 123) {
|
||||
// return false
|
||||
// } else if (e.ctrlKey || e.keyCode === 73) {
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
// document.oncontextmenu = function () {
|
||||
// return false
|
||||
// }
|
||||
|
||||
function getFileInfo () {
|
||||
$.ajax({
|
||||
url: '/api/lawss/sarFileInfo/getPdfFileInfo',
|
||||
async: false,
|
||||
type: 'GET',
|
||||
data: {
|
||||
sarFileId: fileId,
|
||||
filePageNumber: pageNumber
|
||||
},
|
||||
success: function (res) {
|
||||
res = JSON.parse(res)
|
||||
if (res.data != null) {
|
||||
if (res.data.fileInfo != null) {
|
||||
let data = res.data.fileInfo
|
||||
let resultFileMsg = data.substring(30, data.length - 50)
|
||||
resultFileMsg = resultFileMsg.replace(/\*/g, 'A')
|
||||
let password = res.data.filePwd
|
||||
sessionStorage.setItem('fileInfoSteam', password)
|
||||
writeFile(resultFileMsg)
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function (data) {
|
||||
alert('文档未转换成功或本地读取不到该文档')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function writeFile (data) {
|
||||
var BASE64_MARKER = ';base64,' // 声明文件流编码格式
|
||||
var pdfAsDataUri = data
|
||||
var pdfAsArray = convertDataURIToBinary(pdfAsDataUri)
|
||||
DEFAULT_URL = pdfAsArray
|
||||
if (Number(pageCount) > 1) {
|
||||
if (Number(pageNumber) === 1 && Number(pageNumber) !== Number(pageCount)) {
|
||||
$('#upLoadingFile').hide()
|
||||
$('#downLoadingFile').show()
|
||||
} else if (Number(pageNumber) !== 1 && Number(pageNumber) !== Number(pageCount)) {
|
||||
$('#upLoadingFile').show()
|
||||
$('#downLoadingFile').show()
|
||||
} else {
|
||||
$('#upLoadingFile').hide()
|
||||
$('#downLoadingFile').hide()
|
||||
}
|
||||
} else {
|
||||
$('#upLoadingFile').hide()
|
||||
$('#downLoadingFile').hide()
|
||||
}
|
||||
}
|
||||
|
||||
function clickLoadFile (type) {
|
||||
if (type === 'up') {
|
||||
pageNumber = Number(pageNumber) - Number(1)
|
||||
} else {
|
||||
pageNumber = Number(pageNumber) + Number(1)
|
||||
}
|
||||
window.location.href = '/static/pdf/web/viewer.html?sarType=' + sarType + '&pageNumber=' + pageNumber + '&fileId=' + encodeURIComponent(attId)
|
||||
}
|
||||
|
||||
function convertDataURIToBinary (dataURI) {
|
||||
var raw = window.atob(dataURI) // 这个方法在ie内核下无法正常解析。
|
||||
var rawLength = raw.length
|
||||
// 转换成pdf.js能直接解析的Uint8Array类型
|
||||
var array = new Uint8Array(new ArrayBuffer(rawLength))
|
||||
for (let i = 0; i < rawLength; i++) {
|
||||
array[i] = raw.charCodeAt(i)
|
||||
}
|
||||
return array
|
||||
}
|
||||
@@ -0,0 +1,569 @@
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
Copyright 2012 Mozilla Foundation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Adobe CMap resources are covered by their own copyright but the same license:
|
||||
|
||||
Copyright 1990-2015 Adobe Systems Incorporated.
|
||||
|
||||
See https://github.com/adobe-type-tools/cmap-resources
|
||||
-->
|
||||
<html dir="ltr" mozdisallowselectionprint moznomarginboxes>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta name="google" content="notranslate">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>在线查看</title>
|
||||
<link rel="stylesheet" href="bzzqyjViewer.css">
|
||||
<!-- This snippet is used in production (included from viewer.html) -->
|
||||
<link rel="resource" type="application/l10n" href="locale/locale.properties">
|
||||
<link rel="stylesheet" href="../../zTree/css/demo.css" type="text/css">
|
||||
<link rel="stylesheet" href="../../zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
|
||||
<style>
|
||||
/*.pdfViewer .page{*/
|
||||
/* margin: 1px auto -8px 232px;*/
|
||||
/*}*/
|
||||
.right-click-box{
|
||||
position: fixed;
|
||||
width: 100px;
|
||||
min-height: 100px;
|
||||
border-radius: 5px;
|
||||
background: #ffffff;
|
||||
display: none;
|
||||
z-index: 999;
|
||||
box-shadow: inset 0 0 2px 1px #e5e5e5;
|
||||
}
|
||||
.right-click-box p{
|
||||
padding: 5px 10px;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
/*.note-box{*/
|
||||
/* display: none;*/
|
||||
/* padding: 15px;*/
|
||||
/* width: 500px;*/
|
||||
/* height: 380px;*/
|
||||
/* position: fixed;*/
|
||||
/* top: 50%;*/
|
||||
/* left: 50%;*/
|
||||
/* transform: translate(-50%, -50%);*/
|
||||
/* border: 1px solid #e5e5e5;*/
|
||||
/* 8px;*/
|
||||
/* background: #e5e5e5;*/
|
||||
/* z-index: 999;*/
|
||||
/*}*/
|
||||
/*.note-title{*/
|
||||
/* padding-bottom: 10px;*/
|
||||
/*}*/
|
||||
/*.note-textarea{*/
|
||||
/* width: 500px;*/
|
||||
/* height: 300px;*/
|
||||
/*}*/
|
||||
/*.note-footer, .tree-add-footer{*/
|
||||
/* float: right;*/
|
||||
/* padding-top: 15px;*/
|
||||
/*}*/
|
||||
/*.note-footer button, .tree-add-footer button{*/
|
||||
/* width: 60px;*/
|
||||
/* height: 35px;*/
|
||||
/* line-height: 35px;*/
|
||||
/* background-color: #3391CE;*/
|
||||
/* border: #3391CE;*/
|
||||
/* color: #ffffff;*/
|
||||
/* 3px;*/
|
||||
/* cursor: pointer;*/
|
||||
/*}*/
|
||||
/*.note-float{*/
|
||||
/* box-shadow: inset 0 0 2px 1px #e5e5e5;*/
|
||||
/* min-width: 100px;*/
|
||||
/* min-height: 40px;*/
|
||||
/* padding: 10px;*/
|
||||
/* background: lemonchiffon;*/
|
||||
/*}*/
|
||||
/*.note-del{*/
|
||||
/* position: absolute;*/
|
||||
/* top: 2px;*/
|
||||
/* right: 5px;*/
|
||||
/* color: #707070;*/
|
||||
/* cursor: pointer;*/
|
||||
/*}*/
|
||||
/*.ztree{*/
|
||||
/* position: fixed;*/
|
||||
/* top: 32px;*/
|
||||
/* left: 0;*/
|
||||
/* z-index: 99;*/
|
||||
/* height: 100% !important;*/
|
||||
/*}*/
|
||||
/*#rMenu{*/
|
||||
/* position: fixed !important;*/
|
||||
/* z-index: 1000;*/
|
||||
/*}*/
|
||||
/*div#rMenu {position:absolute; visibility:hidden; top:0;text-align: left;padding: 2px;}*/
|
||||
/*div#rMenu ul li{*/
|
||||
/* padding: 0 15px;*/
|
||||
/* cursor: pointer;*/
|
||||
/* list-style: none;*/
|
||||
/* border: 1px solid #888;*/
|
||||
/* border-bottom: 1px solid transparent;*/
|
||||
/* background: #FFEBC0;*/
|
||||
/*}*/
|
||||
/*div#rMenu ul li:last-child{*/
|
||||
/* border-bottom: 1px solid #888;*/
|
||||
/* }*/
|
||||
/*div#rMenu ul li:hover{*/
|
||||
/* background: #FFC774;*/
|
||||
/* }*/
|
||||
/*.tree-add-modal{*/
|
||||
/* display: none;*/
|
||||
/* padding: 15px;*/
|
||||
/* width: 400px;*/
|
||||
/* height: 180px;*/
|
||||
/* position: fixed;*/
|
||||
/* top: 50%;*/
|
||||
/* left: 50%;*/
|
||||
/* transform: translate(-50%, -50%);*/
|
||||
/* border: 1px solid #e5e5e5;*/
|
||||
/* 8px;*/
|
||||
/* background: #e5e5e5;*/
|
||||
/* z-index: 999;*/
|
||||
/*}*/
|
||||
/*.tree-add-modal .form-box label{*/
|
||||
/* display: block;*/
|
||||
/* margin-top: 10px;*/
|
||||
/*}*/
|
||||
/*.tree-add-modal .form-box label span{*/
|
||||
/* display: inline-block;*/
|
||||
/* font-size: 14px;*/
|
||||
/* width: 80px;*/
|
||||
/*}*/
|
||||
/*.tree-add-modal .form-box label input{*/
|
||||
/* width: 200px;*/
|
||||
/* height: 40px;*/
|
||||
/* text-indent: 10px;*/
|
||||
/*}*/
|
||||
/*.mask{*/
|
||||
/* display: none;*/
|
||||
/* width: 100%;*/
|
||||
/* height: 100%;*/
|
||||
/* position: fixed;*/
|
||||
/* top: 0;*/
|
||||
/* bottom: 0;*/
|
||||
/* left: 0;*/
|
||||
/* right: 0;*/
|
||||
/* background: #000000;*/
|
||||
/* opacity: 0.5;*/
|
||||
/* z-index: 998;*/
|
||||
/*}*/
|
||||
.button-box{
|
||||
display: none;
|
||||
position: fixed;
|
||||
height: 26px;
|
||||
line-height: 26px;
|
||||
z-index: 999;
|
||||
border: 1px solid #e5e5e5;
|
||||
border-right: none;
|
||||
background: #ffffff;
|
||||
}
|
||||
.button-box span{
|
||||
display: inline-block;
|
||||
width: 52px;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
border-right: 1px solid #e5e5e5;
|
||||
cursor: default;
|
||||
}
|
||||
.hidden-textarea{
|
||||
position: fixed;
|
||||
z-index: -1;
|
||||
}
|
||||
</style>
|
||||
<script src="js/jquery-3.3.1.min.js"></script>
|
||||
<script src="compatibility.js"></script>
|
||||
<script src="l10n.js"></script>
|
||||
<script src="../build/pdf.js"></script>
|
||||
<!-- <script type="text/javascript" src="../../zTree/js/jquery.ztree.core.js"></script>-->
|
||||
<!--<script type="text/javascript" src="../../../src/assets/zTree/js/jquery.ztree.excheck.js"></script>-->
|
||||
<!--<script type="text/javascript" src="../../../src/assets/zTree/js/jquery.ztree.exedit.js"></script>-->
|
||||
<!--<script type="text/javascript" src="../../../src/assets/zTree/js/jquery.ztree.exhide.js"></script>-->
|
||||
<script src="bzzqyjViewer.js"></script>
|
||||
</head>
|
||||
|
||||
<body tabindex="1" class="loadingInProgress">
|
||||
<!--遮罩层-->
|
||||
<div class="mask"></div>
|
||||
<!-- <ul id="treeDemo" class="ztree"></ul>-->
|
||||
<!-- <div id="rMenu">-->
|
||||
<!-- <!– 不需要权限 –>-->
|
||||
<!-- <ul>-->
|
||||
<!-- <li class="m_add" id="rightAdd">节点新增</li>-->
|
||||
<!-- <!–<li class="m_edit" @click="rightEdit" v-show="!isRoot || root">{{ editTitle }}</li>–>-->
|
||||
<!-- <li class="m_del" id="rightRemove">节点删除</li>-->
|
||||
<!-- <!–<li class="m_copy" @click="rightCopy" v-show="!isRoot|| root">{{ copyTitle }}</li>–>-->
|
||||
<!-- </ul>-->
|
||||
<!-- </div>-->
|
||||
<!-- <!–新增tree弹窗–>-->
|
||||
<!-- <div class="tree-add-modal">-->
|
||||
<!-- <h5>节点新增</h5>-->
|
||||
<!-- <div class="form-box">-->
|
||||
<!-- <label><span>节点位置:</span><input class="title-name" type="number" name="titleName" placeholder="请输入页码" autocomplete="off" disabled/></label>-->
|
||||
<!-- <label><span>节点名称:</span><input class="menu-name" type="text" name="menuName" placeholder="请输入节点名称" autocomplete="off"/></label>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="tree-add-footer">-->
|
||||
<!-- <button id="treeAddCancel">取消</button>-->
|
||||
<!-- <button id="treeAddSave">保存</button>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<div id="outerContainer">
|
||||
|
||||
<div id="sidebarContainer">
|
||||
<div id="toolbarSidebar">
|
||||
<div class="splitToolbarButton toggled">
|
||||
<button id="viewThumbnail" class="toolbarButton toggled" title="Show Thumbnails" tabindex="2" data-l10n-id="thumbs">
|
||||
<span data-l10n-id="thumbs_label">Thumbnails</span>
|
||||
</button>
|
||||
<button id="viewOutline" class="toolbarButton" title="Show Document Outline (double-click to expand/collapse all items)" tabindex="3" data-l10n-id="document_outline">
|
||||
<span data-l10n-id="document_outline_label">Document Outline</span>
|
||||
</button>
|
||||
<button id="viewAttachments" class="toolbarButton" title="Show Attachments" tabindex="4" data-l10n-id="attachments">
|
||||
<span data-l10n-id="attachments_label">Attachments</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="sidebarContent">
|
||||
<div id="thumbnailView">
|
||||
</div>
|
||||
<div id="outlineView" class="hidden">
|
||||
</div>
|
||||
<div id="attachmentsView" class="hidden">
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- sidebarContainer -->
|
||||
|
||||
<div id="mainContainer">
|
||||
<div class="findbar hidden doorHanger" id="findbar">
|
||||
<div id="findbarInputContainer">
|
||||
<input id="findInput" class="toolbarField" title="Find" placeholder="Find in document…" tabindex="91" data-l10n-id="find_input">
|
||||
<div class="splitToolbarButton">
|
||||
<button id="findPrevious" class="toolbarButton findPrevious" title="Find the previous occurrence of the phrase" tabindex="92" data-l10n-id="find_previous">
|
||||
<span data-l10n-id="find_previous_label">Previous</span>
|
||||
</button>
|
||||
<div class="splitToolbarButtonSeparator"></div>
|
||||
<button id="findNext" class="toolbarButton findNext" title="Find the next occurrence of the phrase" tabindex="93" data-l10n-id="find_next">
|
||||
<span data-l10n-id="find_next_label">Next</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="findbarOptionsContainer">
|
||||
<input type="checkbox" id="findHighlightAll" class="toolbarField" tabindex="94">
|
||||
<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
|
||||
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
|
||||
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
|
||||
<span id="findResultsCount" class="toolbarLabel hidden"></span>
|
||||
</div>
|
||||
|
||||
<div id="findbarMessageContainer">
|
||||
<span id="findMsg" class="toolbarLabel"></span>
|
||||
</div>
|
||||
</div> <!-- findbar -->
|
||||
|
||||
<div id="secondaryToolbar" class="secondaryToolbar hidden doorHangerRight">
|
||||
<div id="secondaryToolbarButtonContainer">
|
||||
<button id="secondaryPresentationMode" class="secondaryToolbarButton presentationMode visibleLargeView" title="Switch to Presentation Mode" tabindex="51" data-l10n-id="presentation_mode">
|
||||
<span data-l10n-id="presentation_mode_label">Presentation Mode</span>
|
||||
</button>
|
||||
|
||||
<button id="secondaryOpenFile" class="secondaryToolbarButton openFile visibleLargeView" title="Open File" tabindex="52" data-l10n-id="open_file">
|
||||
<span data-l10n-id="open_file_label">Open</span>
|
||||
</button>
|
||||
|
||||
<button id="secondaryPrint" class="secondaryToolbarButton print visibleMediumView" title="Print" tabindex="53" data-l10n-id="print">
|
||||
<span data-l10n-id="print_label">Print</span>
|
||||
</button>
|
||||
|
||||
<button id="secondaryDownload" class="secondaryToolbarButton download visibleMediumView" title="Download" tabindex="54" data-l10n-id="download">
|
||||
<span data-l10n-id="download_label">Download</span>
|
||||
</button>
|
||||
|
||||
<a href="#" id="secondaryViewBookmark" class="secondaryToolbarButton bookmark visibleSmallView" title="Current view (copy or open in new window)" tabindex="55" data-l10n-id="bookmark">
|
||||
<span data-l10n-id="bookmark_label">Current View</span>
|
||||
</a>
|
||||
|
||||
<div class="horizontalToolbarSeparator visibleLargeView"></div>
|
||||
|
||||
<button id="firstPage" class="secondaryToolbarButton firstPage" title="Go to First Page" tabindex="56" data-l10n-id="first_page">
|
||||
<span data-l10n-id="first_page_label">Go to First Page</span>
|
||||
</button>
|
||||
<button id="lastPage" class="secondaryToolbarButton lastPage" title="Go to Last Page" tabindex="57" data-l10n-id="last_page">
|
||||
<span data-l10n-id="last_page_label">Go to Last Page</span>
|
||||
</button>
|
||||
|
||||
<div class="horizontalToolbarSeparator"></div>
|
||||
|
||||
<button id="pageRotateCw" class="secondaryToolbarButton rotateCw" title="Rotate Clockwise" tabindex="58" data-l10n-id="page_rotate_cw">
|
||||
<span data-l10n-id="page_rotate_cw_label">Rotate Clockwise</span>
|
||||
</button>
|
||||
<button id="pageRotateCcw" class="secondaryToolbarButton rotateCcw" title="Rotate Counterclockwise" tabindex="59" data-l10n-id="page_rotate_ccw">
|
||||
<span data-l10n-id="page_rotate_ccw_label">Rotate Counterclockwise</span>
|
||||
</button>
|
||||
|
||||
<div class="horizontalToolbarSeparator"></div>
|
||||
|
||||
<button id="cursorSelectTool" class="secondaryToolbarButton selectTool toggled" title="Enable Text Selection Tool" tabindex="60" data-l10n-id="cursor_text_select_tool">
|
||||
<span data-l10n-id="cursor_text_select_tool_label">Text Selection Tool</span>
|
||||
</button>
|
||||
<button id="cursorHandTool" class="secondaryToolbarButton handTool" title="Enable Hand Tool" tabindex="61" data-l10n-id="cursor_hand_tool">
|
||||
<span data-l10n-id="cursor_hand_tool_label">Hand Tool</span>
|
||||
</button>
|
||||
|
||||
<div class="horizontalToolbarSeparator"></div>
|
||||
|
||||
<button id="documentProperties" style="display: none" class="secondaryToolbarButton documentProperties" title="Document Properties…" tabindex="62" data-l10n-id="document_properties">
|
||||
<span data-l10n-id="document_properties_label">Document Properties…</span>
|
||||
</button>
|
||||
</div>
|
||||
</div> <!-- secondaryToolbar -->
|
||||
|
||||
<div class="toolbar">
|
||||
<div id="toolbarContainer">
|
||||
<div id="toolbarViewer">
|
||||
<div id="toolbarViewerLeft">
|
||||
<button id="sidebarToggle" class="toolbarButton" title="Toggle Sidebar" tabindex="11" data-l10n-id="toggle_sidebar">
|
||||
<span data-l10n-id="toggle_sidebar_label">Toggle Sidebar</span>
|
||||
</button>
|
||||
<div class="toolbarButtonSpacer"></div>
|
||||
<button id="viewFind" class="toolbarButton" title="Find in Document" tabindex="12" data-l10n-id="findbar">
|
||||
<span data-l10n-id="findbar_label">Find</span>
|
||||
</button>
|
||||
<div class="splitToolbarButton hiddenSmallView">
|
||||
<button class="toolbarButton pageUp" title="Previous Page" id="previous" tabindex="13" data-l10n-id="previous">
|
||||
<span data-l10n-id="previous_label">Previous</span>
|
||||
</button>
|
||||
<div class="splitToolbarButtonSeparator"></div>
|
||||
<button class="toolbarButton pageDown" title="Next Page" id="next" tabindex="14" data-l10n-id="next">
|
||||
<span data-l10n-id="next_label">Next</span>
|
||||
</button>
|
||||
</div>
|
||||
<input type="number" id="pageNumber" class="toolbarField pageNumber" title="Page" value="1" size="4" min="1" tabindex="15" data-l10n-id="page">
|
||||
<span id="numPages" class="toolbarLabel"></span>
|
||||
</div>
|
||||
<div id="toolbarViewerRight">
|
||||
<button id="presentationMode" class="toolbarButton presentationMode hiddenLargeView" title="Switch to Presentation Mode" tabindex="31" data-l10n-id="presentation_mode">
|
||||
<span data-l10n-id="presentation_mode_label">Presentation Mode</span>
|
||||
</button>
|
||||
|
||||
<button id="openFile" class="toolbarButton openFile hiddenLargeView" title="Open File" tabindex="32" data-l10n-id="open_file">
|
||||
<span data-l10n-id="open_file_label">Open</span>
|
||||
</button>
|
||||
|
||||
<button id="print" data-print="KLO98GHSDD" class="toolbarButton print hiddenMediumView" title="Print" tabindex="33" data-l10n-id="print">
|
||||
<span data-l10n-id="print_label">Print</span>
|
||||
</button>
|
||||
|
||||
<button id="download" style="visibility:hidden" class="toolbarButton download hiddenMediumView" title="Download" tabindex="34" data-l10n-id="download">
|
||||
<span data-l10n-id="download_label">Download</span>
|
||||
</button>
|
||||
<a href="#" id="viewBookmark" style="visibility:hidden" class="toolbarButton bookmark hiddenSmallView" title="Current view (copy or open in new window)" tabindex="35" data-l10n-id="bookmark">
|
||||
<span data-l10n-id="bookmark_label">Current View</span>
|
||||
</a>
|
||||
|
||||
<div class="verticalToolbarSeparator hiddenSmallView"></div>
|
||||
|
||||
<button id="secondaryToolbarToggle" class="toolbarButton" title="Tools" tabindex="36" data-l10n-id="tools">
|
||||
<span data-l10n-id="tools_label">Tools</span>
|
||||
</button>
|
||||
</div>
|
||||
<div id="toolbarViewerMiddle">
|
||||
<div class="splitToolbarButton">
|
||||
<button id="zoomOut" class="toolbarButton zoomOut" title="Zoom Out" tabindex="21" data-l10n-id="zoom_out">
|
||||
<span data-l10n-id="zoom_out_label">Zoom Out</span>
|
||||
</button>
|
||||
<div class="splitToolbarButtonSeparator"></div>
|
||||
<button id="zoomIn" class="toolbarButton zoomIn" title="Zoom In" tabindex="22" data-l10n-id="zoom_in">
|
||||
<span data-l10n-id="zoom_in_label">Zoom In</span>
|
||||
</button>
|
||||
</div>
|
||||
<span id="scaleSelectContainer" class="dropdownToolbarButton">
|
||||
<select id="scaleSelect" title="Zoom" tabindex="23" data-l10n-id="zoom">
|
||||
<option id="pageAutoOption" title="" value="auto" selected="selected" data-l10n-id="page_scale_auto">Automatic Zoom</option>
|
||||
<option id="pageActualOption" title="" value="page-actual" data-l10n-id="page_scale_actual">Actual Size</option>
|
||||
<option id="pageFitOption" title="" value="page-fit" data-l10n-id="page_scale_fit">Page Fit</option>
|
||||
<option id="pageWidthOption" title="" value="page-width" data-l10n-id="page_scale_width">Page Width</option>
|
||||
<option id="customScaleOption" title="" value="custom" disabled="disabled" hidden="true"></option>
|
||||
<option title="" value="0.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 50 }'>50%</option>
|
||||
<option title="" value="0.75" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 75 }'>75%</option>
|
||||
<option title="" value="1" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 100 }'>100%</option>
|
||||
<option title="" value="1.25" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 125 }'>125%</option>
|
||||
<option title="" value="1.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 150 }'>150%</option>
|
||||
<option title="" value="2" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 200 }'>200%</option>
|
||||
<option title="" value="3" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 300 }'>300%</option>
|
||||
<option title="" value="4" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 400 }'>400%</option>
|
||||
</select>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="loadingBar">
|
||||
<div class="progress">
|
||||
<div class="glimmer">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<menu type="context" id="viewerContextMenu">
|
||||
<menuitem id="contextFirstPage" label="First Page"
|
||||
data-l10n-id="first_page"></menuitem>
|
||||
<menuitem id="contextLastPage" label="Last Page"
|
||||
data-l10n-id="last_page"></menuitem>
|
||||
<menuitem id="contextPageRotateCw" label="Rotate Clockwise"
|
||||
data-l10n-id="page_rotate_cw"></menuitem>
|
||||
<menuitem id="contextPageRotateCcw" label="Rotate Counter-Clockwise"
|
||||
data-l10n-id="page_rotate_ccw"></menuitem>
|
||||
</menu>
|
||||
|
||||
<div id="viewerContainer" tabindex="0">
|
||||
<div id="viewer" class="pdfViewer"></div>
|
||||
</div>
|
||||
|
||||
<div id="errorWrapper" hidden='true'>
|
||||
<div id="errorMessageLeft">
|
||||
<span id="errorMessage"></span>
|
||||
<button id="errorShowMore" data-l10n-id="error_more_info">
|
||||
More Information
|
||||
</button>
|
||||
<button id="errorShowLess" data-l10n-id="error_less_info" hidden='true'>
|
||||
Less Information
|
||||
</button>
|
||||
</div>
|
||||
<div id="errorMessageRight">
|
||||
<button id="errorClose" data-l10n-id="error_close">
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
<div class="clearBoth"></div>
|
||||
<textarea id="errorMoreInfo" hidden='true' readonly="readonly"></textarea>
|
||||
</div>
|
||||
</div> <!-- mainContainer -->
|
||||
|
||||
<div id="overlayContainer" class="hidden">
|
||||
<div id="passwordOverlay" class="container hidden">
|
||||
<div class="dialog">
|
||||
<div class="row">
|
||||
<p id="passwordText" data-l10n-id="password_label">Enter the password to open this PDF file:</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<input type="password" id="password" class="toolbarField">
|
||||
</div>
|
||||
<div class="buttonRow">
|
||||
<button id="passwordCancel" class="overlayButton"><span data-l10n-id="password_cancel">Cancel</span></button>
|
||||
<button id="passwordSubmit" class="overlayButton"><span data-l10n-id="password_ok">OK</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="documentPropertiesOverlay" class="container hidden">
|
||||
<div class="dialog">
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_file_name">File name:</span> <p id="fileNameField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_file_size">File size:</span> <p id="fileSizeField">-</p>
|
||||
</div>
|
||||
<div class="separator"></div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_title">Title:</span> <p id="titleField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_author">Author:</span> <p id="authorField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_subject">Subject:</span> <p id="subjectField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_keywords">Keywords:</span> <p id="keywordsField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_creation_date">Creation Date:</span> <p id="creationDateField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_modification_date">Modification Date:</span> <p id="modificationDateField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_creator">Creator:</span> <p id="creatorField">-</p>
|
||||
</div>
|
||||
<div class="separator"></div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_producer">PDF Producer:</span> <p id="producerField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_version">PDF Version:</span> <p id="versionField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_page_count">Page Count:</span> <p id="pageCountField">-</p>
|
||||
</div>
|
||||
<div class="buttonRow">
|
||||
<button id="documentPropertiesClose" class="overlayButton"><span data-l10n-id="document_properties_close">Close</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="printServiceOverlay" class="container hidden">
|
||||
<div class="dialog">
|
||||
<div class="row">
|
||||
<span data-l10n-id="print_progress_message">Preparing document for printing…</span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<progress value="0" max="100"></progress>
|
||||
<span data-l10n-id="print_progress_percent" data-l10n-args='{ "progress": 0 }' class="relative-progress">0%</span>
|
||||
</div>
|
||||
<div class="buttonRow">
|
||||
<button id="printCancel" class="overlayButton"><span data-l10n-id="print_progress_close">Cancel</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- overlayContainer -->
|
||||
|
||||
</div> <!-- outerContainer -->
|
||||
<div id="rightClickBox" class="right-click-box">
|
||||
<p id="copy">开启复制</p>
|
||||
</div>
|
||||
<div class="button-box">
|
||||
<!--<span>翻译</span>-->
|
||||
<span id="copyBtn">复制</span>
|
||||
</div>
|
||||
<textarea type="hidden" class="hidden-textarea"></textarea>
|
||||
<div id="printContainer"></div>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
var print = document.getElementById('print')
|
||||
var printId = print.getAttribute('data-print')
|
||||
var printParentNode = print.parentNode
|
||||
var menuList = JSON.parse(localStorage.getItem('menuList'))
|
||||
var visible = false
|
||||
menuList.map(function (menu) {
|
||||
if (menu.id === printId) {
|
||||
visible = true
|
||||
return
|
||||
}
|
||||
})
|
||||
if (!visible) {
|
||||
printParentNode.removeChild(print)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,562 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
/* Copyright 2012 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals VBArray, PDFJS */
|
||||
|
||||
'use strict'
|
||||
|
||||
// Initializing PDFJS global object here, it case if we need to change/disable
|
||||
// some PDF.js features, e.g. range requests
|
||||
if (typeof PDFJS === 'undefined') {
|
||||
(typeof window !== 'undefined' ? window : this).PDFJS = {}
|
||||
}
|
||||
|
||||
// Checking if the typed arrays are supported
|
||||
// Support: iOS<6.0 (subarray), IE<10, Android<4.0
|
||||
(function checkTypedArrayCompatibility () {
|
||||
if (typeof Uint8Array !== 'undefined') {
|
||||
// Support: iOS<6.0
|
||||
if (typeof Uint8Array.prototype.subarray === 'undefined') {
|
||||
Uint8Array.prototype.subarray = function subarray (start, end) {
|
||||
return new Uint8Array(this.slice(start, end))
|
||||
}
|
||||
Float32Array.prototype.subarray = function subarray (start, end) {
|
||||
return new Float32Array(this.slice(start, end))
|
||||
}
|
||||
}
|
||||
|
||||
// Support: Android<4.1
|
||||
if (typeof Float64Array === 'undefined') {
|
||||
window.Float64Array = Float32Array
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
function subarray (start, end) {
|
||||
return new TypedArray(this.slice(start, end))
|
||||
}
|
||||
|
||||
function setArrayOffset (array, offset) {
|
||||
if (arguments.length < 2) {
|
||||
offset = 0
|
||||
}
|
||||
for (var i = 0, n = array.length; i < n; ++i, ++offset) {
|
||||
this[offset] = array[i] & 0xFF
|
||||
}
|
||||
}
|
||||
|
||||
function TypedArray (arg1) {
|
||||
var result, i, n
|
||||
if (typeof arg1 === 'number') {
|
||||
result = []
|
||||
for (i = 0; i < arg1; ++i) {
|
||||
result[i] = 0
|
||||
}
|
||||
} else if ('slice' in arg1) {
|
||||
result = arg1.slice(0)
|
||||
} else {
|
||||
result = []
|
||||
for (i = 0, n = arg1.length; i < n; ++i) {
|
||||
result[i] = arg1[i]
|
||||
}
|
||||
}
|
||||
|
||||
result.subarray = subarray
|
||||
result.buffer = result
|
||||
result.byteLength = result.length
|
||||
result.set = setArrayOffset
|
||||
|
||||
if (typeof arg1 === 'object' && arg1.buffer) {
|
||||
result.buffer = arg1.buffer
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
window.Uint8Array = TypedArray
|
||||
window.Int8Array = TypedArray
|
||||
|
||||
// we don't need support for set, byteLength for 32-bit array
|
||||
// so we can use the TypedArray as well
|
||||
window.Uint32Array = TypedArray
|
||||
window.Int32Array = TypedArray
|
||||
window.Uint16Array = TypedArray
|
||||
window.Float32Array = TypedArray
|
||||
window.Float64Array = TypedArray
|
||||
})();
|
||||
|
||||
// URL = URL || webkitURL
|
||||
// Support: Safari<7, Android 4.2+
|
||||
(function normalizeURLObject () {
|
||||
if (!window.URL) {
|
||||
window.URL = window.webkitURL
|
||||
}
|
||||
})();
|
||||
|
||||
// Object.defineProperty()?
|
||||
// Support: Android<4.0, Safari<5.1
|
||||
(function checkObjectDefinePropertyCompatibility () {
|
||||
if (typeof Object.defineProperty !== 'undefined') {
|
||||
var definePropertyPossible = true
|
||||
try {
|
||||
// some browsers (e.g. safari) cannot use defineProperty() on DOM objects
|
||||
// and thus the native version is not sufficient
|
||||
Object.defineProperty(new Image(), 'id', { value: 'test' })
|
||||
// ... another test for android gb browser for non-DOM objects
|
||||
var Test = function Test () {}
|
||||
Test.prototype = { get id () { } }
|
||||
Object.defineProperty(new Test(), 'id',
|
||||
{ value: '', configurable: true, enumerable: true, writable: false })
|
||||
} catch (e) {
|
||||
definePropertyPossible = false
|
||||
}
|
||||
if (definePropertyPossible) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty = function objectDefineProperty (obj, name, def) {
|
||||
delete obj[name]
|
||||
if ('get' in def) {
|
||||
obj.__defineGetter__(name, def['get'])
|
||||
}
|
||||
if ('set' in def) {
|
||||
obj.__defineSetter__(name, def['set'])
|
||||
}
|
||||
if ('value' in def) {
|
||||
obj.__defineSetter__(name, function objectDefinePropertySetter (value) {
|
||||
this.__defineGetter__(name, function objectDefinePropertyGetter () {
|
||||
return value
|
||||
})
|
||||
return value
|
||||
})
|
||||
obj[name] = def.value
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
// No XMLHttpRequest#response?
|
||||
// Support: IE<11, Android <4.0
|
||||
(function checkXMLHttpRequestResponseCompatibility () {
|
||||
var xhrPrototype = XMLHttpRequest.prototype
|
||||
var xhr = new XMLHttpRequest()
|
||||
if (!('overrideMimeType' in xhr)) {
|
||||
// IE10 might have response, but not overrideMimeType
|
||||
// Support: IE10
|
||||
Object.defineProperty(xhrPrototype, 'overrideMimeType', {
|
||||
value: function xmlHttpRequestOverrideMimeType (mimeType) {}
|
||||
})
|
||||
}
|
||||
if ('responseType' in xhr) {
|
||||
return
|
||||
}
|
||||
|
||||
// The worker will be using XHR, so we can save time and disable worker.
|
||||
PDFJS.disableWorker = true
|
||||
|
||||
// Support: IE9
|
||||
if (typeof VBArray !== 'undefined') {
|
||||
Object.defineProperty(xhrPrototype, 'response', {
|
||||
get: function xmlHttpRequestResponseGet () {
|
||||
if (this.responseType === 'arraybuffer') {
|
||||
return new Uint8Array(new VBArray(this.responseBody).toArray())
|
||||
} else {
|
||||
return this.responseText
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// other browsers
|
||||
function responseTypeSetter () {
|
||||
// will be only called to set "arraybuffer"
|
||||
this.overrideMimeType('text/plain; charset=x-user-defined')
|
||||
}
|
||||
if (typeof xhr.overrideMimeType === 'function') {
|
||||
Object.defineProperty(xhrPrototype, 'responseType',
|
||||
{ set: responseTypeSetter })
|
||||
}
|
||||
function responseGetter () {
|
||||
var text = this.responseText
|
||||
var i, n = text.length
|
||||
var result = new Uint8Array(n)
|
||||
for (i = 0; i < n; ++i) {
|
||||
result[i] = text.charCodeAt(i) & 0xFF
|
||||
}
|
||||
return result.buffer
|
||||
}
|
||||
Object.defineProperty(xhrPrototype, 'response', { get: responseGetter })
|
||||
})();
|
||||
|
||||
// window.btoa (base64 encode function) ?
|
||||
// Support: IE<10
|
||||
(function checkWindowBtoaCompatibility () {
|
||||
if ('btoa' in window) {
|
||||
return
|
||||
}
|
||||
|
||||
var digits =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
||||
|
||||
window.btoa = function windowBtoa (chars) {
|
||||
var buffer = ''
|
||||
var i, n
|
||||
for (i = 0, n = chars.length; i < n; i += 3) {
|
||||
var b1 = chars.charCodeAt(i) & 0xFF
|
||||
var b2 = chars.charCodeAt(i + 1) & 0xFF
|
||||
var b3 = chars.charCodeAt(i + 2) & 0xFF
|
||||
var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4)
|
||||
var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64
|
||||
var d4 = i + 2 < n ? (b3 & 0x3F) : 64
|
||||
buffer += (digits.charAt(d1) + digits.charAt(d2) +
|
||||
digits.charAt(d3) + digits.charAt(d4))
|
||||
}
|
||||
return buffer
|
||||
}
|
||||
})();
|
||||
|
||||
// window.atob (base64 encode function)?
|
||||
// Support: IE<10
|
||||
(function checkWindowAtobCompatibility () {
|
||||
if ('atob' in window) {
|
||||
return
|
||||
}
|
||||
|
||||
// https://github.com/davidchambers/Base64.js
|
||||
var digits =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
||||
window.atob = function (input) {
|
||||
input = input.replace(/=+$/, '')
|
||||
if (input.length % 4 === 1) {
|
||||
throw new Error('bad atob input')
|
||||
}
|
||||
for (
|
||||
// initialize result and counters
|
||||
var bc = 0, bs, buffer, idx = 0, output = '';
|
||||
// get next character
|
||||
buffer = input.charAt(idx++);
|
||||
// character found in table?
|
||||
// initialize bit storage and add its ascii value
|
||||
~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
|
||||
// and if not first of each 4 characters,
|
||||
// convert the first 8 bits to one ascii character
|
||||
bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
|
||||
) {
|
||||
// try to find character in table (0-63, not found => -1)
|
||||
buffer = digits.indexOf(buffer)
|
||||
}
|
||||
return output
|
||||
}
|
||||
})();
|
||||
|
||||
// Function.prototype.bind?
|
||||
// Support: Android<4.0, iOS<6.0
|
||||
(function checkFunctionPrototypeBindCompatibility () {
|
||||
if (typeof Function.prototype.bind !== 'undefined') {
|
||||
return
|
||||
}
|
||||
|
||||
Function.prototype.bind = function functionPrototypeBind (obj) {
|
||||
var fn = this, headArgs = Array.prototype.slice.call(arguments, 1)
|
||||
var bound = function functionPrototypeBindBound () {
|
||||
var args = headArgs.concat(Array.prototype.slice.call(arguments))
|
||||
return fn.apply(obj, args)
|
||||
}
|
||||
return bound
|
||||
}
|
||||
})();
|
||||
|
||||
// HTMLElement dataset property
|
||||
// Support: IE<11, Safari<5.1, Android<4.0
|
||||
(function checkDatasetProperty () {
|
||||
var div = document.createElement('div')
|
||||
if ('dataset' in div) {
|
||||
return // dataset property exists
|
||||
}
|
||||
|
||||
Object.defineProperty(HTMLElement.prototype, 'dataset', {
|
||||
get: function () {
|
||||
if (this._dataset) {
|
||||
return this._dataset
|
||||
}
|
||||
|
||||
var dataset = {}
|
||||
for (var j = 0, jj = this.attributes.length; j < jj; j++) {
|
||||
var attribute = this.attributes[j]
|
||||
if (attribute.name.substring(0, 5) !== 'data-') {
|
||||
continue
|
||||
}
|
||||
var key = attribute.name.substring(5).replace(/\-([a-z])/g,
|
||||
function (all, ch) {
|
||||
return ch.toUpperCase()
|
||||
})
|
||||
dataset[key] = attribute.value
|
||||
}
|
||||
|
||||
Object.defineProperty(this, '_dataset', {
|
||||
value: dataset,
|
||||
writable: false,
|
||||
enumerable: false
|
||||
})
|
||||
return dataset
|
||||
},
|
||||
enumerable: true
|
||||
})
|
||||
})();
|
||||
|
||||
// HTMLElement classList property
|
||||
// Support: IE<10, Android<4.0, iOS<5.0
|
||||
(function checkClassListProperty () {
|
||||
var div = document.createElement('div')
|
||||
if ('classList' in div) {
|
||||
return // classList property exists
|
||||
}
|
||||
|
||||
function changeList (element, itemName, add, remove) {
|
||||
var s = element.className || ''
|
||||
var list = s.split(/\s+/g)
|
||||
if (list[0] === '') {
|
||||
list.shift()
|
||||
}
|
||||
var index = list.indexOf(itemName)
|
||||
if (index < 0 && add) {
|
||||
list.push(itemName)
|
||||
}
|
||||
if (index >= 0 && remove) {
|
||||
list.splice(index, 1)
|
||||
}
|
||||
element.className = list.join(' ')
|
||||
return (index >= 0)
|
||||
}
|
||||
|
||||
var classListPrototype = {
|
||||
add: function (name) {
|
||||
changeList(this.element, name, true, false)
|
||||
},
|
||||
contains: function (name) {
|
||||
return changeList(this.element, name, false, false)
|
||||
},
|
||||
remove: function (name) {
|
||||
changeList(this.element, name, false, true)
|
||||
},
|
||||
toggle: function (name) {
|
||||
changeList(this.element, name, true, true)
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(HTMLElement.prototype, 'classList', {
|
||||
get: function () {
|
||||
if (this._classList) {
|
||||
return this._classList
|
||||
}
|
||||
|
||||
var classList = Object.create(classListPrototype, {
|
||||
element: {
|
||||
value: this,
|
||||
writable: false,
|
||||
enumerable: true
|
||||
}
|
||||
})
|
||||
Object.defineProperty(this, '_classList', {
|
||||
value: classList,
|
||||
writable: false,
|
||||
enumerable: false
|
||||
})
|
||||
return classList
|
||||
},
|
||||
enumerable: true
|
||||
})
|
||||
})();
|
||||
|
||||
// Check console compatibility
|
||||
// In older IE versions the console object is not available
|
||||
// unless console is open.
|
||||
// Support: IE<10
|
||||
(function checkConsoleCompatibility () {
|
||||
if (!('console' in window)) {
|
||||
window.console = {
|
||||
log: function () {},
|
||||
error: function () {},
|
||||
warn: function () {}
|
||||
}
|
||||
} else if (!('bind' in console.log)) {
|
||||
// native functions in IE9 might not have bind
|
||||
console.log = (function (fn) {
|
||||
return function (msg) { return fn(msg) }
|
||||
})(console.log)
|
||||
console.error = (function (fn) {
|
||||
return function (msg) { return fn(msg) }
|
||||
})(console.error)
|
||||
console.warn = (function (fn) {
|
||||
return function (msg) { return fn(msg) }
|
||||
})(console.warn)
|
||||
}
|
||||
})();
|
||||
|
||||
// Check onclick compatibility in Opera
|
||||
// Support: Opera<15
|
||||
(function checkOnClickCompatibility () {
|
||||
// workaround for reported Opera bug DSK-354448:
|
||||
// onclick fires on disabled buttons with opaque content
|
||||
function ignoreIfTargetDisabled (event) {
|
||||
if (isDisabled(event.target)) {
|
||||
event.stopPropagation()
|
||||
}
|
||||
}
|
||||
function isDisabled (node) {
|
||||
return node.disabled || (node.parentNode && isDisabled(node.parentNode))
|
||||
}
|
||||
if (navigator.userAgent.indexOf('Opera') !== -1) {
|
||||
// use browser detection since we cannot feature-check this bug
|
||||
document.addEventListener('click', ignoreIfTargetDisabled, true)
|
||||
}
|
||||
})();
|
||||
|
||||
// Checks if possible to use URL.createObjectURL()
|
||||
// Support: IE
|
||||
(function checkOnBlobSupport () {
|
||||
// sometimes IE loosing the data created with createObjectURL(), see #3977
|
||||
if (navigator.userAgent.indexOf('Trident') >= 0) {
|
||||
PDFJS.disableCreateObjectURL = true
|
||||
}
|
||||
})();
|
||||
|
||||
// Checks if navigator.language is supported
|
||||
(function checkNavigatorLanguage () {
|
||||
if ('language' in navigator &&
|
||||
/^[a-z]+(-[A-Z]+)?$/.test(navigator.language)) {
|
||||
return
|
||||
}
|
||||
function formatLocale (locale) {
|
||||
var split = locale.split(/[-_]/)
|
||||
split[0] = split[0].toLowerCase()
|
||||
if (split.length > 1) {
|
||||
split[1] = split[1].toUpperCase()
|
||||
}
|
||||
return split.join('-')
|
||||
}
|
||||
var language = navigator.language || navigator.userLanguage || 'en-US'
|
||||
PDFJS.locale = formatLocale(language)
|
||||
})();
|
||||
|
||||
(function checkRangeRequests () {
|
||||
// Safari has issues with cached range requests see:
|
||||
// https://github.com/mozilla/pdf.js/issues/3260
|
||||
// Last tested with version 6.0.4.
|
||||
// Support: Safari 6.0+
|
||||
var isSafari = Object.prototype.toString.call(
|
||||
window.HTMLElement).indexOf('Constructor') > 0
|
||||
|
||||
// Older versions of Android (pre 3.0) has issues with range requests, see:
|
||||
// https://github.com/mozilla/pdf.js/issues/3381.
|
||||
// Make sure that we only match webkit-based Android browsers,
|
||||
// since Firefox/Fennec works as expected.
|
||||
// Support: Android<3.0
|
||||
var regex = /Android\s[0-2][^\d]/
|
||||
var isOldAndroid = regex.test(navigator.userAgent)
|
||||
|
||||
if (isSafari || isOldAndroid) {
|
||||
PDFJS.disableRange = true
|
||||
}
|
||||
})();
|
||||
|
||||
// Check if the browser supports manipulation of the history.
|
||||
// Support: IE<10, Android<4.2
|
||||
(function checkHistoryManipulation () {
|
||||
// Android 2.x has so buggy pushState support that it was removed in
|
||||
// Android 3.0 and restored as late as in Android 4.2.
|
||||
// Support: Android 2.x
|
||||
if (!history.pushState || navigator.userAgent.indexOf('Android 2.') >= 0) {
|
||||
PDFJS.disableHistory = true
|
||||
}
|
||||
})();
|
||||
|
||||
// Support: IE<11, Chrome<21, Android<4.4, Safari<6
|
||||
(function checkSetPresenceInImageData () {
|
||||
// IE < 11 will use window.CanvasPixelArray which lacks set function.
|
||||
if (window.CanvasPixelArray) {
|
||||
if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
|
||||
window.CanvasPixelArray.prototype.set = function (arr) {
|
||||
for (var i = 0, ii = this.length; i < ii; i++) {
|
||||
this[i] = arr[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Old Chrome and Android use an inaccessible CanvasPixelArray prototype.
|
||||
// Because we cannot feature detect it, we rely on user agent parsing.
|
||||
var polyfill = false, versionMatch
|
||||
if (navigator.userAgent.indexOf('Chrom') >= 0) {
|
||||
versionMatch = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)
|
||||
// Chrome < 21 lacks the set function.
|
||||
polyfill = versionMatch && parseInt(versionMatch[2]) < 21
|
||||
} else if (navigator.userAgent.indexOf('Android') >= 0) {
|
||||
// Android < 4.4 lacks the set function.
|
||||
// Android >= 4.4 will contain Chrome in the user agent,
|
||||
// thus pass the Chrome check above and not reach this block.
|
||||
polyfill = /Android\s[0-4][^\d]/g.test(navigator.userAgent)
|
||||
} else if (navigator.userAgent.indexOf('Safari') >= 0) {
|
||||
versionMatch = navigator.userAgent
|
||||
.match(/Version\/([0-9]+)\.([0-9]+)\.([0-9]+) Safari\//)
|
||||
// Safari < 6 lacks the set function.
|
||||
polyfill = versionMatch && parseInt(versionMatch[1]) < 6
|
||||
}
|
||||
|
||||
if (polyfill) {
|
||||
var contextPrototype = window.CanvasRenderingContext2D.prototype
|
||||
contextPrototype._createImageData = contextPrototype.createImageData
|
||||
contextPrototype.createImageData = function (w, h) {
|
||||
var imageData = this._createImageData(w, h)
|
||||
imageData.data.set = function (arr) {
|
||||
for (var i = 0, ii = this.length; i < ii; i++) {
|
||||
this[i] = arr[i]
|
||||
}
|
||||
}
|
||||
return imageData
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
// Support: IE<10, Android<4.0, iOS
|
||||
(function checkRequestAnimationFrame () {
|
||||
function fakeRequestAnimationFrame (callback) {
|
||||
window.setTimeout(callback, 20)
|
||||
}
|
||||
|
||||
var isIOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent)
|
||||
if (isIOS) {
|
||||
// requestAnimationFrame on iOS is broken, replacing with fake one.
|
||||
window.requestAnimationFrame = fakeRequestAnimationFrame
|
||||
return
|
||||
}
|
||||
if ('requestAnimationFrame' in window) {
|
||||
return
|
||||
}
|
||||
window.requestAnimationFrame =
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
fakeRequestAnimationFrame
|
||||
})();
|
||||
|
||||
(function checkCanvasSizeLimitation () {
|
||||
var isIOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent)
|
||||
var isAndroid = /Android/g.test(navigator.userAgent)
|
||||
if (isIOS || isAndroid) {
|
||||
// 5MP
|
||||
PDFJS.maxCanvasPixels = 5242880
|
||||
}
|
||||
})()
|
||||
|
After Width: | Height: | Size: 199 B |
|
After Width: | Height: | Size: 304 B |
|
After Width: | Height: | Size: 193 B |
|
After Width: | Height: | Size: 296 B |
|
After Width: | Height: | Size: 193 B |
|
After Width: | Height: | Size: 296 B |
|
After Width: | Height: | Size: 199 B |
|
After Width: | Height: | Size: 304 B |
|
After Width: | Height: | Size: 7.2 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 403 B |
|
After Width: | Height: | Size: 933 B |
|
After Width: | Height: | Size: 179 B |
|
After Width: | Height: | Size: 266 B |
|
After Width: | Height: | Size: 301 B |
|
After Width: | Height: | Size: 583 B |
|
After Width: | Height: | Size: 175 B |
|
After Width: | Height: | Size: 276 B |
|
After Width: | Height: | Size: 360 B |
|
After Width: | Height: | Size: 731 B |
|
After Width: | Height: | Size: 359 B |
|
After Width: | Height: | Size: 714 B |
|
After Width: | Height: | Size: 461 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 290 B |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 174 B |
|
After Width: | Height: | Size: 260 B |
|
After Width: | Height: | Size: 259 B |
|
After Width: | Height: | Size: 425 B |
|
After Width: | Height: | Size: 107 B |
|
After Width: | Height: | Size: 152 B |
|
After Width: | Height: | Size: 295 B |
|
After Width: | Height: | Size: 550 B |
|
After Width: | Height: | Size: 242 B |
|
After Width: | Height: | Size: 398 B |
|
After Width: | Height: | Size: 238 B |
|
After Width: | Height: | Size: 396 B |
|
After Width: | Height: | Size: 245 B |
|
After Width: | Height: | Size: 405 B |
|
After Width: | Height: | Size: 246 B |
|
After Width: | Height: | Size: 403 B |
|
After Width: | Height: | Size: 321 B |
|
After Width: | Height: | Size: 586 B |
|
After Width: | Height: | Size: 257 B |
|
After Width: | Height: | Size: 464 B |
|
After Width: | Height: | Size: 309 B |
|
After Width: | Height: | Size: 653 B |
|
After Width: | Height: | Size: 246 B |
|
After Width: | Height: | Size: 456 B |
|
After Width: | Height: | Size: 243 B |
|
After Width: | Height: | Size: 458 B |
|
After Width: | Height: | Size: 225 B |
|
After Width: | Height: | Size: 344 B |
|
After Width: | Height: | Size: 225 B |
|
After Width: | Height: | Size: 331 B |
|
After Width: | Height: | Size: 384 B |
|
After Width: | Height: | Size: 859 B |
|
After Width: | Height: | Size: 177 B |
|
After Width: | Height: | Size: 394 B |
|
After Width: | Height: | Size: 178 B |
|
After Width: | Height: | Size: 331 B |
|
After Width: | Height: | Size: 185 B |
|
After Width: | Height: | Size: 219 B |
|
After Width: | Height: | Size: 136 B |
|
After Width: | Height: | Size: 160 B |
|
After Width: | Height: | Size: 88 B |
|
After Width: | Height: | Size: 109 B |
|
After Width: | Height: | Size: 143 B |
|
After Width: | Height: | Size: 167 B |
|
After Width: | Height: | Size: 128 B |
|
After Width: | Height: | Size: 149 B |
|
After Width: | Height: | Size: 125 B |
|
After Width: | Height: | Size: 172 B |
@@ -0,0 +1,8 @@
|
||||
/*!
|
||||
* jQuery Cookie Plugin v1.3.1
|
||||
* https://github.com/carhartl/jquery-cookie
|
||||
*
|
||||
* Copyright 2013 Klaus Hartl
|
||||
* Released under the MIT license
|
||||
*/
|
||||
(function(a){if(typeof define==="function"&&define.amd){define(["jquery"],a)}else{a(jQuery)}}(function(e){var a=/\+/g;function d(g){return g}function b(g){return decodeURIComponent(g.replace(a," "))}function f(g){if(g.indexOf('"')===0){g=g.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")}try{return c.json?JSON.parse(g):g}catch(h){}}var c=e.cookie=function(p,o,u){if(o!==undefined){u=e.extend({},c.defaults,u);if(typeof u.expires==="number"){var q=u.expires,s=u.expires=new Date();s.setDate(s.getDate()+q)}o=c.json?JSON.stringify(o):String(o);return(document.cookie=[c.raw?p:encodeURIComponent(p),"=",c.raw?o:encodeURIComponent(o),u.expires?"; expires="+u.expires.toUTCString():"",u.path?"; path="+u.path:"",u.domain?"; domain="+u.domain:"",u.secure?"; secure":""].join(""))}var g=c.raw?d:b;var r=document.cookie.split("; ");var v=p?undefined:{};for(var n=0,k=r.length;n<k;n++){var m=r[n].split("=");var h=g(m.shift());var j=g(m.join("="));if(p&&p===h){v=f(j);break}if(!p){v[h]=f(j)}}return v};c.defaults={};e.removeCookie=function(h,g){if(e.cookie(h)!==undefined){e.cookie(h,"",e.extend({},g,{expires:-1}));return true}return false}}));
|
||||
@@ -0,0 +1,506 @@
|
||||
/******************************************************************************
|
||||
* jquery.i18n.properties
|
||||
*
|
||||
* Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and
|
||||
* MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses.
|
||||
*
|
||||
* @version 1.2.7
|
||||
* @url https://github.com/jquery-i18n-properties/jquery-i18n-properties
|
||||
* @inspiration Localisation assistance for jQuery (http://keith-wood.name/localisation.html)
|
||||
* by Keith Wood (kbwood{at}iinet.com.au) June 2007
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
(function ($) {
|
||||
|
||||
$.i18n = {};
|
||||
|
||||
/**
|
||||
* Map holding bundle keys if mode is 'map' or 'both'. Values of this can also be an
|
||||
* Object, in which case the key is a namespace.
|
||||
*/
|
||||
$.i18n.map = {};
|
||||
|
||||
var debug = function (message) {
|
||||
window.console && console.log('i18n::' + message);
|
||||
};
|
||||
|
||||
/**
|
||||
* Load and parse message bundle files (.properties),
|
||||
* making bundles keys available as javascript variables.
|
||||
*
|
||||
* i18n files are named <name>.js, or <name>_<language>.js or <name>_<language>_<country>.js
|
||||
* Where:
|
||||
* The <language> argument is a valid ISO Language Code. These codes are the lower-case,
|
||||
* two-letter codes as defined by ISO-639. You can find a full list of these codes at a
|
||||
* number of sites, such as: http://www.loc.gov/standards/iso639-2/englangn.html
|
||||
* The <country> argument is a valid ISO Country Code. These codes are the upper-case,
|
||||
* two-letter codes as defined by ISO-3166. You can find a full list of these codes at a
|
||||
* number of sites, such as: http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
|
||||
*
|
||||
* Sample usage for a bundles/Messages.properties bundle:
|
||||
* $.i18n.properties({
|
||||
* name: 'Messages',
|
||||
* language: 'en_US',
|
||||
* path: 'bundles'
|
||||
* });
|
||||
* @param name (string/string[], optional) names of file to load (eg, 'Messages' or ['Msg1','Msg2']). Defaults to "Messages"
|
||||
* @param language (string, optional) language/country code (eg, 'en', 'en_US', 'pt_BR'). if not specified, language reported by the browser will be used instead.
|
||||
* @param path (string, optional) path of directory that contains file to load
|
||||
* @param mode (string, optional) whether bundles keys are available as JavaScript variables/functions or as a map (eg, 'vars' or 'map')
|
||||
* @param debug (boolean, optional) whether debug statements are logged at the console
|
||||
* @param cache (boolean, optional) whether bundles should be cached by the browser, or forcibly reloaded on each page load. Defaults to false (i.e. forcibly reloaded)
|
||||
* @param encoding (string, optional) the encoding to request for bundles. Property file resource bundles are specified to be in ISO-8859-1 format. Defaults to UTF-8 for backward compatibility.
|
||||
* @param callback (function, optional) callback function to be called after script is terminated
|
||||
*/
|
||||
$.i18n.properties = function (settings) {
|
||||
|
||||
var defaults = {
|
||||
name: 'Messages',
|
||||
language: '',
|
||||
path: '',
|
||||
namespace: null,
|
||||
mode: 'vars',
|
||||
cache: false,
|
||||
debug: false,
|
||||
encoding: 'UTF-8',
|
||||
async: false,
|
||||
callback: null
|
||||
};
|
||||
|
||||
settings = $.extend(defaults, settings);
|
||||
|
||||
if (settings.namespace && typeof settings.namespace == 'string') {
|
||||
// A namespace has been supplied, initialise it.
|
||||
if (settings.namespace.match(/^[a-z]*$/)) {
|
||||
$.i18n.map[settings.namespace] = {};
|
||||
} else {
|
||||
debug('Namespaces can only be lower case letters, a - z');
|
||||
settings.namespace = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure a trailing slash on the path
|
||||
if (!settings.path.match(/\/$/)) settings.path += '/';
|
||||
|
||||
// Try to ensure that we have at a least a two letter language code
|
||||
settings.language = this.normaliseLanguageCode(settings);
|
||||
|
||||
// Ensure an array
|
||||
var files = (settings.name && settings.name.constructor === Array) ? settings.name : [settings.name];
|
||||
|
||||
// A locale is at least a language code which means at least two files per name. If
|
||||
// we also have a country code, thats an extra file per name.
|
||||
settings.totalFiles = (files.length * 2) + ((settings.language.length >= 5) ? files.length : 0);
|
||||
if (settings.debug) {
|
||||
debug('totalFiles: ' + settings.totalFiles);
|
||||
}
|
||||
|
||||
settings.filesLoaded = 0;
|
||||
|
||||
files.forEach(function (file) {
|
||||
|
||||
var defaultFileName, shortFileName, longFileName, fileNames;
|
||||
// 1. load base (eg, Messages.properties)
|
||||
defaultFileName = settings.path + file + '.properties';
|
||||
// 2. with language code (eg, Messages_pt.properties)
|
||||
var shortCode = settings.language.substring(0, 2);
|
||||
shortFileName = settings.path + file + '_' + shortCode + '.properties';
|
||||
// 3. with language code and country code (eg, Messages_pt_BR.properties)
|
||||
if (settings.language.length >= 5) {
|
||||
var longCode = settings.language.substring(0, 5);
|
||||
longFileName = settings.path + file + '_' + longCode + '.properties';
|
||||
fileNames = [defaultFileName, shortFileName, longFileName];
|
||||
} else {
|
||||
fileNames = [defaultFileName, shortFileName];
|
||||
}
|
||||
loadAndParseFiles(fileNames, settings);
|
||||
});
|
||||
|
||||
// call callback
|
||||
if (settings.callback && !settings.async) {
|
||||
settings.callback();
|
||||
}
|
||||
}; // properties
|
||||
|
||||
/**
|
||||
* When configured with mode: 'map', allows access to bundle values by specifying its key.
|
||||
* Eg, jQuery.i18n.prop('com.company.bundles.menu_add')
|
||||
*/
|
||||
$.i18n.prop = function (key /* Add parameters as function arguments as necessary */) {
|
||||
|
||||
var args = [].slice.call(arguments);
|
||||
|
||||
var phvList, namespace;
|
||||
if (args.length == 2) {
|
||||
if ($.isArray(args[1])) {
|
||||
// An array was passed as the second parameter, so assume it is the list of place holder values.
|
||||
phvList = args[1];
|
||||
} else if (typeof args[1] === 'object') {
|
||||
// Second argument is an options object {namespace: 'mynamespace', replacements: ['egg', 'nog']}
|
||||
namespace = args[1].namespace;
|
||||
var replacements = args[1].replacements;
|
||||
args.splice(-1, 1);
|
||||
if (replacements) {
|
||||
Array.prototype.push.apply(args, replacements);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var value = (namespace) ? $.i18n.map[namespace][key] : $.i18n.map[key];
|
||||
if (value === null) {
|
||||
return '[' + ((namespace) ? namespace + '#' + key : key) + ']';
|
||||
}
|
||||
|
||||
// Place holder replacement
|
||||
/**
|
||||
* Tested with:
|
||||
* test.t1=asdf ''{0}''
|
||||
* test.t2=asdf '{0}' '{1}'{1}'zxcv
|
||||
* test.t3=This is \"a quote" 'a''{0}''s'd{fgh{ij'
|
||||
* test.t4="'''{'0}''" {0}{a}
|
||||
* test.t5="'''{0}'''" {1}
|
||||
* test.t6=a {1} b {0} c
|
||||
* test.t7=a 'quoted \\ s\ttringy' \t\t x
|
||||
*
|
||||
* Produces:
|
||||
* test.t1, p1 ==> asdf 'p1'
|
||||
* test.t2, p1 ==> asdf {0} {1}{1}zxcv
|
||||
* test.t3, p1 ==> This is "a quote" a'{0}'sd{fgh{ij
|
||||
* test.t4, p1 ==> "'{0}'" p1{a}
|
||||
* test.t5, p1 ==> "'{0}'" {1}
|
||||
* test.t6, p1 ==> a {1} b p1 c
|
||||
* test.t6, p1, p2 ==> a p2 b p1 c
|
||||
* test.t6, p1, p2, p3 ==> a p2 b p1 c
|
||||
* test.t7 ==> a quoted \ s tringy x
|
||||
*/
|
||||
|
||||
var i;
|
||||
if (typeof(value) == 'string') {
|
||||
// Handle escape characters. Done separately from the tokenizing loop below because escape characters are
|
||||
// active in quoted strings.
|
||||
i = 0;
|
||||
while ((i = value.indexOf('\\', i)) != -1) {
|
||||
if (value.charAt(i + 1) == 't') {
|
||||
value = value.substring(0, i) + '\t' + value.substring((i++) + 2); // tab
|
||||
} else if (value.charAt(i + 1) == 'r') {
|
||||
value = value.substring(0, i) + '\r' + value.substring((i++) + 2); // return
|
||||
} else if (value.charAt(i + 1) == 'n') {
|
||||
value = value.substring(0, i) + '\n' + value.substring((i++) + 2); // line feed
|
||||
} else if (value.charAt(i + 1) == 'f') {
|
||||
value = value.substring(0, i) + '\f' + value.substring((i++) + 2); // form feed
|
||||
} else if (value.charAt(i + 1) == '\\') {
|
||||
value = value.substring(0, i) + '\\' + value.substring((i++) + 2); // \
|
||||
} else {
|
||||
value = value.substring(0, i) + value.substring(i + 1); // Quietly drop the character
|
||||
}
|
||||
}
|
||||
|
||||
// Lazily convert the string to a list of tokens.
|
||||
var arr = [], j, index;
|
||||
i = 0;
|
||||
while (i < value.length) {
|
||||
if (value.charAt(i) == '\'') {
|
||||
// Handle quotes
|
||||
if (i == value.length - 1) {
|
||||
value = value.substring(0, i); // Silently drop the trailing quote
|
||||
} else if (value.charAt(i + 1) == '\'') {
|
||||
value = value.substring(0, i) + value.substring(++i); // Escaped quote
|
||||
} else {
|
||||
// Quoted string
|
||||
j = i + 2;
|
||||
while ((j = value.indexOf('\'', j)) != -1) {
|
||||
if (j == value.length - 1 || value.charAt(j + 1) != '\'') {
|
||||
// Found start and end quotes. Remove them
|
||||
value = value.substring(0, i) + value.substring(i + 1, j) + value.substring(j + 1);
|
||||
i = j - 1;
|
||||
break;
|
||||
} else {
|
||||
// Found a double quote, reduce to a single quote.
|
||||
value = value.substring(0, j) + value.substring(++j);
|
||||
}
|
||||
}
|
||||
|
||||
if (j == -1) {
|
||||
// There is no end quote. Drop the start quote
|
||||
value = value.substring(0, i) + value.substring(i + 1);
|
||||
}
|
||||
}
|
||||
} else if (value.charAt(i) == '{') {
|
||||
// Beginning of an unquoted place holder.
|
||||
j = value.indexOf('}', i + 1);
|
||||
if (j == -1) {
|
||||
i++; // No end. Process the rest of the line. Java would throw an exception
|
||||
} else {
|
||||
// Add 1 to the index so that it aligns with the function arguments.
|
||||
index = parseInt(value.substring(i + 1, j));
|
||||
if (!isNaN(index) && index >= 0) {
|
||||
// Put the line thus far (if it isn't empty) into the array
|
||||
var s = value.substring(0, i);
|
||||
if (s !== "") {
|
||||
arr.push(s);
|
||||
}
|
||||
// Put the parameter reference into the array
|
||||
arr.push(index);
|
||||
// Start the processing over again starting from the rest of the line.
|
||||
i = 0;
|
||||
value = value.substring(j + 1);
|
||||
} else {
|
||||
i = j + 1; // Invalid parameter. Leave as is.
|
||||
}
|
||||
}
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
} // while
|
||||
|
||||
// Put the remainder of the no-empty line into the array.
|
||||
if (value !== "") {
|
||||
arr.push(value);
|
||||
}
|
||||
value = arr;
|
||||
|
||||
// Make the array the value for the entry.
|
||||
if (namespace) {
|
||||
$.i18n.map[settings.namespace][key] = arr;
|
||||
} else {
|
||||
$.i18n.map[key] = arr;
|
||||
}
|
||||
}
|
||||
|
||||
if (value.length === 0) {
|
||||
return "";
|
||||
}
|
||||
if (value.length == 1 && typeof(value[0]) == "string") {
|
||||
return value[0];
|
||||
}
|
||||
|
||||
var str = "";
|
||||
for (i = 0, j = value.length; i < j; i++) {
|
||||
if (typeof(value[i]) == "string") {
|
||||
str += value[i];
|
||||
} else if (phvList && value[i] < phvList.length) {
|
||||
// Must be a number
|
||||
str += phvList[value[i]];
|
||||
} else if (!phvList && value[i] + 1 < args.length) {
|
||||
str += args[value[i] + 1];
|
||||
} else {
|
||||
str += "{" + value[i] + "}";
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
function callbackIfComplete(settings) {
|
||||
|
||||
if (settings.debug) {
|
||||
debug('callbackIfComplete()');
|
||||
debug('totalFiles: ' + settings.totalFiles);
|
||||
debug('filesLoaded: ' + settings.filesLoaded);
|
||||
}
|
||||
|
||||
if (settings.async) {
|
||||
if (settings.filesLoaded === settings.totalFiles) {
|
||||
if (settings.callback) {
|
||||
settings.callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadAndParseFiles(fileNames, settings) {
|
||||
|
||||
if (settings.debug) debug('loadAndParseFiles');
|
||||
|
||||
if (fileNames !== null && fileNames.length > 0) {
|
||||
loadAndParseFile(fileNames[0], settings, function () {
|
||||
fileNames.shift();
|
||||
loadAndParseFiles(fileNames,settings);
|
||||
});
|
||||
} else {
|
||||
callbackIfComplete(settings);
|
||||
}
|
||||
}
|
||||
|
||||
/** Load and parse .properties files */
|
||||
function loadAndParseFile(filename, settings, nextFile) {
|
||||
|
||||
if (settings.debug) {
|
||||
debug('loadAndParseFile(\'' + filename +'\')');
|
||||
debug('totalFiles: ' + settings.totalFiles);
|
||||
debug('filesLoaded: ' + settings.filesLoaded);
|
||||
}
|
||||
|
||||
if (filename !== null && typeof filename !== 'undefined') {
|
||||
$.ajax({
|
||||
url: filename,
|
||||
async: settings.async,
|
||||
cache: settings.cache,
|
||||
dataType: 'text',
|
||||
success: function (data, status) {
|
||||
|
||||
if (settings.debug) {
|
||||
debug('Succeeded in downloading ' + filename + '.');
|
||||
debug(data);
|
||||
}
|
||||
|
||||
parseData(data, settings);
|
||||
nextFile();
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
|
||||
if (settings.debug) {
|
||||
debug('Failed to download or parse ' + filename + '. errorThrown: ' + errorThrown);
|
||||
}
|
||||
if (jqXHR.status === 404) {
|
||||
settings.totalFiles -= 1;
|
||||
}
|
||||
nextFile();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** Parse .properties files */
|
||||
function parseData(data, settings) {
|
||||
|
||||
var parsed = '';
|
||||
var lines = data.split(/\n/);
|
||||
var regPlaceHolder = /(\{\d+})/g;
|
||||
var regRepPlaceHolder = /\{(\d+)}/g;
|
||||
var unicodeRE = /(\\u.{4})/ig;
|
||||
for (var i=0,j=lines.length;i<j;i++) {
|
||||
var line = lines[i];
|
||||
|
||||
line = line.trim();
|
||||
if (line.length > 0 && line.match("^#") != "#") { // skip comments
|
||||
var pair = line.split('=');
|
||||
if (pair.length > 0) {
|
||||
/** Process key & value */
|
||||
var name = decodeURI(pair[0]).trim();
|
||||
var value = pair.length == 1 ? "" : pair[1];
|
||||
// process multi-line values
|
||||
while (value.search(/\\$/) != -1) {
|
||||
value = value.substring(0, value.length - 1);
|
||||
value += lines[++i].trimRight();
|
||||
}
|
||||
// Put values with embedded '='s back together
|
||||
for (var s = 2; s < pair.length; s++) {
|
||||
value += '=' + pair[s];
|
||||
}
|
||||
value = value.trim();
|
||||
|
||||
/** Mode: bundle keys in a map */
|
||||
if (settings.mode == 'map' || settings.mode == 'both') {
|
||||
// handle unicode chars possibly left out
|
||||
var unicodeMatches = value.match(unicodeRE);
|
||||
if (unicodeMatches) {
|
||||
unicodeMatches.forEach(function (match) {
|
||||
value = value.replace(match, unescapeUnicode(match));
|
||||
});
|
||||
}
|
||||
// add to map
|
||||
if (settings.namespace) {
|
||||
$.i18n.map[settings.namespace][name] = value;
|
||||
} else {
|
||||
$.i18n.map[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Mode: bundle keys as vars/functions */
|
||||
if (settings.mode == 'vars' || settings.mode == 'both') {
|
||||
value = value.replace(/"/g, '\\"'); // escape quotation mark (")
|
||||
|
||||
// make sure namespaced key exists (eg, 'some.key')
|
||||
checkKeyNamespace(name);
|
||||
|
||||
// value with variable substitutions
|
||||
if (regPlaceHolder.test(value)) {
|
||||
var parts = value.split(regPlaceHolder);
|
||||
// process function args
|
||||
var first = true;
|
||||
var fnArgs = '';
|
||||
var usedArgs = [];
|
||||
parts.forEach(function (part) {
|
||||
|
||||
if (regPlaceHolder.test(part) && (usedArgs.length === 0 || usedArgs.indexOf(part) == -1)) {
|
||||
if (!first) {
|
||||
fnArgs += ',';
|
||||
}
|
||||
fnArgs += part.replace(regRepPlaceHolder, 'v$1');
|
||||
usedArgs.push(part);
|
||||
first = false;
|
||||
}
|
||||
});
|
||||
parsed += name + '=function(' + fnArgs + '){';
|
||||
// process function body
|
||||
var fnExpr = '"' + value.replace(regRepPlaceHolder, '"+v$1+"') + '"';
|
||||
parsed += 'return ' + fnExpr + ';' + '};';
|
||||
// simple value
|
||||
} else {
|
||||
parsed += name + '="' + value + '";';
|
||||
}
|
||||
} // END: Mode: bundle keys as vars/functions
|
||||
} // END: if(pair.length > 0)
|
||||
} // END: skip comments
|
||||
}
|
||||
eval(parsed);
|
||||
settings.filesLoaded += 1;
|
||||
}
|
||||
|
||||
/** Make sure namespace exists (for keys with dots in name) */
|
||||
// TODO key parts that start with numbers quietly fail. i.e. month.short.1=Jan
|
||||
function checkKeyNamespace(key) {
|
||||
|
||||
var regDot = /\./;
|
||||
if (regDot.test(key)) {
|
||||
var fullname = '';
|
||||
var names = key.split(/\./);
|
||||
for (var i=0,j=names.length;i<j;i++) {
|
||||
var name = names[i];
|
||||
|
||||
if (i > 0) {
|
||||
fullname += '.';
|
||||
}
|
||||
|
||||
fullname += name;
|
||||
if (eval('typeof ' + fullname + ' == "undefined"')) {
|
||||
eval(fullname + '={};');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Ensure language code is in the format aa_AA. */
|
||||
$.i18n.normaliseLanguageCode = function (settings) {
|
||||
|
||||
var lang = settings.language;
|
||||
if (!lang || lang.length < 2) {
|
||||
if (settings.debug) debug('No language supplied. Pulling it from the browser ...');
|
||||
lang = (navigator.languages && navigator.languages.length > 0) ? navigator.languages[0]
|
||||
: (navigator.language || navigator.userLanguage /* IE */ || 'en');
|
||||
if (settings.debug) debug('Language from browser: ' + lang);
|
||||
}
|
||||
|
||||
lang = lang.toLowerCase();
|
||||
lang = lang.replace(/-/,"_"); // some browsers report language as en-US instead of en_US
|
||||
if (lang.length > 3) {
|
||||
lang = lang.substring(0, 3) + lang.substring(3).toUpperCase();
|
||||
}
|
||||
return lang;
|
||||
};
|
||||
|
||||
/** Unescape unicode chars ('\u00e3') */
|
||||
function unescapeUnicode(str) {
|
||||
|
||||
// unescape unicode codes
|
||||
var codes = [];
|
||||
var code = parseInt(str.substr(2), 16);
|
||||
if (code >= 0 && code < Math.pow(2, 16)) {
|
||||
codes.push(code);
|
||||
}
|
||||
// convert codes to text
|
||||
return codes.reduce(function (acc, val) { return acc + String.fromCharCode(val); }, '');
|
||||
}
|
||||
}) (jQuery);
|
||||