@@ -229,6 +229,11 @@ function cleanAxRef(container, attr) {
229
229
}
230
230
}
231
231
232
+ /**
233
+ * Cleans up old title attribute structure (flat) in favor of the new one (nested).
234
+ *
235
+ * @param {Object } titleContainer - an object potentially including deprecated title attributes
236
+ */
232
237
function cleanTitle ( titleContainer ) {
233
238
if ( titleContainer ) {
234
239
@@ -241,45 +246,26 @@ function cleanTitle(titleContainer) {
241
246
} ;
242
247
}
243
248
244
- // TODO 882 DRY UP?
245
- // titlefont -> title.font
246
- var oldFontAttrSet = Lib . isPlainObject ( titleContainer . titlefont ) ;
247
- var newFontAttrSet = titleContainer . title && Lib . isPlainObject ( titleContainer . title . font ) ;
248
- if ( oldFontAttrSet && ! newFontAttrSet ) {
249
- nestTitleAttr ( 'titlefont' , 'font' ) ;
250
- }
251
-
252
- // titleposition -> title.position
253
- var oldPositionAttrSet = titleContainer . titleposition ;
254
- var newPositionAttrSet = titleContainer . title && titleContainer . title . position ;
255
- if ( oldPositionAttrSet && ! newPositionAttrSet ) {
256
- nestTitleAttr ( 'titleposition' , 'position' ) ;
257
- }
249
+ rewireAttr ( 'titlefont' , 'font' ) ;
250
+ rewireAttr ( 'titleposition' , 'position' ) ;
251
+ rewireAttr ( 'titleside' , 'side' ) ;
252
+ rewireAttr ( 'titleoffset' , 'offset' ) ;
253
+ }
258
254
259
- // titleside -> title.side
260
- var oldSideAttrSet = titleContainer . titleside ;
261
- var newSideAttrSet = titleContainer . title && titleContainer . title . side ;
262
- if ( oldSideAttrSet && ! newSideAttrSet ) {
263
- nestTitleAttr ( 'titleside' , 'side' ) ;
264
- }
255
+ function rewireAttr ( oldAttrName , newAttrName ) {
256
+ var oldAttrSet = titleContainer [ oldAttrName ] ;
257
+ var newAttrSet = titleContainer . title && titleContainer . title [ newAttrName ] ;
265
258
266
- // titleoffset -> title.offset
267
- var oldOffsetAttrSet = titleContainer . titleoffset ;
268
- var newOffsetAttrSet = titleContainer . title && titleContainer . title . offset ;
269
- if ( oldOffsetAttrSet && ! newOffsetAttrSet ) {
270
- nestTitleAttr ( 'titleoffset' , 'offset' ) ;
271
- }
272
- }
259
+ if ( oldAttrSet && ! newAttrSet ) {
273
260
274
- function nestTitleAttr ( oldAttrName , newAttrName ) {
261
+ // Ensure title object exists
262
+ if ( ! titleContainer . title ) {
263
+ titleContainer . title = { } ;
264
+ }
275
265
276
- // Ensure title object exists
277
- if ( ! titleContainer . title ) {
278
- titleContainer . title = { } ;
266
+ titleContainer . title [ newAttrName ] = titleContainer [ oldAttrName ] ;
267
+ delete titleContainer [ oldAttrName ] ;
279
268
}
280
-
281
- titleContainer . title [ newAttrName ] = titleContainer [ oldAttrName ] ;
282
- delete titleContainer [ oldAttrName ] ;
283
269
}
284
270
}
285
271
0 commit comments