import * as $ from "jquery" ; const selectors = [ ] ; let check_binded = false ; let check_lock = false ; const defaults = { interval : 250 , force_process : false , } ; const $window = $ ( window ) ; const $prior_appeared = [ ] ; function process ( ) { check_lock = false ; for ( let index = 0 , selectorsLength = selectors . length ; index < selectorsLength ; index ++ ) { const $appeared = $ ( selectors [ index ] ) . filter ( function ( ) { return $ ( this ) . is ( ":appeared" ) ; } ) ; $appeared . trigger ( "appear" , [ $appeared ] ) ; if ( $prior_appeared [ index ] ) { const $disappeared = $prior_appeared [ index ] . not ( $appeared ) ; $disappeared . trigger ( "disappear" , [ $disappeared ] ) ; } $prior_appeared [ index ] = $appeared ; } } function add_selector ( selector ) { selectors . push ( selector ) ; $prior_appeared . push ( ) ; } ( < any > $ ) . expr [ ":" ] . appeared = function ( element ) { const $element = $ ( element ) ; if ( ! $element . is ( ":visible" ) ) { return false ; } const window_left = $window . scrollLeft ( ) ; const window_top = $window . scrollTop ( ) ; const offset = $element . offset ( ) ; const left = offset . left ; const top = offset . top ; if ( top + $element . height ( ) >= window_top && top - ( $element . data ( "appear-top-offset" ) || 0 ) <= window_top + $window . height ( ) && left + $element . width ( ) >= window_left && left - ( $element . data ( "appear-left-offset" ) || 0 ) <= window_left + $window . width ( ) ) { return true ; } else { return false ; } } ; $ . fn . extend ( { appear ( options ) { const opts = $ . extend ( { } , defaults , options || { } ) ; const selector = this . selector || this ; if ( ! check_binded ) { const on_check = function ( ) { if ( check_lock ) { return ; } check_lock = true ; setTimeout ( process , opts . interval ) ; } ; $ ( window ) . scroll ( on_check ) . resize ( on_check ) ; check_binded = true ; } if ( opts . force_process ) { setTimeout ( process , opts . interval ) ; } add_selector ( selector ) ; return $ ( selector ) ; } , } ) ; $ . extend ( $ , { force_appear ( ) { if ( check_binded ) { process ( ) ; return true ; } return false ; } , } ) ; export default $ ;