// source --> https://justact.org.au/wp-content/plugins/speakout/js/public.js?ver=4.6.5.1 
jQuery( document ).ready( function( $ ) {
	'use strict';

	// display required asterisks
	$( '.dk-speakout-petition label.required' ).append( '<span> *</span>');

/*
-------------------------------
	Form submission
-------------------------------
*/
	$( '.dk-speakout-submit' ).click( function( e ) {
		e.preventDefault();
		var id             = $( this ).attr( 'name' ),
			lang           = $( '#dk-speakout-lang-' + id ).val(),
			honorific      = $( '#dk-speakout-honorific-' + id ).val(),
			firstname      = $( '#dk-speakout-first-name-' + id ).val(),
			lastname       = $( '#dk-speakout-last-name-' + id ).val(),
			email          = $( '#dk-speakout-email-' + id ).val(),
			street         = $( '#dk-speakout-street-' + id ).val(),
			city           = $( '#dk-speakout-city-' + id ).val(),
			state          = $( '#dk-speakout-state-' + id ).val(),
			postcode       = $( '#dk-speakout-postcode-' + id ).val(),
			country        = $( '#dk-speakout-country-' + id ).val(),
			custom_field   = $( '#dk-speakout-custom-field-' + id ).val(),
            custom_field2   = $( '#dk-speakout-custom-field2-' + id ).val(),
            custom_field3   = $( '#dk-speakout-custom-field3-' + id ).val(),
            custom_field4   = $( '#dk-speakout-custom-field4-' + id ).val(),
            custom_field5   = $( '#dk-speakout-custom-field5-' + id ).val(),
            custom_field6   = $( '#dk-speakout-custom-field6-' + id ).val(),
            custom_field7   = $( '#dk-speakout-custom-field7-' + id ).val(),
			custom_message  = $( '.dk-speakout-message-' + id ).val(),
			optin           = 0,
			bcc             = 0,
            anonymise       = 0,
			privacypolicy   = 0,
			redirect_url    = $( '#dk-speakout-redirect-url-' + id).val(),
            redirect_delay   = $( '#dk-speakout-redirect-delay-' + id).val(),
            url_target       = $( '#dk-speakout-url-target-' + id).val(),
            petition_fade     = $( '#dk-speakout-petition-fade-' + id).val(),
            requires_confirmation = $( '#dk-speakout-requires_confirmation-' + id).val(),
			ajaxloader     = $( '#dk-speakout-ajaxloader-' + id ),
			hide_email_field = $( '#dk-speakout-hide-email-field-' + id ).val();


		// toggle use of .text() / .val() to read from edited textarea properly on Firefox
		if ( $( '#dk-speakout-textval-' + id ).val() === 'text' ) {
			custom_message = $( '.dk-speakout-message-' + id ).text();
		}

		if ( $( '#dk-speakout-optin-' + id ).prop( 'checked' ) ) {
			optin = 1;
		}
		if ( $( '#dk-speakout-bcc-' + id ).prop( 'checked' ) ) {
			bcc = 1;
		}
        if ( $( '#dk-speakout-anonymise-' + id ).prop( 'checked' ) ) {
			anonymise = 1;
		}
        if ( $( '#dk-speakout-privacypolicy-' + id ).prop( 'checked' ) ) {
			privacypolicy = 1;
		}
        if ( $( '#dk-speakout-privacypolicy-' + id ).prop( 'checked' ) ) {
			privacypolicy = 1;
		}       

		// make sure error notices are turned off before checking for new errors
		$( '#dk-speakout-petition-' + id + ' input' ).removeClass( 'dk-speakout-error' );

		// validate form values
		var errors = 0,
		// allow for new gtlds
			emailRegEx = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

	
		// if email is empty or doesn't fit regext and IS being displayed
		if ( ( email === '' || emailRegEx.test( email ) === false ) && hide_email_field == '0'  ) {
			$( '#dk-speakout-email-' + id ).addClass( 'dk-speakout-error' );
			errors ++;
		}
        else{
            $( '#dk-speakout-email-' + id ).removeClass( 'dk-speakout-error' ); 
        }
        
		if ( firstname === '' ) {
			$( '#dk-speakout-first-name-' + id ).addClass( 'dk-speakout-error' );
			errors ++;
		}
        else{
            $( '#dk-speakout-first-name-' + id ).removeClass( 'dk-speakout-error' );
        }
        
		if ( lastname === '' ) {
			$( '#dk-speakout-last-name-' + id ).addClass( 'dk-speakout-error' );
			errors ++;
		}
        else{
        $( '#dk-speakout-last-name-' + id ).removeClass( 'dk-speakout-error' );
        }
		
		if ( $('#dk-speakout-privacypolicy-' + id).length  && privacypolicy === 0 ){
			$( '#dk-speakout-privacypolicy-' + id ).parent().addClass( 'dk-speakout-error' ); 
			errors ++;
		}
        else{
            $( '#dk-speakout-privacypolicy-' + id ).removeClass( 'dk-speakout-error' );
        }
		
		//test for required fields if set
		if ( $('#dk-speakout-custom-field-'+ id).prop('required')  && custom_field === "") {
            $( '#dk-speakout-custom-field-'  + id ).parent().addClass( 'dk-speakout-error' ); 
			errors ++; 
		}
        else{
            $( '#dk-speakout-custom-field-' + id ).removeClass( 'dk-speakout-error' );
        }
        
        if ($('#dk-speakout-custom-field2-'+ id).prop('required')   && custom_field2 === "") {
            $( '#dk-speakout-custom-field2-'  + id ).addClass( 'dk-speakout-error' ); 
			errors ++;
		}
        else{
            $( '#dk-speakout-custom-field2-' + id ).removeClass( 'dk-speakout-error' );
        }
        
        if ($('#dk-speakout-custom-field3-'+ id).prop('required')  && custom_field3 === "") {
            $( '#dk-speakout-custom-field3-'  + id ).addClass( 'dk-speakout-error' ); 
			errors ++;
		}
        else{
            $( '#dk-speakout-custom-field3-' + id ).removeClass( 'dk-speakout-error' );
        }
        
        if ($('#dk-speakout-custom-field4-'+ id).prop('required')  && custom_field4 === "") {
            $( '#dk-speakout-custom-field4-'  + id ).addClass( 'dk-speakout-error' ); 
			errors ++;
		}
        else{
            $( '#dk-speakout-custom-field4-' + id ).removeClass( 'dk-speakout-error' );
        }
        
        if ($('#dk-speakout-custom-field5-'+ id).prop('required')  && custom_field5 === "") {
            $( '#dk-speakout-custom-field5-'  + id ).addClass( 'dk-speakout-error' ); 
			errors ++;
		}
        else{
            $( '#dk-speakout-custom-field5-' + id ).removeClass( 'dk-speakout-error' );
        }
        
        if ($('#dk-speakout-custom-field6-'+ id).prop('required')  && custom_field6 === "") {
            $( '#dk-speakout-custom-field6-'  + id ).addClass( 'dk-speakout-error' ); 
			errors ++;
		}
        else{
            $( '#dk-speakout-custom-field6-' + id ).removeClass( 'dk-speakout-error' );
        }
        
        if ($('#dk-speakout-custom-field7-'+ id).prop('required')  && custom_field7 === "") {
            $( '#dk-speakout-custom-field7-'  + id ).addClass( 'dk-speakout-error' ); 
			errors ++;
		}
        else{
            $( '#dk-speakout-custom-field7-' + id ).removeClass( 'dk-speakout-error' );
        }
        
		if (document.getElementById('dk-speakout-street-' + id) && $( '#dk-speakout-street-'  + id ).prop('required') && street === "") {
            $( '#dk-speakout-street-'  + id ).addClass( 'dk-speakout-error' ); 
			errors ++;
		}
        else{
            $( '#dk-speakout-street-' + id ).removeClass( 'dk-speakout-error' );
        }
        
        if (document.getElementById('dk-speakout-city-' + id) && $( '#dk-speakout-city-'  + id ).prop('required') && city === "") {
			$( '#dk-speakout-city-'  + id ).addClass( 'dk-speakout-error' ); 
			errors ++;
		}
        else{
            $( '#dk-speakout-city-' + id ).removeClass( 'dk-speakout-error' );
        }
        
		if (document.getElementById('dk-speakout-state-' + id) && $( '#dk-speakout-state-'  + id ).prop('required') && state === "") {
            $( '#dk-speakout-state-'  + id ).addClass( 'dk-speakout-error' ); 
			errors ++;
		}
        else{
            $( '#dk-speakout-state-' + id ).removeClass( 'dk-speakout-error' );
        }
        
		if (document.getElementById('dk-speakout-postcode-' + id) && $( '#dk-speakout-postcode-'  + id ).prop('required') && postcode === "") {
            $( '#dk-speakout-postcode-'  + id ).addClass( 'dk-speakout-error' ); 
			errors ++;
        }
        else{
            $( '#dk-speakout-postcode-' + id ).removeClass( 'dk-speakout-error' );
        }
        
		if (document.getElementById('dk-speakout-country-' + id) && $( '#dk-speakout-country-'  + id ).prop('required') && country === "") {
            $( '#dk-speakout-country-'  + id ).addClass( 'dk-speakout-error' ); 
			errors ++;
        }
        else{
            $( '#dk-speakout-country-' + id ).removeClass( 'dk-speakout-error' );
        }

        // if no errors found, submit the data via ajax
		if ( errors === 0 && $( this ).attr( 'rel' ) !== 'disabled' ) {

			// set rel to disabled as flag to block double clicks
			$( this ).attr( 'rel', 'disabled' );

			var form = $( this ).closest( 'form' );
			var data = {
				action:         'dk_speakout_sendmail',
				security:       form.find( '#security' ).val(),
				id:             id,
				honorific:		honorific,
				first_name:     firstname,
				last_name:      lastname,
				email:          email,
				street:         street,
				city:           city,
				state:          state,
				postcode:       postcode,
				country:        country,
				custom_field:   custom_field,
                custom_field2:   custom_field2,
                custom_field3:   custom_field3,
                custom_field4:   custom_field4,
                custom_field5:   custom_field5,
                custom_field6:   custom_field6,
                custom_field7:   custom_field7,
				custom_message: custom_message,
				optin:          optin,
				bcc:            bcc,
                anonymise:      anonymise,
				privacypolicy:  privacypolicy,
				lang:           lang,
				redirect_url:   redirect_url,
                redirect_delay:  redirect_delay,
                petition_fade:   petition_fade
			};

			// display AJAX loading animation
			ajaxloader.css({ 'visibility' : 'visible'});

			// submit form data and handle ajax response
			$.post( dk_speakout_js.ajaxurl, data,
				function( response ) {
				    var response_class = 'dk-speakout-response-success';
					if ( response.status === 'error' ) {
						response_class = 'dk-speakout-response-error';
					}
					//if successfully signed and there is a redirect URL in the form
					if (response.status !== 'error' && redirect_url > ""){
					   	setTimeout(function () {
							//are we opening in a new window?
					   	    if(url_target == 0){
							   window.location.href = redirect_url;
					   	    }
					   	    else{
								/* //this triggers blockup blockers :P
								var redirectWindow = window.open(redirect_url, '_blank');
								$.ajax({
									type: 'POST',
									url: '/echo/json/',
									success: function (data) {
										redirectWindow.location;
									}
									*/
								window.location.href = redirect_url;
								//});
					   	    }
						}, redirect_delay); //delay redirection by n milliseconds e.g. 5000 = 5 seconds
					}
					if(petition_fade=='enabled'){
					    $( '#dk-speakout-petition-' + id + ' .dk-speakout-petition' ).fadeTo( 400, 0.35 );
					}
					else{
					    $( '#dk-speakout-petition-' + id + ' .dk-speakout-petition' ).hide();
					}
					$( '#dk-speakout-petition-' + id + ' .dk-speakout-response' ).addClass( response_class );
					$( '#dk-speakout-petition-' + id + ' .dk-speakout-response' ).fadeIn().html( response.message );
					ajaxloader.css({ 'visibility' : 'hidden'});
                
                	// advance the total but only if confirmation not required and response status has no error
                    if(requires_confirmation == 0 && response.status !== 'error'){
                        var total = $( '.dk-speakout-signature-count span' )[0].textContent;
                        $( '.dk-speakout-signature-count span' )[0].textContent = Number(total.replaceAll(',', ''))+1;
                        $( '.dk-speakout-signature-count span' ).effect( 'highlight', {color:'#FFFF00'}, 3000 );
                    }
				}, 'json'
			);
		}

	});

	// launch Facebook sharing window
	$( '.dk-speakout-facebook' ).click( function( e ) {
		e.preventDefault();

		var id           = $( this ).attr( 'rel' ),
			posttitle    = $( '#dk-speakout-posttitle-' + id ).val(),
			share_url    = document.URL,
			facebook_url = 'http://www.facebook.com/sharer.php?u=' + share_url + '&amp;t=' + posttitle;

		window.open( facebook_url, 'facebook', 'height=400,width=550,left=100,top=100,resizable=yes,location=no,status=no,toolbar=no' );
	});

	// launch x sharing window
	$( '.dk-speakout-x' ).click( function( e ) {
		e.preventDefault();

		var id          = $( this ).attr( 'rel' ),
			tweet       = $( '#dk-speakout-tweet-' + id ).val(),
			current_url = document.URL,
			share_url   = current_url.split('#')[0],
			x_url = 'http://x.com/share?url=' + share_url + '&text=' + tweet;

	window.open( x_url, 'x', 'height=400,width=550,left=100,top=100,resizable=yes,location=no,status=no,toolbar=no' );
	});

/*
-------------------------------
	Petition reader popup
-------------------------------
 */
	$('a.dk-speakout-readme').click( function( e ) {
		e.preventDefault();

		var id = $( this ).attr( 'rel' ),
			sourceOffset = $(this).offset(),
			sourceTop    = sourceOffset.top - $(window).scrollTop(),
			sourceLeft   = sourceOffset.left - $(window).scrollLeft(),
			screenHeight = $( document ).height(),
			screenWidth  = $( window ).width(),
			windowHeight = $( window ).height(),
			windowWidth  = $( window ).width(),
			readerHeight = 520,
			readerWidth  = 640,
			readerTop    = ( ( windowHeight / 2 ) - ( readerHeight / 2 ) ),
			readerLeft   = ( ( windowWidth / 2 ) - ( readerWidth / 2 ) ),
			petitionText = $( 'div#dk-speakout-message-' + id ).html(),
			reader       = '<div id="dk-speakout-reader"><div id="dk-speakout-reader-close"></div><div id="dk-speakout-reader-content"></div></div>';

		// set this to toggle use of .val() / .text() so that Firefox  will read from editable-message textarea as expected
		$( '#dk-speakout-textval-' + id ).val('text');

		// use textarea for editable petition messages
		if ( petitionText === undefined ) {
			petitionText = $( '#dk-speakout-message-editable-' + id ).html();
		}

		$( '#dk-speakout-windowshade' ).css( {
				'width'  : screenWidth,
				'height' : screenHeight
			});
			$( '#dk-speakout-windowshade' ).fadeTo( 500, 0.8 );

		if ( $( '#dk-speakout-reader' ).length > 0 ) {
			$( '#dk-speakout-reader' ).remove();
		}

		$( 'body' ).append( reader );

		$('#dk-speakout-reader').css({
			position   : 'fixed',
			left       : sourceLeft,
			top        : sourceTop,
			zIndex     : 100002

	});

		$('#dk-speakout-reader').animate({
			width  : readerWidth,
			height : readerHeight,
			top    : readerTop,
			left   : readerLeft
		}, 500, function() {
			$( '#dk-speakout-reader-content' ).html( petitionText );
		});

		/* Close the pop-up petition reader */
		// by clicking windowshade area
		$( '#dk-speakout-windowshade' ).click( function () {
			$( this ).fadeOut( 'slow' );
			// write edited text to form - using .text() because target textarea has display: none
			$( '.dk-speakout-message-' + id ).text( $( '#dk-speakout-reader textarea' ).val() );
			$( '#dk-speakout-reader' ).remove();
		});
		// or by clicking the close button
		$( 'body' ).on( 'click', '#dk-speakout-reader-close', function() {
			$( '#dk-speakout-windowshade' ).fadeOut( 'slow' );
			// write edited text to form - using .text() because target textarea has display: none
			$( '.dk-speakout-message-' + id ).text( $( '#dk-speakout-reader textarea' ).val() );
			$( '#dk-speakout-reader' ).remove();
		});
		// or by pressing ESC
		$( document ).keyup( function( e ) {
			if ( e.keyCode === 27 ) {
				$( '#dk-speakout-windowshade' ).fadeOut( 'slow' );
				// write edited text to form - using .text() because target textarea has display: none
				$( '.dk-speakout-message-' + id ).text( $( '#dk-speakout-reader textarea' ).val() );
				$( '#dk-speakout-reader' ).remove();
			}
		});

	});

/*
	Toggle form labels depending on input field focus
	Leaving this in for now to support older custom themes
	But it will be removed in future updates
 */

	$( '.dk-speakout-petition-wrap input[type=text]' ).focus( function( e ) {
		var label = $( this ).siblings( 'label' );
		if ( $( this ).val() === '' ) {
			$( this ).siblings( 'label' ).addClass( 'dk-speakout-focus' ).removeClass( 'dk-speakout-blur' );
		}
		$( this ).blur( function(){
			if ( this.value === '' ) {
				label.addClass( 'dk-speakout-blur' ).removeClass( 'dk-speakout-focus' );
			}
		}).focus( function() {
			label.addClass( 'dk-speakout-focus' ).removeClass( 'dk-speakout-blur' );
		}).keydown( function( e ) {
			label.addClass( 'dk-speakout-focus' ).removeClass( 'dk-speakout-blur' );
			$( this ).unbind( e );
		});
	});

	// hide labels on filled input fields when page is reloaded
	$( '.dk-speakout-petition-wrap input[type=text]' ).each( function() {
		if ( $( this ).val() !== '' ) {
			$( this ).siblings( 'label' ).addClass( 'dk-speakout-focus' );
		}
	});

});
// source --> https://justact.org.au/wp-content/plugins/bb-sticky-column/js/sticky-column.js?ver=6.9.4 

