/*js
//==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>>
//
// Ajax Poll Admin v1.07 [ Commercial Version ]
// Copyright (c) phpkobo.com ( http://www.phpkobo.com/ )
// Email : admin@phpkobo.com
// ID : APADM-107
// URL : http://www.phpkobo.com/ajax-poll-admin
//
//==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<<
*/
(function($){
//----------------------------------------------------------------
// CWaitIcon
//----------------------------------------------------------------
function CWaitIcon( url_img ) {
var s = '';
s += "
";
s += "

";
s += "
";
this.box = $( s );
this.box.css({
"position":"absolute",
"left":"-10000px",
"top":"-10000px",
"padding":"5px 5px 3px 5px",
"opacity":"0.5"
});
this.box.hide();
this.box.appendTo( $( 'body' ) );
}
CWaitIcon.prototype =
{
show : function( e ) {
var w = this.box.outerWidth();
var h = this.box.outerHeight();
this.box.css({
"left" : (e.pageX - w/2) + "px",
"top" : (e.pageY - h/2) + "px"
});
this.will_show = true;
var _this = this;
setTimeout( function(){
if ( _this.will_show ) {
_this.box.show();
}
}, 1000 );
},
hide : function() {
this.will_show = false;
this.box.hide();
}
}
//----------------------------------------------------------------
// CApp
//----------------------------------------------------------------
var app_object_selector = '.apadm';
function CApp( jobj )
{
this.children = [];
this.jobj = jobj;
this.tclass = this.getAttr( 'tclass', jobj );
this.tid = this.getAttr( 'tid', jobj );
//-- tprop
this.tprop = {};
var span = jobj.children( 'span' );
if ( span.length )
{
var json = span.eq(0).html();
jobj.attr( 'tprop', json );
if ( json != '' )
{
this.tprop = eval('(' + json + ')');
}
}
this.url_app_entry = '/ajax-polls/conn/index.php';
this.url_app_root = '/ajax-polls/conn/';
this.url_app_img = '/ajax-polls/conn/images/';
this.appid = this.makeRandomString( 64 );
this.app_init_cmd = 'init';
this.wait_icon = new CWaitIcon( this.url_app_img + 'wait.gif' );
if ( this.app_init_cmd != '' )
{
this.send( { "cmd" : this.app_init_cmd } );
}
}
CApp.prototype =
{
showWaitIcon: function( e )
{
this.wait_icon.show( e );
},
showTipBox: function( obj, cfg, tbox )
{
period = ( "period" in cfg ) ? cfg["period"] : 1000;
var tip_box;
if ( typeof tbox === 'object' )
{
tip_box = tbox.clone();
}
else
{
txt = ( "txt" in cfg ) ? cfg["txt"] : "Saved!";
bgcolor = ( "background-color" in cfg ) ? cfg["background-color"] : "#60a060";
var s = '';
s += "";
s += txt;
s += "";
tip_box = $( s );
}
tip_box.css({
"position":"absolute",
"left":"-10000px",
"top":"-10000px"
});
tip_box.appendTo( $( 'body' ) );
tip_box.show();
wt = tip_box.outerWidth(true);
ht = tip_box.outerHeight(true);
var x = obj.offset().left;
var y = obj.offset().top;
var w = obj.width();
var h = obj.height();
var xtd = 55;
var ytd = 10;
var xt = x + w/2 - wt/2;
var yt = y - ht;
tip_box.offset( { "left":xt, "top":yt } );
window.setTimeout( function(){
tip_box.fadeOut( period, function() {
tip_box.remove();
});
}, period );
},
//-----------------------------------------------
// makeRandomString( n )
//-----------------------------------------------
makeRandomString : function ( n )
{
var s = "";
var src = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < n; i++ )
{
s += src.charAt( Math.floor( Math.random() * src.length ) );
}
return s;
},
//-----------------------------------------------
// errBox
//-----------------------------------------------
errBox : function( data )
{
var errbox_sig = "";
if ( data.substring( 0, errbox_sig.length ) == errbox_sig )
{// prevent double errbox
return data;
}
else
{
var msg = '';
msg += "";
msg += "
ERROR
";
msg += "
";
msg += data;
msg += "
";
msg += "
";
return msg;
}
},
//-----------------------------------------------
// getAttr
//-----------------------------------------------
getAttr : function( id_name, jobj )
{
if (
( typeof( jobj.attr( id_name ) ) == 'undefined' ) ||
( jobj.attr( id_name ) == '' ) // for Opera
) return '';
return jobj.attr( id_name );
},
//-----------------------------------------------
// send
//-----------------------------------------------
send : function( json )
{
json['tprop'] = this.tprop;
json['appid'] = this.appid;
json['tclass'] = this.tclass;
json['tid'] = this.tid;
var _this = this;
$.post( this.url_app_entry,
json,
function(data) {
_this.process(data);
});
},
//-----------------------------------------------
// addChild
//-----------------------------------------------
addChild : function( child )
{
this.children[child.name] = child;
return child;
},
//-----------------------------------------------
// getChild
//-----------------------------------------------
getChild : function( name )
{
return this.children[name];
},
//-----------------------------------------------
// sendMsg
//-----------------------------------------------
sendMsg : function( msg )
{
if ( typeof( msg.receiver ) !== 'undefined' )
{
if( Object.prototype.toString.call( msg.receiver ) === '[object Array]' )
{
for ( var i = 0; i < msg.receiver.length; i++ )
{
var ret = this.children[ msg.receiver[i] ].msgProc( msg );
if ( ret != 0 ) return ret;
}
}
else
{
return this.children[msg.receiver].msgProc( msg );
}
}
else
{
for( name in this.children )
{
var ret = this.children[name].msgProc( msg );
if ( ret != 0 ) return ret;
}
}
},
//-----------------------------------------------
// ajaxpp
//-----------------------------------------------
ajaxpp : function( data )
{
var s_reload = "";
if ( data.substring(0,s_reload.length) == s_reload )
{
location.reload(true);
return false;
}
return true;
},
//-----------------------------------------------
// process
//-----------------------------------------------
process : function( data )
{
this.wait_icon.hide();
if ( !this.ajaxpp( data ) ) return;
var b_evaled = false;
try
{
this.res = eval('(' + data + ')');
b_evaled = true;
}
catch(e)
{
var msg = "[ERROR]:" + "\r\n\r\n" + data.substring(0,1000);
//alert( msg );
this.jobj.html( this.errBox(data) );
}
try
{
if ( b_evaled )
{
if ( this.res.result == 'OK' )
{
window[this.appid] = this;
switch( this.res.cmd )
{
case "alert":
alert(this.res.html);
break;
case "load":
this.jobj.append( this.res.html );
break;
}
if ( typeof( this.res.msg ) !== 'undefined' )
{
this.sendMsg( this.res.msg );
}
}
else
{//-- code error
alert( "^" + this.res.result );
this.jobj.html( this.res.result );
}
}
}
catch(e)
{
var msg = "{ERROR}:" + e.message;
alert( msg );
}
}
}
//----------------------------------------------------------------
// ready
//----------------------------------------------------------------
$(document).ready(function() {
$( app_object_selector ).each( function(){
var app = new CApp( $(this) );
});
});
}(jQuery));