2013-11-08 08:43:57 +00:00
/ * *
* @ fileOverview jui _theme _switch : jquery plugin to switch juery - ui themes
* < p > License MIT
* < br / > Copyright 2012 Christos Pontikis < a href = "http://pontikis.net" > http : //pontikis.net</a>
* < br / > Project page < a href = "http://pontikis.net/labs/jui_theme_switch" > http : //pontikis.net/labs/jui_theme_switch</a>
* < br / > Minified using Online YUI Compressor http : //www.refresh-sf.com/yui/
* @ version 1.0 . 6 ( 21 Jan 2013 )
* @ author Christos Pontikis http : //pontikis.net
* @ requires jquery , jquery - ui
* /
2016-07-17 17:30:25 +00:00
"use strict" ; ( function ( c ) { var h = { init : function ( g ) { var d = this ; return this . each ( function ( ) { var a = d . data ( "jui_theme_switch" ) ; if ( "undefined" == typeof a ) var m = d . jui _theme _switch ( "getDefaults" ) , a = c . extend ( { } , m , g ) ; else a = c . extend ( { } , a , g ) ; d . data ( "jui_theme_switch" , a ) ; "undefined" === typeof d . data ( "jui_theme_switch_status" ) && ( d . data ( "jui_theme_switch_status" , { } ) , d . data ( "jui_theme_switch_status" ) . selected _theme = { } ) ; d . unbind ( "onChangeTheme" ) . bind ( "onChangeTheme" , a . onChangeTheme ) ; d . unbind ( "onDisplay" ) . bind ( "onDisplay" , a . onDisplay ) ;
var m = d . attr ( "id" ) , n , b , f = "" , p = a . switcher _id _prefix + m , h = a . switcher _label _id _prefix + m , k , u , w = c ( "#" + a . stylesheet _link _id ) , q = "" , l , r = "" , t = "" , v ; c . ajax ( { url : a . datasource _url , dataType : "json" , cache : ! 1 , success : function ( e ) { n = e . length ; f += '<label id="' + h + '" for="' + p + '">' + a . switcher _label + "</label>" ; f += '<select id="' + p + '" size="' + a . list _size + '">' ; for ( b = 0 ; b < n ; b ++ ) if ( l = "yes" == e [ b ] . active || "yes" == a . show _all ) "yes" == a . use _groups && ( l = e [ b ] . group , l !== r && ( f += '<optgroup label="' + l + '">' , r = l ) ) , a . default _theme == e [ b ] . theme _name ?
( d . data ( "jui_theme_switch_status" ) . selected _theme = e [ b ] , q = ' selected="selected"' ) : q = "" , t = "" , e [ b ] . hasOwnProperty ( "hosted_locally" ) && "yes" == e [ b ] . hosted _locally && ( t = a . project _url ) , f += '<option value="' + t + e [ b ] . theme _url + '"' + q + ">" , f += e [ b ] . theme _name , f += "</option>" , "yes" == a . use _groups && b < n - 1 && e [ parseInt ( b ) + 1 ] . group !== r && ( f += "</optgroup>" ) ; f += "</select>" ; d . html ( f ) ; u = c ( "#" + h ) ; k = c ( "#" + p ) ; u . removeClass ( ) . addClass ( a . labelClass ) ; k . removeClass ( ) . addClass ( a . listClass ) ; d . removeClass ( ) . addClass ( a . containerClass ) ; d . off ( "change" ,
k ) . on ( "change" , k , function ( ) { v = ( k . val ( ) || "" ) . replace ( /\{version\}/g , c . ui && c . ui . version || "1.12.0" ) ; w . attr ( "href" , v ) ; for ( b = 0 ; b < n ; b ++ ) if ( c ( "#" + p + " option:selected" ) . text ( ) == e [ b ] . theme _name ) { d . data ( "jui_theme_switch_status" ) . selected _theme = e [ b ] ; break } d . triggerHandler ( "onChangeTheme" , e [ b ] ) } ) ; d . triggerHandler ( "onDisplay" ) } } ) } ) } , getDefaults : function ( ) { return { switcher _label : "Select theme" , default _theme : "ui-lightness" , list _size : "1" , use _groups : "yes" , show _all : "no" , project _url : "" , containerClass : "switcher_container" ,
labelClass : "switcher_label" , listClass : "switcher_list" , switcher _label _id _prefix : "lbl_" , switcher _id _prefix : "switcher_" , onChangeTheme : function ( ) { } , onDisplay : function ( ) { } } } , getOption : function ( c ) { return this . data ( "jui_theme_switch" ) [ c ] } , getAllOptions : function ( ) { return this . data ( "jui_theme_switch" ) } , setOption : function ( c , d , a ) { this . data ( "jui_theme_switch" ) [ c ] = d ; a && this . jui _theme _switch ( "init" ) } , refresh : function ( ) { this . jui _theme _switch ( ) } , destroy : function ( ) { return c ( this ) . each ( function ( ) { c ( this ) . removeData ( "jui_theme_switch" ) } ) } ,
getTheme : function ( ) { return this . data ( "jui_theme_switch_status" ) . selected _theme } } ; c . fn . jui _theme _switch = function ( g ) { 1 != this . length && ( this . html ( '<span style="color: red;">ERROR: You must use this plugin (jui_theme_switch) with a unique element (at once)</span>' ) , c . error ( "You must use this plugin (jui_theme_switch) with a unique element (at once)" ) ) ; if ( h [ g ] ) return h [ g ] . apply ( this , Array . prototype . slice . call ( arguments , 1 ) ) ; if ( "object" !== typeof g && g ) c . error ( "Method " + g + " does not exist on jQuery.jui_theme_switch" ) ;
else return h . init . apply ( this , arguments ) } } ) ( jQuery ) ;