/**
  stickybits - Stickybits is a lightweight alternative to `position: sticky` polyfills
  @version v3.6.1
  @link https://github.com/dollarshaveclub/stickybits#readme
  @author Jeff Wainwright <yowainwright@gmail.com> (https://jeffry.in)
  @license MIT
**/
(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  typeof define === 'function' && define.amd ? define(factory) :
  (global = global || self, global.stickybits = factory());
}(this, function () { 'use strict';

  /*
    STICKYBITS 💉
    --------
    > a lightweight alternative to `position: sticky` polyfills 🍬
    --------
    - each method is documented above it our view the readme
    - Stickybits does not manage polymorphic functionality (position like properties)
    * polymorphic functionality: (in the context of describing Stickybits)
      means making things like `position: sticky` be loosely supported with position fixed.
      It also means that features like `useStickyClasses` takes on styles like `position: fixed`.
    --------
    defaults 🔌
    --------
    - version = `package.json` version
    - userAgent = viewer browser agent
    - target = DOM element selector
    - noStyles = boolean
    - offset = number
    - parentClass = 'string'
    - scrollEl = window || DOM element selector || DOM element
    - stickyClass = 'string'
    - stuckClass = 'string'
    - useStickyClasses = boolean
    - useFixed = boolean
    - useGetBoundingClientRect = boolean
    - verticalPosition = 'string'
    --------
    props🔌
    --------
    - p = props {object}
    --------
    instance note
    --------
    - stickybits parent methods return this
    - stickybits instance methods return an instance item
    --------
    nomenclature
    --------
    - target => el => e
    - props => o || p
    - instance => item => it
    --------
    methods
    --------
    - .definePosition = defines sticky or fixed
    - .addInstance = an array of objects for each Stickybits Target
    - .getClosestParent = gets the parent for non-window scroll
    - .getTopPosition = gets the element top pixel position from the viewport
    - .computeScrollOffsets = computes scroll position
    - .toggleClasses = older browser toggler
    - .manageState = manages sticky state
    - .removeClass = older browser support class remover
    - .removeInstance = removes an instance
    - .cleanup = removes all Stickybits instances and cleans up dom from stickybits
  */
  var Stickybits =
  /*#__PURE__*/
  function () {
    function Stickybits(target, obj) {
      var o = typeof obj !== 'undefined' ? obj : {};
      this.version = '3.6.1';
      this.userAgent = window.navigator.userAgent || 'no `userAgent` provided by the browser';
      this.props = {
        customStickyChangeNumber: o.customStickyChangeNumber || null,
        noStyles: o.noStyles || false,
        stickyBitStickyOffset: o.stickyBitStickyOffset || 0,
        parentClass: o.parentClass || 'js-stickybit-parent',
        scrollEl: typeof o.scrollEl === 'string' ? document.querySelector(o.scrollEl) : o.scrollEl || window,
        stickyClass: o.stickyClass || 'js-is-sticky',
        stuckClass: o.stuckClass || 'js-is-stuck',
        stickyChangeClass: o.stickyChangeClass || 'js-is-sticky--change',
        useStickyClasses: o.useStickyClasses || false,
        useFixed: o.useFixed || false,
        useGetBoundingClientRect: o.useGetBoundingClientRect || false,
        verticalPosition: o.verticalPosition || 'top'
        /*
          define positionVal
          ----
          -  uses a computed (`.definePosition()`)
          -  defined the position
        */

      };
      this.props.positionVal = this.definePosition() || 'fixed';
      this.instances = [];
      var _this$props = this.props,
          positionVal = _this$props.positionVal,
          verticalPosition = _this$props.verticalPosition,
          noStyles = _this$props.noStyles,
          stickyBitStickyOffset = _this$props.stickyBitStickyOffset,
          useStickyClasses = _this$props.useStickyClasses;
      var verticalPositionStyle = verticalPosition === 'top' && !noStyles ? stickyBitStickyOffset + "px" : '';
      var positionStyle = positionVal !== 'fixed' ? positionVal : '';
      this.els = typeof target === 'string' ? document.querySelectorAll(target) : target;
      if (!('length' in this.els)) this.els = [this.els];

      for (var i = 0; i < this.els.length; i++) {
        var el = this.els[i]; // set vertical position

        el.style[verticalPosition] = verticalPositionStyle;
        el.style.position = positionStyle;

        if (positionVal === 'fixed' || useStickyClasses) {
          var instance = this.addInstance(el, this.props); // instances are an array of objects

          this.instances.push(instance);
        }
      }
    }
    /*
      setStickyPosition ✔️
      --------
      —  most basic thing stickybits does
      => checks to see if position sticky is supported
      => defined the position to be used
      => stickybits works accordingly
    */


    var _proto = Stickybits.prototype;

    _proto.definePosition = function definePosition() {
      var stickyProp;

      if (this.props.useFixed) {
        stickyProp = 'fixed';
      } else {
        var prefix = ['', '-o-', '-webkit-', '-moz-', '-ms-'];
        var test = document.head.style;

        for (var i = 0; i < prefix.length; i += 1) {
          test.position = prefix[i] + "sticky";
        }

        stickyProp = test.position ? test.position : 'fixed';
        test.position = '';
      }

      return stickyProp;
    }
    /*
      addInstance ✔️
      --------
      — manages instances of items
      - takes in an el and props
      - returns an item object
      ---
      - target = el
      - o = {object} = props
        - scrollEl = 'string' | object
        - verticalPosition = number
        - off = boolean
        - parentClass = 'string'
        - stickyClass = 'string'
        - stuckClass = 'string'
      ---
      - defined later
        - parent = dom element
        - state = 'string'
        - offset = number
        - stickyStart = number
        - stickyStop = number
      - returns an instance object
    */
    ;

    _proto.addInstance = function addInstance(el, props) {
      var _this = this;

      var item = {
        el: el,
        parent: el.parentNode,
        props: props
      };
      this.isWin = this.props.scrollEl === window;
      var se = this.isWin ? window : this.getClosestParent(item.el, item.props.scrollEl);
      this.computeScrollOffsets(item);
      item.parent.className += " " + props.parentClass;
      item.state = 'default';

      item.stateContainer = function () {
        return _this.manageState(item);
      };

      se.addEventListener('scroll', item.stateContainer);
      return item;
    }
    /*
      --------
      getParent 👨‍
      --------
      - a helper function that gets the target element's parent selected el
      - only used for non `window` scroll elements
      - supports older browsers
    */
    ;

    _proto.getClosestParent = function getClosestParent(el, match) {
      // p = parent element
      var p = match;
      var e = el;
      if (e.parentElement === p) return p; // traverse up the dom tree until we get to the parent

      while (e.parentElement !== p) {
        e = e.parentElement;
      } // return parent element


      return p;
    }
    /*
      --------
      getTopPosition
      --------
      - a helper function that gets the topPosition of a Stickybit element
      - from the top level of the DOM
    */
    ;

    _proto.getTopPosition = function getTopPosition(el) {
      if (this.props.useGetBoundingClientRect) {
        return el.getBoundingClientRect().top + (this.props.scrollEl.pageYOffset || document.documentElement.scrollTop);
      }

      var topPosition = 0;

      do {
        topPosition = el.offsetTop + topPosition;
      } while (el = el.offsetParent);

      return topPosition;
    }
    /*
      computeScrollOffsets 📊
      ---
      computeScrollOffsets for Stickybits
      - defines
        - offset
        - start
        - stop
    */
    ;

    _proto.computeScrollOffsets = function computeScrollOffsets(item) {
      var it = item;
      var p = it.props;
      var el = it.el;
      var parent = it.parent;
      var isCustom = !this.isWin && p.positionVal === 'fixed';
      var isTop = p.verticalPosition !== 'bottom';
      var scrollElOffset = isCustom ? this.getTopPosition(p.scrollEl) : 0;
      var stickyStart = isCustom ? this.getTopPosition(parent) - scrollElOffset : this.getTopPosition(parent);
      var stickyChangeOffset = p.customStickyChangeNumber !== null ? p.customStickyChangeNumber : el.offsetHeight;
      var parentBottom = stickyStart + parent.offsetHeight;
      it.offset = scrollElOffset + p.stickyBitStickyOffset;
      it.stickyStart = isTop ? stickyStart - it.offset : 0;
      it.stickyChange = it.stickyStart + stickyChangeOffset;
      it.stickyStop = isTop ? parentBottom - (el.offsetHeight + it.offset) : parentBottom - window.innerHeight;
      return it;
    }
    /*
      toggleClasses ⚖️
      ---
      toggles classes (for older browser support)
      r = removed class
      a = added class
    */
    ;

    _proto.toggleClasses = function toggleClasses(el, r, a) {
      var e = el;
      var cArray = e.className.split(' ');
      if (a && cArray.indexOf(a) === -1) cArray.push(a);
      var rItem = cArray.indexOf(r);
      if (rItem !== -1) cArray.splice(rItem, 1);
      e.className = cArray.join(' ');
    }
    /*
      manageState 📝
      ---
      - defines the state
        - normal
        - sticky
        - stuck
    */
    ;

    _proto.manageState = function manageState(item) {
      // cache object
      var it = item;
      var e = it.el;
      var p = it.props;
      var state = it.state;
      var start = it.stickyStart;
      var change = it.stickyChange;
      var stop = it.stickyStop;
      var stl = e.style; // cache props

      var ns = p.noStyles;
      var pv = p.positionVal;
      var se = p.scrollEl;
      var sticky = p.stickyClass;
      var stickyChange = p.stickyChangeClass;
      var stuck = p.stuckClass;
      var vp = p.verticalPosition;
      var isTop = vp !== 'bottom';
      /*
        requestAnimationFrame
        ---
        - use rAF
        - or stub rAF
      */

      var rAFStub = function rAFDummy(f) {
        f();
      };

      var rAF = !this.isWin ? rAFStub : window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || rAFStub;
      /*
        define scroll vars
        ---
        - scroll
        - notSticky
        - isSticky
        - isStuck
      */

      var tC = this.toggleClasses;
      var scroll = this.isWin ? window.scrollY || window.pageYOffset : se.scrollTop;
      var notSticky = scroll > start && scroll < stop && (state === 'default' || state === 'stuck');
      var isSticky = isTop && scroll <= start && (state === 'sticky' || state === 'stuck');
      var isStuck = scroll >= stop && state === 'sticky';
      /*
        Unnamed arrow functions within this block
        ---
        - help wanted or discussion
        - view test.stickybits.js
          - `stickybits .manageState  `position: fixed` interface` for more awareness 👀
      */

      if (notSticky) {
        it.state = 'sticky';
        rAF(function () {
          tC(e, stuck, sticky);
          stl.position = pv;
          if (ns) return;
          stl.bottom = '';
          stl[vp] = p.stickyBitStickyOffset + "px";
        });
      } else if (isSticky) {
        it.state = 'default';
        rAF(function () {
          tC(e, sticky);
          tC(e, stuck);
          if (pv === 'fixed') stl.position = '';
        });
      } else if (isStuck) {
        it.state = 'stuck';
        rAF(function () {
          tC(e, sticky, stuck);
          if (pv !== 'fixed' || ns) return;
          stl.top = '';
          stl.bottom = '0';
          stl.position = 'absolute';
        });
      }

      var isStickyChange = scroll >= change && scroll <= stop;
      var isNotStickyChange = scroll < change / 2 || scroll > stop;
      var stub = 'stub'; // a stub css class to remove

      if (isNotStickyChange) {
        rAF(function () {
          tC(e, stickyChange);
        });
      } else if (isStickyChange) {
        rAF(function () {
          tC(e, stub, stickyChange);
        });
      }

      return it;
    };

    _proto.update = function update(updatedProps) {
      if (updatedProps === void 0) {
        updatedProps = null;
      }

      for (var i = 0; i < this.instances.length; i += 1) {
        var instance = this.instances[i];
        this.computeScrollOffsets(instance);

        if (updatedProps) {
          for (var updatedProp in updatedProps) {
            instance.props[updatedProp] = updatedProps[updatedProp];
          }
        }
      }

      return this;
    }
    /*
      removes an instance 👋
      --------
      - cleanup instance
    */
    ;

    _proto.removeInstance = function removeInstance(instance) {
      var e = instance.el;
      var p = instance.props;
      var tC = this.toggleClasses;
      e.style.position = '';
      e.style[p.verticalPosition] = '';
      tC(e, p.stickyClass);
      tC(e, p.stuckClass);
      tC(e.parentNode, p.parentClass);
    }
    /*
      cleanup 🛁
      --------
      - cleans up each instance
      - clears instance
    */
    ;

    _proto.cleanup = function cleanup() {
      for (var i = 0; i < this.instances.length; i += 1) {
        var instance = this.instances[i];
        instance.props.scrollEl.removeEventListener('scroll', instance.stateContainer);
        this.removeInstance(instance);
      }

      this.manageState = false;
      this.instances = [];
    };

    return Stickybits;
  }();
  /*
    export
    --------
    exports StickBits to be used 🏁
  */


  function stickybits(target, o) {
    return new Stickybits(target, o);
  }

  return stickybits;

}));


