meta-box.js
87 lines
| 1 | /** |
| 2 | * Minute Control. |
| 3 | * |
| 4 | * @package ShareThisFollowButtons |
| 5 | */ |
| 6 | |
| 7 | /* exported MinuteControl */ |
| 8 | var MinuteControl = ( function( $, wp ) { |
| 9 | 'use strict'; |
| 10 | |
| 11 | return { |
| 12 | /** |
| 13 | * Holds data. |
| 14 | */ |
| 15 | data: {}, |
| 16 | |
| 17 | /** |
| 18 | * Boot plugin. |
| 19 | * |
| 20 | * @param data |
| 21 | */ |
| 22 | boot: function( data ) { |
| 23 | this.data = data; |
| 24 | |
| 25 | $( document ).ready( |
| 26 | function() { |
| 27 | this.init(); |
| 28 | }.bind( this ) |
| 29 | ); |
| 30 | }, |
| 31 | |
| 32 | /** |
| 33 | * Initialize plugin. |
| 34 | */ |
| 35 | init: function() { |
| 36 | this.$container = $( '#sharethis-follow-meta-box' ); |
| 37 | |
| 38 | this.listen(); |
| 39 | }, |
| 40 | |
| 41 | /** |
| 42 | * Initiate listeners. |
| 43 | */ |
| 44 | listen: function() { |
| 45 | var self = this; |
| 46 | |
| 47 | // When checking an option in the meta box. |
| 48 | this.$container.on( |
| 49 | 'click', |
| 50 | '#sharethis-follow-bottom-post, #sharethis-follow-top-post', |
| 51 | function() { |
| 52 | var checked = $( this ).prop( 'checked' ), |
| 53 | type = $( this ).closest( '.button-setting-wrap' ).attr( 'id' ), |
| 54 | placement = $( this ).attr( 'class' ); |
| 55 | |
| 56 | self.updateList( type, checked, placement ); |
| 57 | } |
| 58 | ); |
| 59 | }, |
| 60 | |
| 61 | /** |
| 62 | * Add / remove post to list. |
| 63 | * |
| 64 | * @param type |
| 65 | * @param checked |
| 66 | * @param placement |
| 67 | */ |
| 68 | updateList: function( type, checked, placement ) { |
| 69 | |
| 70 | // Update specifide list per checked. |
| 71 | wp.ajax.post( |
| 72 | 'follow_update_list', |
| 73 | { |
| 74 | postid: this.data.postid, |
| 75 | type: type, |
| 76 | checked: checked, |
| 77 | placement: placement, |
| 78 | nonce: this.data.nonce |
| 79 | } |
| 80 | ).always( |
| 81 | function() { |
| 82 | } |
| 83 | ); |
| 84 | } |
| 85 | }; |
| 86 | } )( window.jQuery, window.wp ); |
| 87 |