Move CustomStyle.

This commit is contained in:
Yury Delendik 2015-11-09 19:24:15 -06:00
parent 467c6f93b5
commit 2f34fd46cb
11 changed files with 87 additions and 55 deletions

View File

@ -11,6 +11,7 @@
<script src="../../src/display/webgl.js"></script> <script src="../../src/display/webgl.js"></script>
<script src="../../src/display/pattern_helper.js"></script> <script src="../../src/display/pattern_helper.js"></script>
<script src="../../src/display/font_loader.js"></script> <script src="../../src/display/font_loader.js"></script>
<script src="../../src/display/dom_utils.js"></script>
<script src="../../src/display/annotation_helper.js"></script> <script src="../../src/display/annotation_helper.js"></script>
<script> <script>

View File

@ -11,6 +11,7 @@
<script src="../../src/display/webgl.js"></script> <script src="../../src/display/webgl.js"></script>
<script src="../../src/display/pattern_helper.js"></script> <script src="../../src/display/pattern_helper.js"></script>
<script src="../../src/display/font_loader.js"></script> <script src="../../src/display/font_loader.js"></script>
<script src="../../src/display/dom_utils.js"></script>
<script src="../../src/display/annotation_helper.js"></script> <script src="../../src/display/annotation_helper.js"></script>
<script> <script>

View File

@ -530,6 +530,7 @@ target.bundle = function(args) {
'display/webgl.js', 'display/webgl.js',
'display/pattern_helper.js', 'display/pattern_helper.js',
'display/font_loader.js', 'display/font_loader.js',
'display/dom_utils.js',
'display/annotation_helper.js', 'display/annotation_helper.js',
'display/svg.js' 'display/svg.js'
]); ]);

73
src/display/dom_utils.js Normal file
View File

@ -0,0 +1,73 @@
/* Copyright 2015 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 PDFJS */
'use strict';
/**
* Optimised CSS custom property getter/setter.
* @class
*/
var CustomStyle = (function CustomStyleClosure() {
// As noted on: http://www.zachstronaut.com/posts/2009/02/17/
// animate-css-transforms-firefox-webkit.html
// in some versions of IE9 it is critical that ms appear in this list
// before Moz
var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
var _cache = {};
function CustomStyle() {}
CustomStyle.getProp = function get(propName, element) {
// check cache only when no element is given
if (arguments.length === 1 && typeof _cache[propName] === 'string') {
return _cache[propName];
}
element = element || document.documentElement;
var style = element.style, prefixed, uPropName;
// test standard property first
if (typeof style[propName] === 'string') {
return (_cache[propName] = propName);
}
// capitalize
uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
// test vendor specific properties
for (var i = 0, l = prefixes.length; i < l; i++) {
prefixed = prefixes[i] + uPropName;
if (typeof style[prefixed] === 'string') {
return (_cache[propName] = prefixed);
}
}
//if all fails then set to undefined
return (_cache[propName] = 'undefined');
};
CustomStyle.setProp = function set(propName, element, str) {
var prop = this.getProp(propName);
if (prop !== 'undefined') {
element.style[prop] = str;
}
};
return CustomStyle;
})();
PDFJS.CustomStyle = CustomStyle;

View File

@ -25,6 +25,7 @@ limitations under the License.
<script src="../src/display/webgl.js"></script> <script src="../src/display/webgl.js"></script>
<script src="../src/display/pattern_helper.js"></script> <script src="../src/display/pattern_helper.js"></script>
<script src="../src/display/font_loader.js"></script> <script src="../src/display/font_loader.js"></script>
<script src="../src/display/dom_utils.js"></script>
<script src="../src/display/annotation_helper.js"></script> <script src="../src/display/annotation_helper.js"></script>
<script src="driver.js"></script> <script src="driver.js"></script>
</head> </head>

View File

