css-editor.js
| 1 | /* global postboxes, addLoadEvent */ |
| 2 | |
| 3 | ( function( $ ) { |
| 4 | var safe, win, safecssResize, safecssInit; |
| 5 | |
| 6 | safecssResize = function() { |
| 7 | safe.height( win.height() - safe.offset().top - 250 ); |
| 8 | }; |
| 9 | |
| 10 | safecssInit = function() { |
| 11 | safe = $( '#safecss' ); |
| 12 | win = $( window ); |
| 13 | |
| 14 | postboxes.add_postbox_toggles( 'editcss' ); |
| 15 | safecssResize(); |
| 16 | |
| 17 | // Bound on a parent to ensure that this click event executes last. |
| 18 | $( '#safecssform' ).on( 'click', '#preview', function( e ) { |
| 19 | e.preventDefault(); |
| 20 | |
| 21 | document.forms.safecssform.target = 'csspreview'; |
| 22 | document.forms.safecssform.action.value = 'preview'; |
| 23 | document.forms.safecssform.submit(); |
| 24 | document.forms.safecssform.target = ''; |
| 25 | document.forms.safecssform.action.value = 'save'; |
| 26 | } ); |
| 27 | }; |
| 28 | |
| 29 | window.onresize = safecssResize; |
| 30 | addLoadEvent( safecssInit ); |
| 31 | } )( jQuery ); |
| 32 | |
| 33 | jQuery( function( $ ) { |
| 34 | $( '.edit-preprocessor' ).bind( 'click', function( e ) { |
| 35 | e.preventDefault(); |
| 36 | |
| 37 | $( '#preprocessor-select' ).slideDown(); |
| 38 | $( this ).hide(); |
| 39 | } ); |
| 40 | |
| 41 | $( '.cancel-preprocessor' ).bind( 'click', function( e ) { |
| 42 | e.preventDefault(); |
| 43 | |
| 44 | $( '#preprocessor-select' ).slideUp( function() { |
| 45 | $( '.edit-preprocessor' ).show(); |
| 46 | $( '#preprocessor_choices' ).val( $( '#custom_css_preprocessor' ).val() ); |
| 47 | } ); |
| 48 | } ); |
| 49 | |
| 50 | $( '.save-preprocessor' ).bind( 'click', function( e ) { |
| 51 | e.preventDefault(); |
| 52 | |
| 53 | $( '#preprocessor-select' ).slideUp(); |
| 54 | $( '#preprocessor-display' ).text( $( '#preprocessor_choices option:selected' ).text() ); |
| 55 | $( '#custom_css_preprocessor' ) |
| 56 | .val( $( '#preprocessor_choices' ).val() ) |
| 57 | .change(); |
| 58 | $( '.edit-preprocessor' ).show(); |
| 59 | } ); |
| 60 | |
| 61 | $( '.edit-css-mode' ).bind( 'click', function( e ) { |
| 62 | e.preventDefault(); |
| 63 | |
| 64 | $( '#css-mode-select' ).slideDown(); |
| 65 | $( this ).hide(); |
| 66 | } ); |
| 67 | |
| 68 | $( '.cancel-css-mode' ).bind( 'click', function( e ) { |
| 69 | e.preventDefault(); |
| 70 | |
| 71 | $( '#css-mode-select' ).slideUp( function() { |
| 72 | $( '.edit-css-mode' ).show(); |
| 73 | $( 'input[name=add_to_existing_display][value=' + $( '#add_to_existing' ).val() + ']' ).attr( |
| 74 | 'checked', |
| 75 | true |
| 76 | ); |
| 77 | } ); |
| 78 | } ); |
| 79 | |
| 80 | $( '.save-css-mode' ).bind( 'click', function( e ) { |
| 81 | e.preventDefault(); |
| 82 | |
| 83 | $( '#css-mode-select' ).slideUp(); |
| 84 | $( '#css-mode-display' ).text( |
| 85 | $( 'input[name=add_to_existing_display]:checked' ).val() === 'true' ? 'Add-on' : 'Replacement' |
| 86 | ); |
| 87 | $( '#add_to_existing' ).val( $( 'input[name=add_to_existing_display]:checked' ).val() ); |
| 88 | $( '.edit-css-mode' ).show(); |
| 89 | } ); |
| 90 | } ); |
| 91 |