Skip to content

Commit cb55528

Browse files
author
Matthew Spencer
committed
Merge branch 'config-import'
2 parents f704cef + 6a18f83 commit cb55528

File tree

7 files changed

+62
-87
lines changed

7 files changed

+62
-87
lines changed

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ A configuration object is required to initialize the Ad Manager.
107107
| [`account`](#account) | Integer |
108108
| [`autoload`](#autoload) | Boolean |
109109
| [`clientType`](#clienttype) | String |
110-
| [`pageConfigAttr`](#pageconfigattr) | String |
111110
| [`inventory`](#inventory) | Array |
112111
| [`context`](#context) | String |
113112
| [`enabled`](#enabled) | Boolean |
@@ -121,7 +120,6 @@ A configuration object is required to initialize the Ad Manager.
121120
{
122121
account: 1234567,
123122
clientType: 'desktop',
124-
pageConfigAttr: 'ad-page-config',
125123
inventory: [
126124
{
127125
slot: 'Unit_Name_in_DFP',
@@ -168,18 +166,6 @@ For example, if a desktop device is detected, this value should be set to `clien
168166

169167
[:arrow_up:](#configuration)
170168

171-
### `pageConfigAttr`
172-
173-
**Type:** String
174-
175-
**Default:** `false`, optional
176-
177-
**Description:** Optional DOM element data attribute name that Ad Manager uses to import additional config parameters (JSON) from. By default, Ad Manager will look for JSON in an attribute named `data-ad-page-config`.
178-
179-
_Not currently used._
180-
181-
[:arrow_up:](#configuration)
182-
183169
### `inventory`
184170

185171
**Type:** Array
@@ -426,6 +412,7 @@ Custom jQuery events prefixed with `AdManager`.
426412
| [`AdManager:runSequence`](#admanagerrunsequence) | both |
427413
| [`AdManager:emptySlots`](#admanageremptyslots) | external |
428414
| [`AdManager:emptySlotsInContext`](#admanageremptyslotsincontext) | external |
415+
| [`AdManager:importConfig`](#admanagerimportconfig) | both |
429416

430417
### `AdManager:libraryLoaded`
431418

@@ -508,6 +495,26 @@ $.event.trigger( 'AdManager:emptySlotsInContext', {
508495

509496
[:arrow_up:](#events)
510497

498+
### `AdManager:importConfig`
499+
500+
**Description:** Pass an object to import new configuration values. The new config will override values in the current config.
501+
502+
**Example Usage:**
503+
504+
```javascript
505+
$.event.trigger( 'AdManager:importConfig', {
506+
targeting: {
507+
category: [
508+
'athletics',
509+
'technology',
510+
'graphic design'
511+
]
512+
}
513+
} );
514+
```
515+
516+
[:arrow_up:](#events)
517+
511518
## Dynamic Insertion
512519

513520
### Overview

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "admanager",
3-
"version": "0.5.1",
3+
"version": "0.6.0",
44
"homepage": "https://github.com/athletics/AdManager",
55
"description": "A JavaScipt library for interacting with Google DFP.",
66
"license": "Apache-2.0",
@@ -14,6 +14,6 @@
1414
"Athletics"
1515
],
1616
"dependencies": {
17-
"jquery": "~2.1.4"
17+
"jquery": ">=1.8"
1818
}
1919
}

dist/AdManager.js

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @author Athletics - http://athleticsnyc.com
55
* @see https://github.com/athletics/AdManager
6-
* @version 0.5.1
6+
* @version 0.6.0
77
*//**
88
* Shared utilities for debugging and array manipulation.
99
*/
@@ -165,7 +165,6 @@
165165
]
166166
},
167167
inventory: [], // Inventory of ad units
168-
pageConfigAttr: false, // Selector for dynamic config import
169168
targeting: [] // Key value pairs to send with DFP request
170169
};
171170

@@ -174,11 +173,15 @@
174173
/**
175174
* Merge passed config with defaults.
176175
*
176+
* @fires AdManager:unitsInserted
177+
*
177178
* @param {Object} newConfig
178179
*/
179180
function init( newConfig ) {
180181

181-
config = $.extend( defaults, newConfig );
182+
$( document ).on( 'AdManager:importConfig', onImportConfig );
183+
184+
$.event.trigger( 'AdManager:importConfig', newConfig );
182185

183186
}
184187

@@ -262,46 +265,27 @@
262265
}
263266

264267
/**
265-
* Import JSON page config data from DOM.
266-
*
267-
* This imports inline JSON via data attribute
268-
* and extends an existing config with it.
268+
* Import new config.
269+
* Merges with the current config.
269270
*
270-
* @todo Reenable usage in the project.
271-
* Ascertain the correct place to use.
272-
*
273-
* @param {Object} options.$context
274-
* @param {String} options.attrName
275-
* @return {Object}
271+
* @param {Object} event
272+
* @param {Object} newConfig
273+
* @return {Object} config
276274
*/
277-
function importConfig( options ) {
278-
279-
var $context = options.$context,
280-
attrName = options.attrName,
281-
existConfig = options.existConfig,
282-
selector,
283-
newConfig,
284-
data = {};
275+
function onImportConfig( event, newConfig ) {
285276

286-
selector = '*[data-' + attrName + ']';
287-
newConfig = $.extend( {}, existConfig );
288-
data = $context.find( selector ).data( attrName );
277+
config = $.extend( defaults, config, newConfig );
289278

290-
if ( typeof newConfig === 'object' ) {
291-
newConfig = $.extend( newConfig, data );
292-
}
293-
294-
return newConfig;
279+
return config;
295280

296281
}
297282

298283
//////////////////////////////////////////////////////////////////////////////////////
299284

300285
return {
301-
init: init,
302-
set: set,
303-
get: get,
304-
importConfig: importConfig
286+
init: init,
287+
set: set,
288+
get: get
305289
};
306290

307291
} ) );
@@ -810,7 +794,7 @@
810794

811795
var targeting = Config.get( 'targeting' );
812796

813-
if ( ! targeting.length ) {
797+
if ( $.isEmptyObject( targeting ) ) {
814798
return;
815799
}
816800

dist/AdManager.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "admanager",
3-
"version": "0.5.1",
3+
"version": "0.6.0",
44
"description": "A JavaScipt library for interacting with Google DFP.",
55
"main": "src/Index.js",
66
"repository": {
@@ -20,6 +20,6 @@
2020
"requirejs": "^2.1.17"
2121
},
2222
"dependencies": {
23-
"jquery": "^2.1.4"
23+
"jquery": ">=1.8"
2424
}
2525
}

src/Config.js

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
]
6262
},
6363
inventory: [], // Inventory of ad units
64-
pageConfigAttr: false, // Selector for dynamic config import
6564
targeting: [] // Key value pairs to send with DFP request
6665
};
6766

@@ -70,11 +69,15 @@
7069
/**
7170
* Merge passed config with defaults.
7271
*
72+
* @fires AdManager:unitsInserted
73+
*
7374
* @param {Object} newConfig
7475
*/
7576
function init( newConfig ) {
7677

77-
config = $.extend( defaults, newConfig );
78+
$( document ).on( 'AdManager:importConfig', onImportConfig );
79+
80+
$.event.trigger( 'AdManager:importConfig', newConfig );
7881

7982
}
8083

@@ -158,46 +161,27 @@
158161
}
159162

160163
/**
161-
* Import JSON page config data from DOM.
162-
*
163-
* This imports inline JSON via data attribute
164-
* and extends an existing config with it.
164+
* Import new config.
165+
* Merges with the current config.
165166
*
166-
* @todo Reenable usage in the project.
167-
* Ascertain the correct place to use.
168-
*
169-
* @param {Object} options.$context
170-
* @param {String} options.attrName
171-
* @return {Object}
167+
* @param {Object} event
168+
* @param {Object} newConfig
169+
* @return {Object} config
172170
*/
173-
function importConfig( options ) {
174-
175-
var $context = options.$context,
176-
attrName = options.attrName,
177-
existConfig = options.existConfig,
178-
selector,
179-
newConfig,
180-
data = {};
171+
function onImportConfig( event, newConfig ) {
181172

182-
selector = '*[data-' + attrName + ']';
183-
newConfig = $.extend( {}, existConfig );
184-
data = $context.find( selector ).data( attrName );
173+
config = $.extend( defaults, config, newConfig );
185174

186-
if ( typeof newConfig === 'object' ) {
187-
newConfig = $.extend( newConfig, data );
188-
}
189-
190-
return newConfig;
175+
return config;
191176

192177
}
193178

194179
//////////////////////////////////////////////////////////////////////////////////////
195180

196181
return {
197-
init: init,
198-
set: set,
199-
get: get,
200-
importConfig: importConfig
182+
init: init,
183+
set: set,
184+
get: get
201185
};
202186

203187
} ) );

src/Manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220

221221
var targeting = Config.get( 'targeting' );
222222

223-
if ( ! targeting.length ) {
223+
if ( $.isEmptyObject( targeting ) ) {
224224
return;
225225
}
226226

0 commit comments

Comments
 (0)