jQuery(function() {

  var stickybit = [];
  //dont enable when page builder is active, and check that there is a data-sticky attribute
  if(!jQuery('body').hasClass('fl-builder-edit') && jQuery("[bt-sticky='true']").length)
  {
    var stickyItems = jQuery("[bt-sticky='true']");

    if(stickyItems.length !== 0){
      //check for overflow visible on all parents and fix
      jQuery('[bt-sticky]').parents().each(function(){
        if(jQuery(this).css("overflow") != "visible")
        {
          console.log("Sticky Column Notice: CSS Sticky position requires all parent elements to have overflow:visible. We detected one below that does not have that setting. Not to worry, we have updated them automatically.");
          console.log(jQuery(this));
          console.log("overflow: " + jQuery(this).css('overflow') + ", changed to...  overflow:visible");
          jQuery(this).css("overflow","visible");
        }
      });

      stickyItems.each(function(index, item){
        
        // get the offset
        var topPadding = parseInt(jQuery(item).attr('bt-sticky-top-margin'));
        var stickyItem = jQuery(item);
        
        //target the parent if its a nested col, then we target the parent
        if(stickyItem.parent().hasClass('fl-col-group-nested'))
          stickyItem = stickyItem.parent();

        stickybit[jQuery(item).attr('data-node')] = stickybits(stickyItem,{
          stickyBitStickyOffset: topPadding,
          useStickyClasses: true,
          stickyClass: 'bt-sticking',
          stuckClass: 'bt-stuck',
        });
      });
    }
  }
});