2012-03-28 10:53:30 +00:00
// JavaScript Document
2012-04-18 14:01:12 +00:00
//Harry Bomrah
2012-03-28 10:53:30 +00:00
var orbitDesktopAPI = function ( ) {
o = this ;
2012-05-25 07:41:07 +00:00
this . windowcounter = 0 ;
2012-03-29 11:50:23 +00:00
this . notify = function ( msg , type , time ) {
2012-05-25 07:41:07 +00:00
//takes 3 arguments
//msg (string) : message to display
//type (string : success, imp, alert
//time (int) : duration for notification in seconds
2013-04-16 07:48:14 +00:00
var $notify = $ ( '#orbitnote' ) ,
ani _method = { direction : 'up' , easing : 'easeInOutQuint' } ,
img , n _height ;
2012-03-29 11:50:23 +00:00
if ( ! type ) type = "" ;
switch ( type ) {
case "alert" :
2013-04-16 07:48:14 +00:00
img = "exclamation-sign" ;
2012-03-29 11:50:23 +00:00
break ;
case "imp" :
2013-04-16 07:48:14 +00:00
img = "warning-sign" ;
2012-03-29 11:50:23 +00:00
break ;
case "success" :
2013-04-16 07:48:14 +00:00
img = "ok" ;
2012-03-29 11:50:23 +00:00
break ;
default :
2013-04-16 07:48:14 +00:00
img = "exclamation-sign" ;
2012-03-29 11:50:23 +00:00
break ;
}
2013-04-16 07:48:14 +00:00
if ( ! time || time > 20 ) time = 5000 ; else time = time * 1000 ;
var sign = '<div class="note_type"><span class="sign icon-' + img + '"></span></div>' ,
message = '<div class="note_message">' + msg + '</div>' ,
item = '<div class="note_holder admbg">' + sign + message + '</div>' ;
$ ( item )
. prependTo ( $notify )
. stop ( 1 , 1 )
. toggle ( 'slide' , ani _method , 300 )
2012-04-05 20:42:20 +00:00
. delay ( time )
2013-04-16 07:48:14 +00:00
. toggle ( 'slide' , ani _method , 800 ) ;
$notify . find ( '.note_holder:hidden' ) . remove ( ) ;
2012-03-28 10:53:30 +00:00
} ;
2012-04-11 07:31:10 +00:00
this . executeFunc = function ( func , callbackFn ) {
2012-05-25 07:41:07 +00:00
//takes 2 arguments
//func (object Function) : the function which has to be executed
//callbackFn (object function) : the function for callback
2012-04-11 07:31:10 +00:00
func . call ( this ) ;
if ( callbackFn ) {
callbackFn . call ( this , func ) ;
}
} ;
this . sortJSON = function ( field , reverse , primer ) {
2012-05-25 07:41:07 +00:00
//takes 3 arguments
//field (string): it is the field on which sorting has to be done
//reverse (boolean): this is for asc or desc
//primer (method): for example pass parseInt for converting the field attribute in integer
2012-04-11 07:31:10 +00:00
var key = function ( x ) { return primer ? primer ( x [ field ] ) : x [ field ] } ;
return function ( a , b ) {
var A = key ( a ) , B = key ( b ) ;
return ( ( A < B ) ? - 1 : ( A > B ) ? + 1 : 0 ) * [ - 1 , 1 ] [ + ! ! reverse ] ;
}
2012-04-18 10:15:02 +00:00
} ;
this . rgb2hex = function ( rgb ) {
2012-05-25 07:41:07 +00:00
// takes 1 parameter
// rgb (string) : pass rgb string to convert
2012-04-18 10:15:02 +00:00
rgb = rgb . match ( /^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/ ) ;
var hex = function ( x ) {
return ( "0" + parseInt ( x ) . toString ( 16 ) ) . slice ( - 2 ) ;
}
return "#" + hex ( rgb [ 1 ] ) + hex ( rgb [ 2 ] ) + hex ( rgb [ 3 ] ) ;
} ;
2012-04-18 14:01:12 +00:00
this . changeWallpaper = function ( wallpaper ) {
2012-05-25 07:41:07 +00:00
//takes 1 parameter
//wallpaper (string): takes wallpaper and sets the wallpaper
2013-05-30 07:24:16 +00:00
$ ( "#thmbackground" ) . attr ( "src" , o . wallpaperPath + wallpaper ) ;
2012-04-18 14:01:12 +00:00
o . saveWallpaper ( wallpaper ) ;
} ;
2012-04-19 07:36:03 +00:00
this . confirm = function ( settings , callbackfn ) {
2012-05-25 07:41:07 +00:00
//takes set of arguments in array
//settings.buttons (array string) : name of buttons to be displayed
//settings.highlighted (integer) : takes either 1 or 2.. will highlight the button which is passed
//settings.message (string) : takes a string and message to be displayed on the confirmbox
//callbackfn (object function) : function to callback
2012-04-19 07:36:03 +00:00
if ( ! settings . buttons ) settings . buttons = [ "Ok" , "Cancel" ] ;
2012-04-24 08:45:26 +00:00
if ( settings . highlighted != 1 && settings . highlighted != 2 ) settings . highlighted = 2 ;
2012-04-19 07:36:03 +00:00
if ( ! settings . message ) settings . message = "Are you sure?"
2012-04-18 14:01:12 +00:00
var $confirm = $ ( "#orbitdiag" ) ;
2012-04-24 08:45:26 +00:00
$confirm . find ( ".diag_action a" ) . removeClass ( "thmc1 thmtxt" ) . addClass ( "admbg admtxt" ) ;
2012-04-19 07:36:03 +00:00
$confirm . find ( ".diag_message" ) . text ( settings . message ) ;
if ( settings . highlighted == 1 )
2012-04-18 14:01:12 +00:00
$confirm . find ( "#diag_confirm" ) . removeClass ( "admbg admtxt" ) . addClass ( "thmc1 thmtxt" ) ;
2012-04-19 07:36:03 +00:00
if ( settings . highlighted == 2 )
2012-04-18 14:01:12 +00:00
$confirm . find ( "#diag_cancel" ) . removeClass ( "admbg admtxt" ) . addClass ( "thmc1 thmtxt" ) ;
2012-04-19 07:36:03 +00:00
$confirm . find ( "#diag_confirm" ) . text ( settings . buttons [ 0 ] ) . one ( "click" , function ( ) {
2012-04-26 15:18:35 +00:00
$confirm . stop ( 1 , 1 ) . fadeOut ( ) ;
2012-04-18 14:01:12 +00:00
$confirm . find ( ".diag_action a" ) . unbind ( ) ;
if ( typeof callbackfn == "function" )
callbackfn . call ( this , true ) ;
} ) ;
2012-04-19 07:36:03 +00:00
$confirm . find ( "#diag_cancel" ) . text ( settings . buttons [ 1 ] ) . one ( "click" , function ( ) {
2012-04-26 15:18:35 +00:00
$confirm . stop ( 1 , 1 ) . fadeOut ( ) ;
2012-04-18 14:01:12 +00:00
$confirm . find ( ".diag_action a" ) . unbind ( ) ;
if ( typeof callbackfn == "function" )
callbackfn . call ( this , false ) ;
} ) ;
2012-04-26 15:18:35 +00:00
$confirm . stop ( 1 , 1 ) . fadeIn ( ) ;
2012-04-24 08:45:26 +00:00
} ;
2012-05-11 07:27:16 +00:00
this . getArrayfromJson = function ( tjson , key ) {
2012-05-25 07:41:07 +00:00
// returns array and takes json object and key
//json (json object) : json object from which the key has to be extracted
// key (string) : key which has to be extracted
2012-05-11 07:27:16 +00:00
var tempArray = new Array ;
$ . each ( tjson , function ( i , val ) {
tempArray . push ( val [ key ] ) ;
} )
return tempArray ;
2012-05-25 07:41:07 +00:00
} ;
2013-07-25 09:18:24 +00:00
this . appWindow = function ( options , callbackfn ) {
2012-05-25 07:41:07 +00:00
//takes set of arguments as array and gives callback
//settings.method (string) : like open and close
//settings.title (string) : the window title
2013-03-25 10:44:06 +00:00
//settings.extUrl (boolean) : true for opening external url else false
2012-05-25 07:41:07 +00:00
//settings.appid (string) : appid.. user can use this appid to open or close or refresh the window
//settings.url (string) : it is the url if you want to force external url to open in appwindow... you have to pass extURL in appid if you want to open externalurl
2013-07-25 09:18:24 +00:00
var settings = {
method : "open" ,
extUrl : true ,
title : "New Window"
}
$ . extend ( settings , options ) ;
2012-05-25 07:41:07 +00:00
if ( ! settings . appid ) {
o . notify ( "Invalid AppID." , "imp" , 3 ) ;
return ;
}
2013-07-25 09:18:24 +00:00
var isWindow = ( $ ( "div.app_frame[data-app=" + settings . appid + "]" ) . length > 0 ? $ ( "div.app_frame[data-app=" + settings . appid + "]" ) : null ) ;
if ( isWindow ) {
o . minimizeBarManager . maximize ( isWindow ) ;
return ;
}
2012-05-25 07:41:07 +00:00
if ( settings . method == 'open' ) {
var appurl = "http://www.rulingcom.com" ;
o . windowcounter ++ ;
2013-03-25 10:44:06 +00:00
if ( settings . extUrl ) {
2012-05-25 07:41:07 +00:00
if ( settings . url ) {
2013-03-25 10:44:06 +00:00
if ( settings . url . substr ( 0 , 4 ) != "http" ) settings . url = "http://" + settings . url ;
2012-05-25 07:41:07 +00:00
var urlregex = new RegExp ( "^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)" ) ;
if ( urlregex . test ( settings . url ) )
appurl = settings . url ;
else {
o . notify ( "Invalid URL" , "alert" , 3 ) ;
return ;
}
}
else {
o . notify ( "Invalid URL" , "alert" , 3 ) ;
return ;
}
}
2013-07-25 09:18:24 +00:00
var whtml = $ ( '<div id="app_frame_' + o . windowcounter + '" class="thmc2 app_frame" data-app="' + settings . appid + '" data-title="' + settings . title + '"><div class="app_frame_header"><div class="dtitle hh2 hp"><span class="thmtxth">' + settings . title + '</span></div><span class="icon-remove hh2 hp thmtxt"></span><span class="icon-minus hh2 hp thmtxt"></span></div><div id="holder_' + o . windowcounter + '" class="app_holder clear"><iframe src="' + appurl + '" frameborder="0" scrolling="auto"></iframe></div></div>' ) ;
2013-07-29 10:21:07 +00:00
$ ( o . contentHolder ) . append ( whtml ) ;
2013-05-30 07:24:16 +00:00
var parentwindow = $ ( o . contentHolder ) . find ( "#app_frame_" + o . windowcounter ) ;
2012-05-25 07:41:07 +00:00
var app _holder _height = parentwindow . height ( ) - 72 ;
var app _holder _width = parentwindow . width ( ) ;
parentwindow . find ( "iframe" ) . attr ( { "height" : app _holder _height , "width" : app _holder _width } ) ;
2013-05-30 07:24:16 +00:00
parentwindow . find ( ".app_holder" ) . height ( app _holder _height ) ;
parentwindow . find ( ".icon-remove" ) . click ( function ( ) {
2013-07-25 09:18:24 +00:00
o . appWindow . close ( parentwindow ) ;
} ) ;
parentwindow . find ( ".icon-minus" ) . click ( function ( ) {
o . appWindow . minimize ( parentwindow ) ;
2012-05-25 07:41:07 +00:00
} )
2013-07-25 09:18:24 +00:00
2012-05-25 07:41:07 +00:00
}
2013-07-25 09:18:24 +00:00
this . appWindow . close = function ( win ) {
win . remove ( ) ;
}
this . appWindow . minimize = function ( win ) {
o . minimizeBarManager . minimize ( win )
}
2012-05-25 07:41:07 +00:00
if ( typeof callbackfn == "function" ) {
2013-07-25 09:18:24 +00:00
callbackfn . call ( this , parentwindow ) ;
2012-05-25 07:41:07 +00:00
}
2013-07-25 09:18:24 +00:00
return parentwindow ;
2012-05-25 07:41:07 +00:00
} ;
2012-06-26 07:59:28 +00:00
this . toolPopup = function ( settings ) {
if ( settings == "destroy" ) {
$ ( ".desktop_toolpopup" ) . hide ( "fold" , function ( ) {
$ ( this ) . remove ( ) ;
$ ( this ) . parent ( ) . css ( "position" , "" ) ;
} )
return ;
}
if ( settings . parent ) {
if ( settings . parent . find ( "div.desktop_toolpopup" ) . length == 0 ) {
settings . height = ( ! settings . height ? "50px" : settings . height ) ;
settings . width = ( ! settings . width ? "150px" : settings . width ) ;
settings . html = ( ! settings . html ? "" : settings . html ) ;
2012-07-06 08:11:03 +00:00
//Events
settings . onClose = ( ! settings . onClose ? function ( ) { } : settings . onClose ) ;
settings . beforeOpen = ( ! settings . beforeOpen ? function ( ) { } : settings . beforeOpen ) ;
settings . onOpen = ( ! settings . onOpen ? function ( ) { } : settings . onOpen ) ;
settings . beforeClose = ( ! settings . beforeClose ? function ( ) { } : settings . beforeClose ) ;
//Events end
2012-07-05 08:23:13 +00:00
var leftpos = settings . parent . outerWidth ( ) ;
var toolpopup = $ ( "<div class='desktop_toolpopup' style='height:" + settings . height + ";width:" + settings . width + "; left:" + leftpos + "px;'>" + settings . html + "</div>" ) ;
2012-06-26 07:59:28 +00:00
settings . parent . css ( "position" , "relative" ) ;
settings . parent . prepend ( toolpopup ) ;
toolpopup . click ( function ( event ) {
event . stopPropagation ( ) ;
} ) ;
2012-07-06 08:11:03 +00:00
settings . beforeOpen . call ( this ) ;
2012-06-26 07:59:28 +00:00
toolpopup . show ( "fold" , function ( ) {
2012-07-06 08:11:03 +00:00
settings . onOpen . call ( this ) ;
2012-06-26 07:59:28 +00:00
$ ( document ) . unbind ( "click" ) ;
$ ( document ) . one ( "click" , function ( e ) {
2012-07-06 08:11:03 +00:00
settings . beforeClose . call ( this ) ;
2012-06-26 07:59:28 +00:00
toolpopup . hide ( "fold" , function ( ) {
toolpopup . remove ( ) ;
settings . parent . css ( "position" , "" ) ;
2012-07-06 08:11:03 +00:00
settings . onClose . call ( this ) ;
2012-06-26 07:59:28 +00:00
} ) ;
} )
} ) ;
}
}
2013-03-25 08:23:07 +00:00
} ;
2012-03-29 11:50:23 +00:00
} ;
2012-04-18 14:01:12 +00:00
orbitDesktopAPI . prototype . notifyImgPath = "temp" ;
orbitDesktopAPI . prototype . wallpaperPath = "temp" ;