|
3 | 3 | * |
4 | 4 | * @author Athletics - http://athleticsnyc.com |
5 | 5 | * @see https://github.com/athletics/AdManager |
6 | | - * @version 0.5.1 |
| 6 | + * @version 0.6.0 |
7 | 7 | *//** |
8 | 8 | * Shared utilities for debugging and array manipulation. |
9 | 9 | */ |
|
165 | 165 | ] |
166 | 166 | }, |
167 | 167 | inventory: [], // Inventory of ad units |
168 | | - pageConfigAttr: false, // Selector for dynamic config import |
169 | 168 | targeting: [] // Key value pairs to send with DFP request |
170 | 169 | }; |
171 | 170 |
|
|
174 | 173 | /** |
175 | 174 | * Merge passed config with defaults. |
176 | 175 | * |
| 176 | + * @fires AdManager:unitsInserted |
| 177 | + * |
177 | 178 | * @param {Object} newConfig |
178 | 179 | */ |
179 | 180 | function init( newConfig ) { |
180 | 181 |
|
181 | | - config = $.extend( defaults, newConfig ); |
| 182 | + $( document ).on( 'AdManager:importConfig', onImportConfig ); |
| 183 | + |
| 184 | + $.event.trigger( 'AdManager:importConfig', newConfig ); |
182 | 185 |
|
183 | 186 | } |
184 | 187 |
|
|
262 | 265 | } |
263 | 266 |
|
264 | 267 | /** |
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. |
269 | 270 | * |
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 |
276 | 274 | */ |
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 ) { |
285 | 276 |
|
286 | | - selector = '*[data-' + attrName + ']'; |
287 | | - newConfig = $.extend( {}, existConfig ); |
288 | | - data = $context.find( selector ).data( attrName ); |
| 277 | + config = $.extend( defaults, config, newConfig ); |
289 | 278 |
|
290 | | - if ( typeof newConfig === 'object' ) { |
291 | | - newConfig = $.extend( newConfig, data ); |
292 | | - } |
293 | | - |
294 | | - return newConfig; |
| 279 | + return config; |
295 | 280 |
|
296 | 281 | } |
297 | 282 |
|
298 | 283 | ////////////////////////////////////////////////////////////////////////////////////// |
299 | 284 |
|
300 | 285 | return { |
301 | | - init: init, |
302 | | - set: set, |
303 | | - get: get, |
304 | | - importConfig: importConfig |
| 286 | + init: init, |
| 287 | + set: set, |
| 288 | + get: get |
305 | 289 | }; |
306 | 290 |
|
307 | 291 | } ) ); |
|
810 | 794 |
|
811 | 795 | var targeting = Config.get( 'targeting' ); |
812 | 796 |
|
813 | | - if ( ! targeting.length ) { |
| 797 | + if ( $.isEmptyObject( targeting ) ) { |
814 | 798 | return; |
815 | 799 | } |
816 | 800 |
|
|
0 commit comments