Skip to content
This repository
Browse code

Added metabox.js

  • Loading branch information...
commit d6413344ce2686de120b2482c0d6c497490b39c2 1 parent f5469ae
Michael Sisk authored

Showing 1 changed file with 70 additions and 0 deletions. Show diff stats Hide diff stats

  1. +70 0 webcomic-includes/metabox.js
70 webcomic-includes/metabox.js
... ... @@ -0,0 +1,70 @@
  1 +<script type="text/javascript">
  2 +jQuery( document ).ready( function( $ ) {
  3 + // Enable file uploads during post publish/save.
  4 + $( 'form#post' ).attr( 'enctype', 'multipart/form-data' ).attr( 'encoding', 'multipart/form-data' );
  5 +
  6 + // Enable dynamic character/storyline loading.
  7 + $( 'select#webcomic_collection' ).change( function() {
  8 + $( 'input[name=webcomic_ajax]' ).val( 'collection' );
  9 +
  10 + var params = $( 'form' ).serialize();
  11 +
  12 + $( '#webcomic_terms' ).load( '<?php echo $_SERVER[ 'PHP_SELF' ]; ?>', params );
  13 + $( 'input[name=webcomic_ajax]' ).val( 'orphans' );
  14 +
  15 + var params = $( 'form' ).serialize();
  16 +
  17 + $( '#webcomic_orphans' ).load( '<?php echo $_SERVER[ 'PHP_SELF' ]; ?>', params );
  18 + $( 'input[name="webcomic_ajax"]' ).val(0);
  19 + } ).change();
  20 +
  21 + // Enable multiple individual file uploads.
  22 + $( '#add_webcomic_file' ).click( function() {
  23 + $( '#webcomic_files' ).append( '<br><input type="file" name="webcomic_file[]">' );
  24 + } );
  25 +
  26 + // Enable multiple transcript languages.
  27 + $( '#webcomic_transcript_language' ).change( function() {
  28 + var x=$(this).val();
  29 + $('[id*="webcomic_lang_"]').hide();
  30 + $('[id*="[webcomic_lang_'+x+']"]').show();
  31 + } ).change();
  32 +} );
  33 +
  34 +// Paypal price function.
  35 +jQuery('select[name*=webcomic_paypal],input[name*=webcomic_paypal]').change(function(){
  36 + var i,x,p,m,f,a,t,s,c,cost_d,cost_i,cost_o,ship_d,ship_i,ship_o,currency;
  37 +
  38 + i = jQuery( this ) . attr( 'name' ) . lastIndexOf( '_price' );
  39 + cost_d = <?php echo $this->price( $this->option( 'paypal_price_d' ), array( $wc->webcomic_paypal[ 'price_d' ], $price_d ) ); ?>;
  40 + cost_i = <?php echo $this->price( $this->option( 'paypal_price_i' ), array( $wc->webcomic_paypal[ 'price_i' ], $price_i ) ); ?>;
  41 + cost_o = <?php echo $this->price( $this->option( 'paypal_price_o' ), array( $wc->webcomic_paypal[ 'price_o' ], $price_o ) ); ?>;
  42 + ship_d = <?php echo $this->price( $this->option( 'paypal_shipping_d' ), array( $wc->webcomic_paypal[ 'shipping_d' ], $shipping_d ) ); ?>;
  43 + ship_i = <?php echo $this->price( $this->option( 'paypal_shipping_i' ), array( $wc->webcomic_paypal[ 'shipping_i' ], $shipping_i ) ); ?>;
  44 + ship_o = <?php echo $this->price( $this->option( 'paypal_shipping_o' ), array( $wc->webcomic_paypal[ 'shipping_o' ], $shipping_o ) ); ?>;
  45 + currency = ' <?php echo $this->option( 'paypal_currency' ); ?>';
  46 +
  47 + if ( 0 < jQuery(this).attr('name').lastIndexOf('_d') ) {
  48 + x = 'd';
  49 + c = cost_d;
  50 + s = ship_d;
  51 + } else if ( 0 < jQuery( this ).attr( 'name' ).lastIndexOf( '_i' ) ) {
  52 + x = 'i';
  53 + c = cost_i;
  54 + s = ship_i;
  55 + } else {
  56 + x = 'o';
  57 + c = cost_o;
  58 + s = ship_o;
  59 + }
  60 +
  61 + a = ( i > 0 ) ? 'webcomic_paypal_price_' + x : 'webcomic_paypal_shipping_' + x;
  62 + t = ( i > 0 ) ? 'webcomic_paypal_price_type_' + x : 'webcomic_paypal_shipping_type_' + x;
  63 + p = ( i > 0 ) ? c : s;
  64 + m = p * ( Math.abs( jQuery( 'input[name=' + a + ']' ).val() ) / 100 );
  65 + f = ( 'sub' == jQuery( 'select[name=' + t + ']' ).val() ) ? p - m : p + m;
  66 + f = ( f <= .01 ) ? '<span class="error">!</span>' : f.toFixed( 2 ) + currency;
  67 +
  68 + jQuery( '.' + a ).html( f );
  69 +} );
  70 +</script>

0 comments on commit d641334

Please sign in to comment.
Something went wrong with that request. Please try again.