| 1 |
const StockpackAttribution = wp.media.View.extend( /** @lends wp.media.view.Toolbar.prototype */{ |
| 2 |
tagName: 'div', |
| 3 |
className: 'stockpack-attribution', |
| 4 |
template: wp.template( 'stockpack-attribution' ), |
| 5 |
events: { |
| 6 |
'click .notice-dismiss': 'dismiss', |
| 7 |
}, |
| 8 |
defaults: { |
| 9 |
id: 'stockpack-attribution', |
| 10 |
message: '', |
| 11 |
author_info: '', |
| 12 |
link: '', |
| 13 |
link_title: '', |
| 14 |
}, |
| 15 |
dismissed: false, |
| 16 |
|
| 17 |
initialize() { |
| 18 |
this.model = new Backbone.Model( this.defaults ); |
| 19 |
// If any of the `options` have a key from `defaults`, apply its |
| 20 |
// value to the `model` and remove it from the `options object. |
| 21 |
_.each( this.defaults, function( def, key ) { |
| 22 |
const value = this.options[ key ]; |
| 23 |
if ( _.isUndefined( value ) ) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
this.model.set( key, value ); |
| 28 |
delete this.options[ key ]; |
| 29 |
}, this ); |
| 30 |
|
| 31 |
this.updateProvider( 'default' ); |
| 32 |
|
| 33 |
this.controller.on( 'update_provider', _.debounce( this.updateProvider, 150 ), this ); |
| 34 |
}, |
| 35 |
|
| 36 |
show() { |
| 37 |
if ( ! this.dismissed ) { |
| 38 |
this.$el.removeClass('hidden') |
| 39 |
} |
| 40 |
}, |
| 41 |
|
| 42 |
hide() { |
| 43 |
this.$el.addClass('hidden') |
| 44 |
}, |
| 45 |
|
| 46 |
dispose() { |
| 47 |
this.$el.remove(); |
| 48 |
}, |
| 49 |
|
| 50 |
dismiss() { |
| 51 |
this.$el.hide(); |
| 52 |
this.dismissed = true; |
| 53 |
}, |
| 54 |
|
| 55 |
prepare() { |
| 56 |
return this.model.toJSON(); |
| 57 |
}, |
| 58 |
|
| 59 |
updateProvider( provider ) { |
| 60 |
const data = wp.media.view.l10n.stockpack.attribution[ provider ]; |
| 61 |
_.each( data, function( value, key ) { |
| 62 |
this.model.set( key, value ); |
| 63 |
}, this ); |
| 64 |
this.render(); |
| 65 |
}, |
| 66 |
|
| 67 |
} ); |
| 68 |
|
| 69 |
export default StockpackAttribution; |
| 70 |
|