Skip to content

Commit

Permalink
fix: fix jscs errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanee committed Aug 30, 2015
1 parent 66d7bb9 commit bfcbedf
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 43 deletions.
69 changes: 65 additions & 4 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,69 @@
{
"preset": "jquery",
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
"validateQuoteMarks": "'",
"disallowMultipleVarDecl": true,
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireOperatorBeforeLineBreak": true,
"requireParenthesesAroundIIFE": true,
"requireCommaBeforeLineBreak": true,
"requireDotNotation": true,
"requireSpacesInsideArrayBrackets": "all",
"maximumLineLength": {
"value": 1000
}
"value": 1000,
"tabSize": 4,
"allowUrlComments": true,
"allowRegex": true
},
"validateQuoteMarks": "'",
"disallowMixedSpacesAndTabs": "smart",
"disallowTrailingWhitespace": true,
"disallowMultipleLineStrings": true,
"disallowTrailingComma": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpacesInsideObjectBrackets": "all",
"requireSpacesInsideArrayBrackets": "all",
"requireSpacesInConditionalExpression": true,
"requireSpaceAfterBinaryOperators": true,
"requireLineFeedAtFileEnd": true,
"requireSpaceBeforeBinaryOperators": [
"=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=",
"&=", "|=", "^=", "+=",
"+", "-", "*", "/", "%", "<<", ">>", ">>>", "&",
"|", "^", "&&", "||", "===", "==", ">=",
"<=", "<", ">", "!=", "!=="
],
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"validateLineBreaks": "LF",
"disallowKeywords": [ "with" ],
"disallowKeywordsOnNewLine": [ "else" ],
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeBinaryOperators": [ ",", ":" ],
"disallowMultipleLineBreaks": true
}
47 changes: 23 additions & 24 deletions dist/angular-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@
'use strict';

angular.module('pdf', []).directive('ngPdf', [ '$window', function($window) {
var backingScale = function (canvas) {
var ctx = canvas.getContext("2d"),
dpr = window.devicePixelRatio || 1,
bsr = ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
ctx.oBackingStorePixelRatio ||
ctx.backingStorePixelRatio || 1;
var backingScale = function(canvas) {
var ctx = canvas.getContext('2d');
var dpr = window.devicePixelRatio || 1;
var bsr = ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
ctx.oBackingStorePixelRatio ||
ctx.backingStorePixelRatio || 1;

return dpr / bsr;
};


var setCanvasDimensions = function(canvas, w, h) {
var ratio = backingScale(canvas);
canvas.width = w * ratio;
canvas.height = h * ratio;
canvas.style.width = w + "px";
canvas.style.height = h + "px";
canvas.getContext("2d").setTransform(ratio, 0, 0, ratio, 0, 0);
canvas.style.width = w + 'px';
canvas.style.height = h + 'px';
canvas.getContext('2d').setTransform(ratio, 0, 0, ratio, 0, 0);
return canvas;
};
return {
Expand All @@ -32,13 +31,13 @@
return attr.templateUrl ? attr.templateUrl : 'partials/viewer.html'
},
link: function(scope, element, attrs) {
var url = scope.pdfUrl,
pdfDoc = null,
pageNum = (attrs.page ? attrs.page : 1),
scale = attrs.scale > 0 ? attrs.scale : 1,
canvas = (attrs.canvasid ? document.getElementById(attrs.canvasid) : document.getElementById('pdf-canvas')),
ctx = canvas.getContext('2d'),
windowEl = angular.element($window);
var url = scope.pdfUrl;
var pdfDoc = null
var pageNum = (attrs.page ? attrs.page : 1);
var scale = attrs.scale > 0 ? attrs.scale : 1;
var canvas = (attrs.canvasid ? document.getElementById(attrs.canvasid) : document.getElementById('pdf-canvas'));
var ctx = canvas.getContext('2d');
var windowEl = angular.element($window);

windowEl.on('scroll', function() {
scope.$apply(function() {
Expand All @@ -51,11 +50,11 @@

scope.renderPage = function(num) {
pdfDoc.getPage(num).then(function(page) {
var viewport,
pageWidthScale,
pageHeightScale,
renderContext = {},
pageRendering;
var viewport;
var pageWidthScale;
var pageHeightScale;
var renderContext = {};
var pageRendering;

if (attrs.scale === 'page-fit' && !scale) {
viewport = page.getViewport(1);
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-pdf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 34 additions & 14 deletions example/js/directives/angular-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,40 @@
'use strict';

angular.module('pdf', []).directive('ngPdf', [ '$window', function($window) {
var backingScale = function(canvas) {
var ctx = canvas.getContext('2d');
var dpr = window.devicePixelRatio || 1;
var bsr = ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
ctx.oBackingStorePixelRatio ||
ctx.backingStorePixelRatio || 1;

return dpr / bsr;
};

var setCanvasDimensions = function(canvas, w, h) {
var ratio = backingScale(canvas);
canvas.width = w * ratio;
canvas.height = h * ratio;
canvas.style.width = w + 'px';
canvas.style.height = h + 'px';
canvas.getContext('2d').setTransform(ratio, 0, 0, ratio, 0, 0);
return canvas;
};
return {
restrict: 'E',
templateUrl: function(element, attr) {
return attr.templateUrl ? attr.templateUrl : 'partials/viewer.html'
},
link: function(scope, element, attrs) {
var url = scope.pdfUrl,
pdfDoc = null,
pageNum = (attrs.page ? attrs.page : 1),
scale = attrs.scale > 0 ? attrs.scale : 1,
canvas = (attrs.canvasid ? document.getElementById(attrs.canvasid) : document.getElementById('pdf-canvas')),
ctx = canvas.getContext('2d'),
windowEl = angular.element($window);
var url = scope.pdfUrl;
var pdfDoc = null
var pageNum = (attrs.page ? attrs.page : 1);
var scale = attrs.scale > 0 ? attrs.scale : 1;
var canvas = (attrs.canvasid ? document.getElementById(attrs.canvasid) : document.getElementById('pdf-canvas'));
var ctx = canvas.getContext('2d');
var windowEl = angular.element($window);

windowEl.on('scroll', function() {
scope.$apply(function() {
Expand All @@ -29,11 +50,11 @@

scope.renderPage = function(num) {
pdfDoc.getPage(num).then(function(page) {
var viewport,
pageWidthScale,
pageHeightScale,
renderContext = {},
pageRendering;
var viewport;
var pageWidthScale;
var pageHeightScale;
var renderContext = {};
var pageRendering;

if (attrs.scale === 'page-fit' && !scale) {
viewport = page.getViewport(1);
Expand All @@ -44,8 +65,7 @@
viewport = page.getViewport(scale)
}

canvas.height = viewport.height;
canvas.width = viewport.width;
setCanvasDimensions(canvas, viewport.width, viewport.height);

renderContext = {
canvasContext: ctx,
Expand Down

0 comments on commit bfcbedf

Please sign in to comment.