1+ /*
2+ * This file is part of rekalogika/temporary-url-bundle package.
3+ *
4+ * (c) Priyadi Iman Nurcahyo <https://rekalogika.dev>
5+ *
6+ * For the full copyright and license information, please view the LICENSE file
7+ * that was distributed with this source code.
8+ */
9+
110'use strict' ;
211
3- import { Controller } from '@hotwired/stimulus' ;
4- export default class extends Controller {
5- connect ( ) {
6- let element = this . element ;
7- let href = element . getAttribute ( 'href' ) ;
8- if ( ! href ) {
9- return ;
10- }
11- let url = new URL ( href , 'http://example.com/' ) ;
12- if ( ! url ) {
13- return ;
14- }
15- let expiration = parseInt ( url . searchParams . get ( 'expiration' ) ) ;
16- let secondsToExpiration = 1800 ;
17- if ( expiration ) {
18- let now = new Date ( ) . getTime ( ) / 1000 ;
19- secondsToExpiration = expiration - now ;
20- }
21- if ( secondsToExpiration < 0 ) {
22- secondsToExpiration = 1 ;
23- }
24- setTimeout ( function ( ) {
25- element . classList . add ( 'disabled' ) ;
26- element . setAttribute ( 'disabled' , 'disabled' ) ;
27- element . setAttribute ( 'tabindex' , '-1' ) ;
28- element . setAttribute ( 'aria-disabled' , 'true' ) ;
29- element . setAttribute ( 'title' , 'This link has expired. Please refresh the page, and try again.' ) ;
30- element . href = '#' ;
31- } , secondsToExpiration * 1000 ) ;
12+ function _typeof ( o ) { "@babel/helpers - typeof" ; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol . iterator ? function ( o ) { return typeof o ; } : function ( o ) { return o && "function" == typeof Symbol && o . constructor === Symbol && o !== Symbol . prototype ? "symbol" : typeof o ; } , _typeof ( o ) ; }
13+ Object . defineProperty ( exports , "__esModule" , {
14+ value : true
15+ } ) ;
16+ exports [ "default" ] = void 0 ;
17+ var _stimulus = require ( "@hotwired/stimulus" ) ;
18+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
19+ function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , _toPropertyKey ( descriptor . key ) , descriptor ) ; } }
20+ function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; Object . defineProperty ( Constructor , "prototype" , { writable : false } ) ; return Constructor ; }
21+ function _toPropertyKey ( arg ) { var key = _toPrimitive ( arg , "string" ) ; return _typeof ( key ) === "symbol" ? key : String ( key ) ; }
22+ function _toPrimitive ( input , hint ) { if ( _typeof ( input ) !== "object" || input === null ) return input ; var prim = input [ Symbol . toPrimitive ] ; if ( prim !== undefined ) { var res = prim . call ( input , hint || "default" ) ; if ( _typeof ( res ) !== "object" ) return res ; throw new TypeError ( "@@toPrimitive must return a primitive value." ) ; } return ( hint === "string" ? String : Number ) ( input ) ; }
23+ function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function" ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , writable : true , configurable : true } } ) ; Object . defineProperty ( subClass , "prototype" , { writable : false } ) ; if ( superClass ) _setPrototypeOf ( subClass , superClass ) ; }
24+ function _setPrototypeOf ( o , p ) { _setPrototypeOf = Object . setPrototypeOf ? Object . setPrototypeOf . bind ( ) : function _setPrototypeOf ( o , p ) { o . __proto__ = p ; return o ; } ; return _setPrototypeOf ( o , p ) ; }
25+ function _createSuper ( Derived ) { var hasNativeReflectConstruct = _isNativeReflectConstruct ( ) ; return function _createSuperInternal ( ) { var Super = _getPrototypeOf ( Derived ) , result ; if ( hasNativeReflectConstruct ) { var NewTarget = _getPrototypeOf ( this ) . constructor ; result = Reflect . construct ( Super , arguments , NewTarget ) ; } else { result = Super . apply ( this , arguments ) ; } return _possibleConstructorReturn ( this , result ) ; } ; }
26+ function _possibleConstructorReturn ( self , call ) { if ( call && ( _typeof ( call ) === "object" || typeof call === "function" ) ) { return call ; } else if ( call !== void 0 ) { throw new TypeError ( "Derived constructors may only return object or undefined" ) ; } return _assertThisInitialized ( self ) ; }
27+ function _assertThisInitialized ( self ) { if ( self === void 0 ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return self ; }
28+ function _isNativeReflectConstruct ( ) { if ( typeof Reflect === "undefined" || ! Reflect . construct ) return false ; if ( Reflect . construct . sham ) return false ; if ( typeof Proxy === "function" ) return true ; try { Boolean . prototype . valueOf . call ( Reflect . construct ( Boolean , [ ] , function ( ) { } ) ) ; return true ; } catch ( e ) { return false ; } }
29+ function _getPrototypeOf ( o ) { _getPrototypeOf = Object . setPrototypeOf ? Object . getPrototypeOf . bind ( ) : function _getPrototypeOf ( o ) { return o . __proto__ || Object . getPrototypeOf ( o ) ; } ; return _getPrototypeOf ( o ) ; }
30+ var _default = exports [ "default" ] = /*#__PURE__*/ function ( _Controller ) {
31+ _inherits ( _default , _Controller ) ;
32+ var _super = _createSuper ( _default ) ;
33+ function _default ( ) {
34+ _classCallCheck ( this , _default ) ;
35+ return _super . apply ( this , arguments ) ;
3236 }
33- }
37+ _createClass ( _default , [ {
38+ key : "connect" ,
39+ value : function connect ( ) {
40+ var element = this . element ;
41+ var href = element . getAttribute ( 'href' ) ;
42+ if ( ! href ) {
43+ return ;
44+ }
45+ var url = new URL ( href , 'http://example.com/' ) ;
46+ if ( ! url ) {
47+ return ;
48+ }
49+ var expiration = parseInt ( url . searchParams . get ( 'expiration' ) ) ;
50+ var secondsToExpiration = 1800 ;
51+ if ( expiration ) {
52+ var now = new Date ( ) . getTime ( ) / 1000 ;
53+ secondsToExpiration = expiration - now ;
54+ }
55+ if ( secondsToExpiration < 0 ) {
56+ secondsToExpiration = 1 ;
57+ }
58+ setTimeout ( function ( ) {
59+ element . classList . add ( 'disabled' ) ;
60+ element . setAttribute ( 'disabled' , 'disabled' ) ;
61+ element . setAttribute ( 'tabindex' , '-1' ) ;
62+ element . setAttribute ( 'aria-disabled' , 'true' ) ;
63+ element . setAttribute ( 'title' , 'This link has expired. Please refresh the page, and try again.' ) ;
64+ element . href = '#' ;
65+ } , secondsToExpiration * 1000 ) ;
66+ }
67+ } ] ) ;
68+ return _default ;
69+ } ( _stimulus . Controller ) ;
0 commit comments