1if ( !window.AsteikkoAuth ) window.AsteikkoAuth = {}; 2 3( function( $ ) { 4 5 AsteikkoAuth.baseurl = ''; 6 AsteikkoAuth.userAccessLevel = 1; 7 8 AsteikkoAuth.submitAccountForm = function( form, callback ) { 9 10 var jqForm = $( form ); 11 jqForm.find( 'input' ).blur(); 12 13 return $.ajax( { 14 url: AsteikkoAuth.baseurl +'asauth/ajax', 15 type: 'POST', 16 dataType: 'json', 17 data: jqForm.serialize() 18 } ). 19 done( function( data ) { 20 if ( data && typeof data === 'object' && typeof callback === 'function' ) { 21 callback( form, data.code, data.message, data.data ); 22 } 23 } ); 24 }; 25 26 AsteikkoAuth.readCookie = function(name) { 27 var nameEQ = name + "="; 28 var ca = document.cookie.split(';'); 29 for (var i = 0; i < ca.length; i++) { 30 var c = ca[i]; 31 while (c.charAt(0) == ' ') { 32 c = c.substring(1, c.length); 33 } 34 if (c.indexOf(nameEQ) == 0) { 35 return unescape(c.substring(nameEQ.length, c.length)); 36 } 37 }; 38 return null; 39 }; 40 41 AsteikkoAuth._closeIssuePaywall = function( event ) { 42 43 event.preventDefault(); 44 $( event.target ).closest( '.asauth-dialog-wrapper' ).fadeOut(); 45 }; 46 47 AsteikkoAuth._onClickIssuePaywallWrapper = function( event ) { 48 49 if ( !$( '.asauth-dialog-wrapper' ).is( event.target ) ) 50 return; 51 AsteikkoAuth._closeIssuePaywall( event ); 52 }; 53 54 AsteikkoAuth.showDialog = function( elemId, htmlContent ) { 55 56 if ( elemId ) 57 $( '#'+ elemId ).remove(); 58 59 var dialogWrapper = $( '<div '+ ( elemId ? 'id="'+ elemId +'"' : '' ) +' class="asauth-dialog-wrapper"></div>' ). 60 click( AsteikkoAuth._onClickIssuePaywallWrapper ); 61 62 // Assuming that the environment has font-awesome installed 63 // TODO: bundle font-awesome with Asteikko Auth? 64 var button = $( '<i class="asauth-dialog-close fa fa-times-circle"></i>' ). 65 click( AsteikkoAuth._closeIssuePaywall ); 66 67 var dialog = $( '<div class="asauth-notificationBox"></div>' ). 68 append( button ). 69 appendTo( dialogWrapper ); 70 71 $( '<div class="asauth-notificationBoxContent"></div>' ). 72 append( htmlContent ). 73 appendTo( dialog ); 74 75 $( 'body' ).append( dialogWrapper ); 76 77 return dialogWrapper; 78 }; 79 80 81 /***************************************************************************** 82 Product buying 83 *****************************************************************************/ 84 85 function initOrderProductDialog() { 86 87 if ( $( '#asauth-orderproduct' ).length ) return; 88 89 var dialogWrapper = $( '<div id="asauth-orderproduct" class="asauth-dialog-wrapper"></div>' ); 90 var dialog = $( '<div class="asauth-notificationBox"></div>' ).appendTo( dialogWrapper ); 91 var dialogContent = $( '<div class="asauth-notificationBoxContent"></div>' ).appendTo( dialog ); 92 93 $( document.body ).append( dialogWrapper ); 94 } 95 96 AsteikkoAuth.orderProduct = function( productCode ) { 97 98 initOrderProductDialog(); 99 100 var dialog = $( '#asauth-orderproduct' ).hide(); 101 var dialogContent = dialog.find( '.asauth-notificationBoxContent' ); 102 103 return $.ajax( { 104 url: AsteikkoAuth.baseurl +'asauth/ajax', 105 type: 'POST', 106 dataType: 'json', 107 data: { 108 action: 'create_order', 109 product_code: productCode 110 } 111 } ). 112 done( function( data ) { 113 var okButton = $( 114 '<br><br><a id="btn_order_cancel" class="asauth-textButton clickdelay"><span>OK</span></a>' 115 ).click( function() { 116 dialog.hide(); 117 dialogContent.empty(); 118 return false; 119 } ); 120 if ( data && data.code === 0 ) { 121 window.location.href = data.message; 122 } 123 else if ( data && data.message ) { 124 dialogContent.html( data.message ); 125 dialogContent.append( okButton ); 126 dialog.show(); 127 } 128 else { 129 dialogContent.html( 'Error' ); 130 dialogContent.append( okButton ); 131 dialog.show(); 132 } 133 } ); 134 }; 135 136 137 /***************************************************************************** 138 Analytics 139 *****************************************************************************/ 140 141 AsteikkoAuth.trackEvent = function( category, action, label ) { 142 if ( window._gaq && navigator.onLine ) {
143 window._gaq.push( [ '_trackEvent', category, action, label ] ); 144 } 145 }; 146 147 AsteikkoAuth.init = function( baseUrl ) { 148 149 if ( !baseUrl || typeof baseUrl !== 'string' ) 150 throw 'Invalid base URL'; 151 152 AsteikkoAuth.baseurl = baseUrl.replace( /\/+$/g, '' ) +'/'; 153 154 var accessLevel = parseInt( 155 AsteikkoAuth.readCookie( 'asauth_user_accesslevel' ), 10 ) || 1; 156 AsteikkoAuth.userAccessLevel = accessLevel; 157 158 $( function() { 159 $( 'body' ).addClass( 'asauth-accesslevel-'+ accessLevel ); 160 } ); 161 }; 162 163} )( window.jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.