@ -36,6 +36,7 @@
<script src="../../src/core/ps_parser.js"></script> <script src="../../src/core/ps_parser.js"></script>
<script src="../../src/display/pattern_helper.js"></script> <script src="../../src/display/pattern_helper.js"></script>
<script src="../../src/display/font_loader.js"></script> <script src="../../src/display/font_loader.js"></script>
<script src="../../src/display/dom_utils.js"></script>
<script src="../../src/display/annotation_helper.js"></script> <script src="../../src/display/annotation_helper.js"></script>
<script src="../../src/core/stream.js"></script> <script src="../../src/core/stream.js"></script>
<script src="../../src/core/worker.js"></script> <script src="../../src/core/worker.js"></script>

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/*globals PDFJS, CustomStyle, mozL10n, SimpleLinkService */ /*globals PDFJS, mozL10n, SimpleLinkService */
'use strict'; 'use strict';
@ -27,6 +27,8 @@
* @class * @class
*/ */
var AnnotationsLayerBuilder = (function AnnotationsLayerBuilderClosure() { var AnnotationsLayerBuilder = (function AnnotationsLayerBuilderClosure() {
var CustomStyle = PDFJS.CustomStyle;
/** /**
* @param {AnnotationsLayerBuilderOptions} options * @param {AnnotationsLayerBuilderOptions} options
* @constructs AnnotationsLayerBuilder * @constructs AnnotationsLayerBuilder

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals RenderingStates, PDFJS, CustomStyle, CSS_UNITS, getOutputScale, /* globals RenderingStates, PDFJS, CSS_UNITS, getOutputScale,
TextLayerBuilder, AnnotationsLayerBuilder, Promise, TextLayerBuilder, AnnotationsLayerBuilder, Promise,
approximateFraction, roundToDivide */ approximateFraction, roundToDivide */
@ -36,6 +36,8 @@ var TEXT_LAYER_RENDER_DELAY = 200; // ms
* @implements {IRenderableView} * @implements {IRenderableView}
*/ */
var PDFPageView = (function PDFPageViewClosure() { var PDFPageView = (function PDFPageViewClosure() {
var CustomStyle = PDFJS.CustomStyle;
/** /**
* @constructs PDFPageView * @constructs PDFPageView
* @param {PDFPageViewOptions} options * @param {PDFPageViewOptions} options

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals CustomStyle, PDFJS */ /* globals PDFJS */
'use strict'; 'use strict';
@ -119,7 +119,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
transform = 'rotate(' + rotation + 'deg) ' + transform; transform = 'rotate(' + rotation + 'deg) ' + transform;
} }
if (transform) { if (transform) {
CustomStyle.setProp('transform' , textDiv, transform); PDFJS.CustomStyle.setProp('transform' , textDiv, transform);
} }
} }
} }

View File

@ -23,57 +23,6 @@ var MAX_AUTO_SCALE = 1.25;
var SCROLLBAR_PADDING = 40; var SCROLLBAR_PADDING = 40;
var VERTICAL_PADDING = 5; var VERTICAL_PADDING = 5;
// optimised CSS custom property getter/setter
var CustomStyle = (function CustomStyleClosure() {
// As noted on: http://www.zachstronaut.com/posts/2009/02/17/
// animate-css-transforms-firefox-webkit.html
// in some versions of IE9 it is critical that ms appear in this list
// before Moz
var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
var _cache = {};
function CustomStyle() {}
CustomStyle.getProp = function get(propName, element) {
// check cache only when no element is given
if (arguments.length === 1 && typeof _cache[propName] === 'string') {
return _cache[propName];
}
element = element || document.documentElement;
var style = element.style, prefixed, uPropName;
// test standard property first
if (typeof style[propName] === 'string') {
return (_cache[propName] = propName);
}
// capitalize
uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
// test vendor specific properties
for (var i = 0, l = prefixes.length; i < l; i++) {
prefixed = prefixes[i] + uPropName;
if (typeof style[prefixed] === 'string') {
return (_cache[propName] = prefixed);
}
}
//if all fails then set to undefined
return (_cache[propName] = 'undefined');
};
CustomStyle.setProp = function set(propName, element, str) {
var prop = this.getProp(propName);
if (prop !== 'undefined') {
element.style[prop] = str;
}
};
return CustomStyle;
})();
var NullCharactersRegExp = /\x00/g; var NullCharactersRegExp = /\x00/g;
function removeNullCharacters(str) { function removeNullCharacters(str) {

View File

@ -60,6 +60,7 @@ See https://github.com/adobe-type-tools/cmap-resources
<script src="../src/display/webgl.js"></script> <script src="../src/display/webgl.js"></script>
<script src="../src/display/pattern_helper.js"></script> <script src="../src/display/pattern_helper.js"></script>
<script src="../src/display/font_loader.js"></script> <script src="../src/display/font_loader.js"></script>
<script src="../src/display/dom_utils.js"></script>
<script src="../src/display/annotation_helper.js"></script> <script src="../src/display/annotation_helper.js"></script>
<script>PDFJS.workerSrc = '../src/worker_loader.js';</script> <script>PDFJS.workerSrc = '../src/worker_loader.js';</script>
<!--#endif--> <!--#endif-->