Skip to content

Commit

Permalink
Now with linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Kos committed Aug 21, 2015
1 parent 18f971c commit dd89a91
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 33 deletions.
26 changes: 26 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"rules": {
"indent": [2, 2],
"quotes": [2, "single"],
"linebreak-style": [2, "unix"],
"max-len": [2, 120, 4, {"ignoreUrls": true}],
"semi": [2, "always"],
"space-before-function-paren": [2, "always"]
},
"env": {
"browser": true
},
"extends": "eslint:recommended",
"globals": {
"afterEach": false,
"beforeEach": false,
"describe": false,
"expect": false,
"global": false,
"it": false,
"module": false,
"process": false,
"require": false,
"sinon": false
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"description": "Do not install via npm.",
"private": true,
"scripts": {
"build": "mkdir -p build && ./node_modules/.bin/browserify -s bulbs.ads.manager -r ./src/dfp.js:bulbs.ads.dfp -r ./src/utils.js:bulbs.ads.utils -r ./src/manager.js:bulbs.ads.manager -x bulbs.ads.units > build/adsManager.js",
"test": "./node_modules/.bin/karma start resources/test/karma.conf.js"
"test": "./node_modules/.bin/karma start resources/test/karma.conf.js",
"lint": "./node_modules/.bin/eslint src resources"
},
"devDependencies": {
"browserify": "^11.0.1",
"chai": "^3.2.0",
"eslint": "^1.2.1",
"karma": "^0.13.8",
"karma-browserify": "^4.3.0",
"karma-chai": "^0.1.0",
Expand Down
4 changes: 2 additions & 2 deletions resources/test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function (config) {

// list of files / patterns to load in the browser
files: [
'src/*.spec.js',
'src/*.spec.js'
],

// list of files to exclude
Expand All @@ -25,7 +25,7 @@ module.exports = function (config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'src/*.spec.js': 'browserify',
'src/*.spec.js': 'browserify'
},

plugins : [
Expand Down
15 changes: 5 additions & 10 deletions resources/test/mock-ad-units.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ module.exports = {
[[970, 0], [[728, 90], [970, 250], [970, 90], [970, 415]]],
[[728, 0], [728, 90]],
[[0, 0], [320, 50]]
],
onSlotRenderEnded: function (e, el) {}
]
},

'article-header': {
Expand All @@ -39,29 +38,25 @@ module.exports = {
[[970, 0], [[728, 90], [970, 250]]],
[[728, 0], [728, 90]],
[[0, 0], [320, 50]]
],
onSlotRenderEnded: function (e, el) {}
]
},

'sidebar-primary': {
sizes: [
[[0, 0], [300, 250]]
],
onSlotRenderEnded: function (e, el) {}
]
},

'sidebar-secondary': {
sizes: [
[[0, 0], [300, 250]]
],
onSlotRenderEnded: function (e, el) {}
]
},

'sidebar-tertiary': {
sizes: [
[[0, 0], [300, 250]]
],
onSlotRenderEnded: function (e, el) {}
]
}
}
};
16 changes: 8 additions & 8 deletions resources/test/mock-google-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ var MockGoogleTag = function MockGoogleTag () {
};

MockGoogleTag.prototype.content = function () {
return {
setContent: function (slot, content) {},
return {
setContent: function () {},
addEventListener: function () {}
};
};
};

MockGoogleTag.prototype.pubads = function () {
return {
collapseEmptyDivs: function () {},
enableSingleRequest: function () {},
return {
collapseEmptyDivs: function () {},
enableSingleRequest: function () {},
disableInitialLoad: function () {},
addEventListener: function () {},
};
addEventListener: function () {}
};
};

module.exports = MockGoogleTag;
12 changes: 7 additions & 5 deletions src/dfp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
window.googletag = window.googletag || {};
window.googletag.cmd = window.googletag.cmd || [];

var gads = document.createElement("script");
var gads = document.createElement('script');
gads.async = true;
gads.type = "text/javascript";
var useSSL = "https:" == document.location.protocol;
gads.src = (useSSL ? "https:" : "http:") + "//www.googletagservices.com/tag/js/gpt.js";
var node = document.getElementsByTagName("script")[0];
gads.type = 'text/javascript';

var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js';

var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);

module.exports = window.googletag;
15 changes: 11 additions & 4 deletions src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
var resizeTimeout = null;
var viewportWidth = 0;
var oldViewportWidth = null;
global.addEventListener('resize', function (e) {
global.addEventListener('resize', function () {
if (adManager.doReloadOnResize) {
viewportWidth = global.document.body.clientWidth;

Expand Down Expand Up @@ -186,7 +186,7 @@ module.exports = {

// Let's make a random placeholder ad!
var randomIndex = Math.floor(Math.random() * validSizes.length);
size = validSizes[randomIndex];
var size = validSizes[randomIndex];

var iframe = document.createElement('iframe');
iframe.scrolling = 'no';
Expand All @@ -208,9 +208,16 @@ module.exports = {
'line-height: ' + size[1] + 'px'
];

iframe.srcdoc = '<html><head><style>body{' + styles.join(';') + '}</style><title>' + sizeLabel + '</title></head><body><b>' + sizeLabel + '</b></body></html>';
iframe.srcdoc =
'<html><head><style>body{' +
styles.join(';') +
'}</style><title>' +
sizeLabel +
'</title></head><body><b>' +
sizeLabel +
'</b></body></html>';

var tmp = document.createElement("div");
var tmp = document.createElement('div');
tmp.appendChild(iframe);

return tmp.innerHTML;
Expand Down
10 changes: 8 additions & 2 deletions src/manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ describe('AdsManager', function () {
el.innerHTML = '<div class="dfp" data-slot-name="testing"></div>';
expect(ads.findAds(el).length).to.equal(1);

el.innerHTML = '<div class="dfp" data-slot-name="testing"></div><div class="dfp" data-slot-name="testing-two"></div>';
el.innerHTML =
'<div class="dfp" data-slot-name="testing"></div>' +
'<div class="dfp" data-slot-name="testing-two"></div>';
expect(ads.findAds(el).length).to.equal(2);

el.innerHTML = '<section class="bullshit"><div class="dfp" data-ad-unit="testing"></div><div class="dfp" data-ad-unit="testing-two"></div></section>';
el.innerHTML =
'<section class="bullshit">' +
'<div class="dfp" data-ad-unit="testing"></div>' +
'<div class="dfp" data-ad-unit="testing-two"></div>' +
'</section>';
expect(ads.findAds(el).length).to.equal(2);
});

Expand Down

0 comments on commit dd89a91

Please sign in to comment.