[2420] | 1 | ( function( ) |
---|
| 2 | { |
---|
[2732] | 3 | var _connector = new XConnector; |
---|
[2703] | 4 | var _script = new XScript; |
---|
[2802] | 5 | var _location = window.location; |
---|
[2628] | 6 | |
---|
[2732] | 7 | function Link( ) |
---|
| 8 | { |
---|
| 9 | var _path = ( arguments.length && arguments[ 0 ].constructor == String ) ? arguments[ 0 ] : '/'; |
---|
[2802] | 10 | |
---|
[2875] | 11 | _path = ( |
---|
| 12 | ( ( _path.indexOf( _location.protocol ) != 0 ) ? _location.protocol + '//' : '' ) |
---|
| 13 | + ( ( _path.indexOf( _location.host ) != 0 ) ? _location.host : '' ) |
---|
| 14 | + ( ( _path.indexOf( '/' ) != 0 ) ? '/' : '' ) |
---|
| 15 | ) + _path; |
---|
| 16 | |
---|
[2732] | 17 | var _last_request = null; |
---|
[2875] | 18 | var _handlers_registred = { |
---|
| 19 | after : null, |
---|
| 20 | before : null, |
---|
| 21 | data : null |
---|
| 22 | }; |
---|
[2469] | 23 | |
---|
[2802] | 24 | if ( _location.protocol + '//' + _location.host + _location.pathname != _path ) |
---|
[2732] | 25 | window.location.href = _path + ( |
---|
[2802] | 26 | ( _location.hash ) ? |
---|
| 27 | _location.hash : '#' + String( _location.protocol + '//' + _location.host + _location.pathname + _location.search ).substr( _path.length ) |
---|
[2732] | 28 | ); |
---|
[2677] | 29 | |
---|
[2732] | 30 | function _click( _action, _cache ) |
---|
| 31 | { |
---|
[2875] | 32 | switch ( _action.indexOf( _location.pathname ) ) |
---|
| 33 | { |
---|
| 34 | case -1 : |
---|
| 35 | _action = _path + ( ( _action.indexOf( '/' ) == 0 ) ? _action.substr( 1 ) : _action ); |
---|
| 36 | break; |
---|
| 37 | case 0 : |
---|
| 38 | _action = _action.replace( _location.pathname, _path ); |
---|
| 39 | break; |
---|
| 40 | default : |
---|
| 41 | if ( _action.indexOf( _path ) != 0 ) |
---|
| 42 | _action = _path + _action; |
---|
| 43 | } |
---|
[2712] | 44 | |
---|
[2732] | 45 | var _post = ( arguments.length == 3 && arguments[ 2 ] && arguments[ 2 ].constructor == String ) ? arguments[ 2 ] : null; |
---|
[2677] | 46 | |
---|
[2732] | 47 | if ( _post == null && _action == _last_request ) |
---|
| 48 | return false; |
---|
[2677] | 49 | |
---|
[2875] | 50 | if ( _handlers_registred.before ) |
---|
| 51 | _handlers_registred.before( ); |
---|
[2677] | 52 | |
---|
[2732] | 53 | _connector.go( |
---|
| 54 | { |
---|
| 55 | 'access' : _action, |
---|
| 56 | 'cache' : _cache, |
---|
[2802] | 57 | 'handler' : _manipulator, |
---|
[2732] | 58 | 'post' : _post |
---|
| 59 | } ); |
---|
| 60 | |
---|
| 61 | _last_request = _action; |
---|
| 62 | |
---|
| 63 | window.location = '#' + ( |
---|
| 64 | ( _action.indexOf( _path ) < 0 ) ? |
---|
| 65 | _action : _action.substr( _action.indexOf( _path ) + _path.length ) |
---|
| 66 | ); |
---|
[2691] | 67 | } |
---|
| 68 | |
---|
[2732] | 69 | function _intercept( pLink ) |
---|
[2677] | 70 | { |
---|
[2732] | 71 | var action = pLink.href; |
---|
| 72 | if ( action == '' ) |
---|
| 73 | return false; |
---|
[2677] | 74 | |
---|
[2732] | 75 | var a = ( action.indexOf( 'javascript:' ) === 0 ); |
---|
| 76 | a = ( a || ( action.indexOf( '#' ) === 0 ) ); |
---|
| 77 | a = ( a || ( action.indexOf( window.location + '#' ) === 0 ) ); |
---|
| 78 | a = ( a || ! ( action.indexOf( 'workflow' ) < 0 ) ); |
---|
[2691] | 79 | |
---|
[2732] | 80 | if ( ! a ) |
---|
| 81 | pLink.onclick = function( ) |
---|
| 82 | { |
---|
| 83 | var _cacheit = false;//( ( pLink.hasAttribute( 'cacheit' ) && pLink.getAttribute( 'cacheit' ) === 'true' ) ? true : false ); |
---|
[2677] | 84 | |
---|
[2732] | 85 | _click( action, _cacheit ); |
---|
[2677] | 86 | |
---|
[2732] | 87 | return false; |
---|
| 88 | }; |
---|
| 89 | } |
---|
[2677] | 90 | |
---|
[2875] | 91 | function _manipulator( _pData ) |
---|
[2732] | 92 | { |
---|
[2875] | 93 | if ( ! ( _pData.constructor == String ) ) |
---|
[2802] | 94 | return false; |
---|
| 95 | |
---|
[2875] | 96 | if ( _handlers_registred.data ) |
---|
| 97 | _pData = _handlers_registred.data( _pData ); |
---|
| 98 | |
---|
[2802] | 99 | var _line_feed = '__LINE_FEED_CHARACTER_' + ( Date.parse( new Date ) ) + '__'; |
---|
| 100 | |
---|
[2875] | 101 | _pData = _pData.trim( ).replace( /[\r\t]/g, '' ).replace( /\n/g, _line_feed ); |
---|
[2802] | 102 | |
---|
| 103 | _line_feed = new RegExp( _line_feed, 'g' ); |
---|
| 104 | |
---|
[2903] | 105 | var _css = _pData.match( new RegExp( '<link type="text\/css" rel="StyleSheet"[^>]*\/>', 'gi' ) ); |
---|
| 106 | if ( _css ) |
---|
| 107 | for ( var i = 0; _css, i < _css.length; i++ ) |
---|
| 108 | { |
---|
| 109 | _pData = _pData.replace( _css[ i ], '' ); |
---|
| 110 | XStyle.add( ( /<[^>]*href="(\S+)"[^>]*\/>/i ).exec( _css[ i ] )[ 1 ] ); |
---|
| 111 | } |
---|
| 112 | |
---|
[2875] | 113 | var _js = _pData.match( new RegExp( '<script[^>]*>.*?<\/script>', 'gi' ) ); |
---|
[2756] | 114 | if ( _js ) |
---|
| 115 | for ( var i = 0; i < _js.length; i++ ) |
---|
[2732] | 116 | { |
---|
[2875] | 117 | _pData = _pData.replace( _js[ i ], '' ); |
---|
[2677] | 118 | |
---|
[2903] | 119 | _js[ i ] = ( /<script([^>]+src=["'](\S+)["'])?[^>]*>(.*?)<\/script>/i ).exec( _js[ i ] ); |
---|
[2756] | 120 | |
---|
[2802] | 121 | var _external = _js[ i ][ 2 ]; |
---|
| 122 | |
---|
| 123 | if ( _external == undefined || _external.length == 0 ) |
---|
| 124 | _script.inline( _js[ i ][ 3 ].replace( _line_feed, '\n' ) ); |
---|
[2732] | 125 | else |
---|
| 126 | { |
---|
[2756] | 127 | if ( _external.indexOf( window.location.host ) < 0 ) |
---|
| 128 | _external = window.location.protocol + '//' + window.location.host + _external; |
---|
| 129 | |
---|
[2732] | 130 | _script.external( |
---|
[2756] | 131 | _external.substr( |
---|
[2732] | 132 | _path.length - 1, |
---|
[2756] | 133 | _external.length - _path.length + 1 - ( |
---|
| 134 | ( _external.indexOf( '?' ) < 0 ) ? |
---|
| 135 | 0 : ( _external.length - _external.indexOf( '?' ) ) |
---|
[2732] | 136 | ) |
---|
| 137 | ) |
---|
| 138 | ); |
---|
| 139 | } |
---|
| 140 | } |
---|
[2656] | 141 | |
---|
[2732] | 142 | var el = document.createElement( 'div' ); |
---|
[2875] | 143 | el.innerHTML = _pData.replace( _line_feed, '' ); |
---|
[2656] | 144 | |
---|
[2732] | 145 | var _links = el.getElementsByTagName( 'a' ); |
---|
| 146 | for ( var i = 0; i < _links.length; i++ ) |
---|
| 147 | _intercept( _links.item( i ) ); |
---|
[2656] | 148 | |
---|
[2875] | 149 | if ( _handlers_registred.after ) |
---|
| 150 | _handlers_registred.after( el ); |
---|
[2656] | 151 | |
---|
[2732] | 152 | _script.load( ); |
---|
| 153 | } |
---|
| 154 | |
---|
[2802] | 155 | function _handler( ) |
---|
[2656] | 156 | { |
---|
[2732] | 157 | if ( arguments.length != 1 ) |
---|
| 158 | return false; |
---|
| 159 | |
---|
| 160 | switch ( arguments[ 0 ].constructor ) |
---|
[2656] | 161 | { |
---|
[2732] | 162 | case Function : |
---|
[2875] | 163 | _handler.after = arguments[ 0 ]; |
---|
[2732] | 164 | break; |
---|
| 165 | case Object : |
---|
[2875] | 166 | if ( arguments[ 0 ].after && arguments[ 0 ].after.constructor == Function ) |
---|
| 167 | _handlers_registred.after = arguments[ 0 ].after; |
---|
[2679] | 168 | |
---|
[2875] | 169 | if ( arguments[ 0 ].before && arguments[ 0 ].before.constructor == Function ) |
---|
| 170 | _handlers_registred.before = arguments[ 0 ].before; |
---|
| 171 | |
---|
| 172 | if ( arguments[ 0 ].data && arguments[ 0 ].data.constructor == Function ) |
---|
| 173 | _handlers_registred.data = arguments[ 0 ].data; |
---|
[2732] | 174 | break; |
---|
| 175 | default : return false; |
---|
[2656] | 176 | } |
---|
| 177 | } |
---|
| 178 | |
---|
[2732] | 179 | this.click = function( ) |
---|
| 180 | { |
---|
| 181 | _click( arguments[ 0 ], |
---|
| 182 | ( |
---|
| 183 | ( arguments.length > 1 && arguments[ 1 ] && arguments[ 1 ].constructor == Boolean ) ? |
---|
| 184 | arguments[ 1 ] : false |
---|
| 185 | ), |
---|
| 186 | ( |
---|
| 187 | ( arguments.length > 2 && arguments[ 2 ] && arguments[ 2 ].constructor == String ) ? |
---|
| 188 | arguments[ 2 ] : null |
---|
| 189 | ) |
---|
[2703] | 190 | ); |
---|
[2732] | 191 | }; |
---|
[2703] | 192 | |
---|
[2732] | 193 | this.intercept = _intercept; |
---|
[2802] | 194 | this.handler = _handler; |
---|
| 195 | this.manipulator = _manipulator; |
---|
[2703] | 196 | } |
---|
| 197 | |
---|
[2656] | 198 | window.XLink = Link; |
---|
[2420] | 199 | } )( ); |
---|