2014-04-24 02:43:42 +00:00
/*jshint bitwise:true, curly:true, devel:true, eqeqeq:true, evil:true, forin:false, noarg:true, noempty:true, nonew:true, undef:true, strict:false, browser:true, jquery:true */
2013-06-19 19:59:59 +00:00
var History = function ( ) {
var self = this ;
var args = arguments ;
$ ( function ( ) {
self . init . apply ( self , args ) ;
} ) ;
} ;
History . prototype = {
animSpeed : 'normal' ,
noPosts : '<div id="ys-post-1" class="ys-post ys-first ys-admin-post">\n<span class="ys-post-timestamp">13:37</span>\n<span class="ys-post-nickname">Yurivish:<span>\n<span class="ys-post-message">Hey, there aren\'t any posts in this log.</span>\n</div>' ,
init : function ( options ) {
this . prefsInfo = options . prefsInfo ;
this . log = options . log ;
this . initEvents ( ) ;
$ ( 'body' ) . ScrollToAnchors ( { duration : 800 } ) ;
} ,
initEvents : function ( ) {
var self = this ;
this . initLogEvents ( ) ;
// Select log
$ ( '#log' ) . change ( function ( ) {
var logIndex = $ ( this ) . find ( 'option[@selected]' ) . attr ( 'rel' ) ;
var pars = {
p : 'yes' ,
log : logIndex
2014-04-24 02:43:42 +00:00
} ;
2013-06-19 19:59:59 +00:00
self . ajax ( function ( html ) {
2014-04-24 02:43:42 +00:00
$ ( '#ys-posts' ) . html ( html ) ;
2013-06-19 19:59:59 +00:00
$ ( '#yshout' ) . fadeIn ( ) ;
self . initLogEvents ( ) ;
} , pars , true , 'index.php' ) ;
} ) ;
// Clear the log
$ ( '#clear-log' ) . click ( function ( ) {
var el = this ;
var pars = {
reqType : 'clearlog'
} ;
self . ajax ( function ( json ) {
if ( json . error ) {
switch ( json . error ) {
case 'admin' :
self . error ( 'You\'re not an admin. Log in through the admin CP to clear the log.' ) ;
el . innerHTML = 'Clear this log' ;
return ;
}
}
$ ( '#ys-posts' ) . html ( self . noPosts ) ;
self . initLogEvents ( ) ;
2014-04-24 02:43:42 +00:00
el . innerHTML = 'Clear this log' ;
2013-06-19 19:59:59 +00:00
} , pars ) ;
this . innerHTML = 'Clearing...' ;
return false ;
} ) ;
// Clear all logs
$ ( '#clear-logs' ) . click ( function ( ) {
var el = this ;
var pars = {
reqType : 'clearlogs'
} ;
self . ajax ( function ( json ) {
if ( json . error ) {
switch ( json . error ) {
case 'admin' :
2014-04-24 02:43:42 +00:00
el . innerHTML = 'Clear all logs' ;
2013-06-19 19:59:59 +00:00
self . error ( 'You\'re not an admin. Log in through the admin CP to clear logs.' ) ;
return ;
}
}
$ ( '#ys-posts' ) . html ( self . noPosts ) ;
self . initLogEvents ( ) ;
2014-04-24 02:43:42 +00:00
el . innerHTML = 'Clear all logs' ;
2013-06-19 19:59:59 +00:00
} , pars ) ;
this . innerHTML = 'Clearing...' ;
return false ;
} ) ;
} ,
initLogEvents : function ( ) {
var self = this ;
$ ( '#yshout .ys-post' )
. find ( '.ys-info-link' ) . toggle (
function ( ) { self . showInfo . apply ( self , [ $ ( this ) . parent ( ) . parent ( ) [ 0 ] . id , this ] ) ; return false ; } ,
function ( ) { self . hideInfo . apply ( self , [ $ ( this ) . parent ( ) . parent ( ) [ 0 ] . id , this ] ) ; return false ; } )
. end ( )
. find ( '.ys-ban-link' ) . click (
function ( ) { self . ban . apply ( self , [ $ ( this ) . parent ( ) . parent ( ) [ 0 ] ] ) ; return false ; } )
. end ( )
. find ( '.ys-delete-link' ) . click (
function ( ) { self . del . apply ( self , [ $ ( this ) . parent ( ) . parent ( ) [ 0 ] ] ) ; return false ; } ) ;
} ,
showInfo : function ( id , el ) {
var jEl = $ ( '#' + id + ' .ys-post-info' ) ;
2014-04-24 02:43:42 +00:00
if ( jEl . length === 0 ) { return false ; }
2013-06-19 19:59:59 +00:00
2014-04-24 02:43:42 +00:00
if ( this . prefsInfo === 'overlay' ) {
2013-06-19 19:59:59 +00:00
jEl . css ( 'display' , 'block' ) . fadeIn ( this . animSpeed ) ;
2014-04-24 02:43:42 +00:00
} else {
2013-06-19 19:59:59 +00:00
jEl . slideDown ( this . animSpeed ) ;
2014-04-24 02:43:42 +00:00
}
2013-06-19 19:59:59 +00:00
2014-04-24 02:43:42 +00:00
el . innerHTML = 'Close Info' ;
2013-06-19 19:59:59 +00:00
return false ;
} ,
hideInfo : function ( id , el ) {
var jEl = $ ( '#' + id + ' .ys-post-info' ) ;
2014-04-24 02:43:42 +00:00
if ( jEl . length === 0 ) { return false ; }
2013-06-19 19:59:59 +00:00
2014-04-24 02:43:42 +00:00
if ( this . prefsInfo === 'overlay' ) {
2013-06-19 19:59:59 +00:00
jEl . fadeOut ( this . animSpeed ) ;
2014-04-24 02:43:42 +00:00
} else {
2013-06-19 19:59:59 +00:00
jEl . slideUp ( this . animSpeed ) ;
2014-04-24 02:43:42 +00:00
}
2013-06-19 19:59:59 +00:00
el . innerHTML = 'Info' ;
return false ;
} ,
ban : function ( post ) {
var self = this ;
var link = $ ( '#' + post . id ) . find ( '.ys-ban-link' ) [ 0 ] ;
2014-04-24 02:43:42 +00:00
switch ( link . innerHTML )
{
2013-06-19 19:59:59 +00:00
case 'Ban' :
var pIP = $ ( post ) . find ( '.ys-h-ip' ) . html ( ) ;
var pNickname = $ ( post ) . find ( '.ys-h-nickname' ) . html ( ) ;
var pars = {
log : self . log ,
reqType : 'ban' ,
ip : pIP ,
nickname : pNickname
} ;
this . ajax ( function ( json ) {
if ( json . error ) {
switch ( json . error ) {
case 'admin' :
self . error ( 'You\'re not an admin. Log in through the admin CP to ban people.' ) ;
break ;
}
return ;
}
$ ( '#yshout .ys-post[@rel="' + pars . ip + '"]' )
. addClass ( 'ys-banned-post' )
. find ( '.ys-ban-link' )
. html ( 'Unban' ) ;
} , pars ) ;
link . innerHTML = 'Banning...' ;
return false ;
case 'Banning...' :
return false ;
case 'Unban' :
var pIP = $ ( post ) . find ( '.ys-h-ip' ) . html ( ) ;
var pars = {
reqType : 'unban' ,
ip : pIP
} ;
this . ajax ( function ( json ) {
if ( json . error ) {
switch ( json . error ) {
case 'admin' :
self . error ( 'You\'re not an admin. Log in through the admin CP to unban people.' ) ;
return ;
}
}
$ ( '#yshout .ys-post[@rel="' + pars . ip + '"]' )
. removeClass ( 'ys-banned-post' )
. find ( '.ys-ban-link' )
. html ( 'Ban' ) ;
} , pars ) ;
link . innerHTML = 'Unbanning...' ;
return false ;
case 'Unbanning...' :
return false ;
}
} ,
del : function ( post ) {
var self = this ;
var link = $ ( '#' + post . id ) . find ( '.ys-delete-link' ) [ 0 ] ;
2014-04-24 02:43:42 +00:00
if ( link . innerHTML === 'Deleting...' ) { return ; }
2013-06-19 19:59:59 +00:00
var pUID = $ ( post ) . find ( '.ys-h-uid' ) . html ( ) ;
var pars = {
reqType : 'delete' ,
uid : pUID
} ;
self . ajax ( function ( json ) {
if ( json . error ) {
switch ( json . error ) {
case 'admin' :
self . error ( 'You\'re not an admin. Log in through the admin CP to ban people.' ) ;
return ;
}
}
$ ( post ) . slideUp ( self . animSpeed ) ;
} , pars ) ;
link . innerHTML = 'Deleting...' ;
return false ;
} ,
json : function ( parse ) {
var json = eval ( '(' + parse + ')' ) ;
return json ;
} ,
ajax : function ( callback , pars , html , page ) {
pars = jQuery . extend ( {
reqFor : 'history' ,
log : this . log
} , pars ) ;
var self = this ;
2014-04-24 02:43:42 +00:00
if ( page === null ) { page = '../yshout.php' ; }
2013-06-19 19:59:59 +00:00
$ . post ( page , pars , function ( parse ) {
2014-04-24 02:43:42 +00:00
if ( parse ) {
if ( html ) {
2013-06-19 19:59:59 +00:00
callback . apply ( self , [ parse ] ) ;
2014-04-24 02:43:42 +00:00
} else {
2013-06-19 19:59:59 +00:00
callback . apply ( self , [ self . json ( parse ) ] ) ;
2014-04-24 02:43:42 +00:00
}
} else {
2013-06-19 19:59:59 +00:00
callback . apply ( self ) ;
2014-04-24 02:43:42 +00:00
}
2013-06-19 19:59:59 +00:00
} ) ;
} ,
error : function ( err ) {
alert ( err ) ;
}
} ;