| 1857 | initDropzone: function() { |
| 1858 | if ( ! this.frame ) { |
| 1859 | this.initFrame(); |
| 1860 | } |
| 1861 | |
| 1862 | if ( ! this.frame.options.uploader ) { |
| 1863 | return; |
| 1864 | } |
| 1865 | |
| 1866 | var uploaderOptions, postID, self = this, |
| 1867 | $browser = $( '<a href="#" class="browser" />' ).hide().appendTo( 'body' ), |
| 1868 | dropzone = this.container.find( '.placeholder' ); |
| 1869 | |
| 1870 | if ( 0 === dropzone.length ) { |
| 1871 | // There is currently no placeholder, so there will be no dropzone. |
| 1872 | $browser.remove(); |
| 1873 | return; |
| 1874 | } |
| 1875 | |
| 1876 | uploaderOptions = _.defaults( this.frame.options.uploader || {}, { |
| 1877 | dropzone: dropzone, |
| 1878 | browser: $browser, |
| 1879 | params: {} |
| 1880 | }); |
| 1881 | |
| 1882 | postId = wp.media.view.settings.post.id; |
| 1883 | if ( postId ) { |
| 1884 | uploader.params.post_id = postId; |
| 1885 | } |
| 1886 | this.dropzoneUploader = new wp.Uploader( uploaderOptions ); // @todo figure out how wp.Uploader works (this currently doesn't work beyond here) |
| 1887 | |
| 1888 | dropzone.on( 'dropzone:enter', _.bind( function() { |
| 1889 | self.container.addClass( 'dropping' ); |
| 1890 | }, this ) ); |
| 1891 | dropzone.on( 'dropzone:leave', _.bind( function() { |
| 1892 | self.container.removeClass( 'dropping' ); |
| 1893 | }, this ) ); |
| 1894 | |
| 1895 | }, |
| 1896 | |
| 3672 | // Keyboard shortcuts - esc to exit section/panel. |
| 3673 | $( 'body' ).on( 'keydown', function( event ) { |
| 3674 | |
| 3675 | if ( 27 !== event.which ) { // esc |
| 3676 | return; |
| 3677 | } |
| 3678 | |
| 3679 | var foundExpandedContainer = false; |
| 3680 | |
| 3681 | // Check for expanded sections, return when/if found. |
| 3682 | api.section.each( function ( section ) { |
| 3683 | if ( section.expanded() ) { |
| 3684 | section.collapse(); |
| 3685 | event.preventDefault(); |
| 3686 | foundExpandedContainer = true; |
| 3687 | } |
| 3688 | }); |
| 3689 | |
| 3690 | if ( foundExpandedContainer ) { |
| 3691 | return; |
| 3692 | } |
| 3693 | |
| 3694 | // Check for expanded panels, return when/if found. |
| 3695 | api.panel.each( function ( panel ) { |
| 3696 | if ( panel.expanded() ) { |
| 3697 | panel.collapse(); |
| 3698 | event.preventDefault(); |
| 3699 | foundExpandedContainer = true; |
| 3700 | } |
| 3701 | }); |
| 3702 | |
| 3703 | if ( foundExpandedContainer ) { |
| 3704 | return; |
| 3705 | } |
| 3706 | |
| 3707 | // Otherwise, we're at the root level, so do nothing. |
| 3708 | }); |
| 3709 | |