2007-05-31 22:43:05 +00:00
Xinha . Config . prototype . css _style = { } ;
Xinha . Config . prototype . stylistLoadStylesheet = function ( _1 , _2 ) {
if ( ! _2 ) {
_2 = { } ;
}
var _3 = Xinha . ripStylesFromCSSFile ( _1 ) ;
for ( var i in _3 ) {
if ( _2 [ i ] ) {
this . css _style [ i ] = _2 [ i ] ;
} else {
this . css _style [ i ] = _3 [ i ] ;
}
}
this . pageStyleSheets [ this . pageStyleSheets . length ] = _1 ;
} ;
Xinha . Config . prototype . stylistLoadStyles = function ( _5 , _6 ) {
if ( ! _6 ) {
_6 = { } ;
}
var _7 = Xinha . ripStylesFromCSSString ( _5 ) ;
for ( var i in _7 ) {
if ( _6 [ i ] ) {
this . css _style [ i ] = _6 [ i ] ;
} else {
this . css _style [ i ] = _7 [ i ] ;
}
}
this . pageStyle += _5 ;
} ;
Xinha . prototype . _fillStylist = function ( ) {
if ( ! this . _stylist ) {
return false ;
}
this . plugins . Stylist . instance . main . innerHTML = "" ;
var _9 = true ;
var _a = this . _getSelection ( ) ;
var _b = this . _activeElement ( _a ) ;
for ( var x in this . config . css _style ) {
var _d = null ;
var _e = x . trim ( ) ;
var _f = true ;
var _10 = _b ;
if ( _f && /[^a-zA-Z0-9_.-]/ . test ( _e ) ) {
_f = false ;
}
if ( _e . indexOf ( "." ) < 0 ) {
_f = false ;
}
if ( _f && ( _e . indexOf ( "." ) > 0 ) ) {
_d = _e . substring ( 0 , _e . indexOf ( "." ) ) . toLowerCase ( ) ;
_e = _e . substring ( _e . indexOf ( "." ) , _e . length ) ;
if ( _b != null && _b . tagName . toLowerCase ( ) == _d ) {
_f = true ;
_10 = _b ;
} else {
if ( this . _getFirstAncestor ( this . _getSelection ( ) , [ _d ] ) != null ) {
_f = true ;
_10 = this . _getFirstAncestor ( this . _getSelection ( ) , [ _d ] ) ;
} else {
if ( ( _d == "div" || _d == "span" || _d == "p" || ( _d . substr ( 0 , 1 ) == "h" && _d . length == 2 && _d != "hr" ) ) ) {
if ( ! this . _selectionEmpty ( this . _getSelection ( ) ) ) {
_f = true ;
_10 = "new" ;
} else {
_10 = this . _getFirstAncestor ( _a , [ "p" , "h1" , "h2" , "h3" , "h4" , "h5" , "h6" , "h7" ] ) ;
if ( _10 != null ) {
_f = true ;
}
}
} else {
_f = false ;
}
}
}
}
if ( _f ) {
_e = _e . substring ( _e . indexOf ( "." ) , _e . length ) ;
_e = _e . replace ( "." , " " ) ;
if ( _10 == null ) {
if ( this . _selectionEmpty ( this . _getSelection ( ) ) ) {
_10 = this . _getFirstAncestor ( this . _getSelection ( ) , null ) ;
} else {
_10 = "new" ;
_d = "span" ;
}
}
}
var _11 = ( this . _ancestorsWithClasses ( _a , _d , _e ) . length > 0 ? true : false ) ;
var _12 = this . _ancestorsWithClasses ( _a , _d , _e ) ;
if ( _f ) {
var _13 = document . createElement ( "a" ) ;
_13 . _stylist _className = _e . trim ( ) ;
_13 . _stylist _applied = _11 ;
_13 . _stylist _appliedTo = _12 ;
_13 . _stylist _applyTo = _10 ;
_13 . _stylist _applyTag = _d ;
_13 . innerHTML = this . config . css _style [ x ] ;
_13 . href = "javascript:void(0)" ;
var _14 = this ;
_13 . onclick = function ( ) {
if ( this . _stylist _applied == true ) {
_14 . _stylistRemoveClasses ( this . _stylist _className , this . _stylist _appliedTo ) ;
} else {
_14 . _stylistAddClasses ( this . _stylist _applyTo , this . _stylist _applyTag , this . _stylist _className ) ;
}
return false ;
} ;
_13 . style . display = "block" ;
_13 . style . paddingLeft = "3px" ;
_13 . style . paddingTop = "1px" ;
_13 . style . paddingBottom = "1px" ;
_13 . style . textDecoration = "none" ;
if ( _11 ) {
_13 . style . background = "Highlight" ;
_13 . style . color = "HighlightText" ;
}
this . plugins . Stylist . instance . main . appendChild ( _13 ) ;
}
}
} ;
Xinha . prototype . _stylistAddClasses = function ( el , tag , _17 ) {
if ( el == "new" ) {
this . insertHTML ( "<" + tag + " class=\"" + _17 + "\">" + this . getSelectedHTML ( ) + "</" + tag + ">" ) ;
} else {
if ( tag != null && el . tagName . toLowerCase ( ) != tag ) {
var _18 = this . switchElementTag ( el , tag ) ;
if ( typeof el . _stylist _usedToBe != "undefined" ) {
_18 . _stylist _usedToBe = el . _stylist _usedToBe ;
_18 . _stylist _usedToBe [ _18 . _stylist _usedToBe . length ] = { "tagName" : el . tagName , "className" : el . getAttribute ( "class" ) } ;
} else {
_18 . _stylist _usedToBe = [ { "tagName" : el . tagName , "className" : el . getAttribute ( "class" ) } ] ;
}
Xinha . addClasses ( _18 , _17 ) ;
} else {
Xinha . _addClasses ( el , _17 ) ;
}
}
this . focusEditor ( ) ;
this . updateToolbar ( ) ;
2005-12-07 03:37:36 +00:00
} ;
2007-05-31 22:43:05 +00:00
Xinha . prototype . _stylistRemoveClasses = function ( _19 , _1a ) {
for ( var x = 0 ; x < _1a . length ; x ++ ) {
this . _stylistRemoveClassesFull ( _1a [ x ] , _19 ) ;
}
this . focusEditor ( ) ;
this . updateToolbar ( ) ;
2005-12-07 03:37:36 +00:00
} ;
2007-05-31 22:43:05 +00:00
Xinha . prototype . _stylistRemoveClassesFull = function ( el , _1d ) {
if ( el != null ) {
var _1e = el . className . trim ( ) . split ( " " ) ;
var _1f = [ ] ;
var _20 = _1d . split ( " " ) ;
for ( var x = 0 ; x < _1e . length ; x ++ ) {
var _22 = false ;
for ( var i = 0 ; _22 == false && i < _20 . length ; i ++ ) {
if ( _20 [ i ] == _1e [ x ] ) {
_22 = true ;
}
}
if ( _22 == false ) {
_1f [ _1f . length ] = _1e [ x ] ;
}
}
if ( _1f . length == 0 && el . _stylist _usedToBe && el . _stylist _usedToBe . length > 0 && el . _stylist _usedToBe [ el . _stylist _usedToBe . length - 1 ] . className != null ) {
var _24 = el . _stylist _usedToBe [ el . _stylist _usedToBe . length - 1 ] ;
var _25 = Xinha . arrayFilter ( _24 . className . trim ( ) . split ( " " ) , function ( c ) {
if ( c == null || c . trim ( ) == "" ) {
return false ;
}
return true ;
} ) ;
if ( ( _1f . length == 0 ) || ( Xinha . arrayContainsArray ( _1f , _25 ) && Xinha . arrayContainsArray ( _25 , _1f ) ) ) {
el = this . switchElementTag ( el , _24 . tagName ) ;
_1f = _25 ;
} else {
el . _stylist _usedToBe = [ ] ;
}
}
if ( _1f . length > 0 || el . tagName . toLowerCase ( ) != "span" || ( el . id && el . id != "" ) ) {
el . className = _1f . join ( " " ) . trim ( ) ;
} else {
var _27 = el . parentNode ;
var _28 = el . childNodes ;
for ( var x = 0 ; x < _28 . length ; x ++ ) {
_27 . insertBefore ( _28 [ x ] , el ) ;
}
_27 . removeChild ( el ) ;
}
}
2005-12-07 03:37:36 +00:00
} ;
2007-05-31 22:43:05 +00:00
Xinha . prototype . switchElementTag = function ( el , tag ) {
var _2b = el . parentNode ;
var _2c = this . _doc . createElement ( tag ) ;
if ( Xinha . is _ie || el . hasAttribute ( "id" ) ) {
_2c . setAttribute ( "id" , el . getAttribute ( "id" ) ) ;
}
if ( Xinha . is _ie || el . hasAttribute ( "style" ) ) {
_2c . setAttribute ( "style" , el . getAttribute ( "style" ) ) ;
}
var _2d = el . childNodes ;
for ( var x = 0 ; x < _2d . length ; x ++ ) {
_2c . appendChild ( _2d [ x ] . cloneNode ( true ) ) ;
}
_2b . insertBefore ( _2c , el ) ;
_2c . _stylist _usedToBe = [ el . tagName ] ;
_2b . removeChild ( el ) ;
this . selectNodeContents ( _2c ) ;
return _2c ;
2005-12-07 03:37:36 +00:00
} ;
2007-05-31 22:43:05 +00:00
Xinha . prototype . _getAncestorsClassNames = function ( sel ) {
var _30 = this . _activeElement ( sel ) ;
if ( _30 == null ) {
_30 = ( Xinha . is _ie ? this . _createRange ( sel ) . parentElement ( ) : this . _createRange ( sel ) . commonAncestorContainer ) ;
}
var _31 = [ ] ;
while ( _30 ) {
if ( _30 . nodeType == 1 ) {
var _32 = _30 . className . trim ( ) . split ( " " ) ;
for ( var x = 0 ; x < _32 . length ; x ++ ) {
_31 [ _31 . length ] = _32 [ x ] ;
}
if ( _30 . tagName . toLowerCase ( ) == "body" ) {
break ;
}
if ( _30 . tagName . toLowerCase ( ) == "table" ) {
break ;
}
}
_30 = _30 . parentNode ;
}
return _31 ;
2005-12-07 03:37:36 +00:00
} ;
2007-05-31 22:43:05 +00:00
Xinha . prototype . _ancestorsWithClasses = function ( sel , tag , _36 ) {
var _37 = [ ] ;
var _38 = this . _activeElement ( sel ) ;
if ( _38 == null ) {
try {
_38 = ( Xinha . is _ie ? this . _createRange ( sel ) . parentElement ( ) : this . _createRange ( sel ) . commonAncestorContainer ) ;
}
catch ( e ) {
return _37 ;
}
}
var _39 = _36 . trim ( ) . split ( " " ) ;
while ( _38 ) {
if ( _38 . nodeType == 1 && _38 . className ) {
if ( tag == null || _38 . tagName . toLowerCase ( ) == tag ) {
var _36 = _38 . className . trim ( ) . split ( " " ) ;
var _3a = true ;
for ( var i = 0 ; i < _39 . length ; i ++ ) {
var _3c = false ;
for ( var x = 0 ; x < _36 . length ; x ++ ) {
if ( _39 [ i ] == _36 [ x ] ) {
_3c = true ;
break ;
}
}
if ( ! _3c ) {
_3a = false ;
break ;
}
}
if ( _3a ) {
_37 [ _37 . length ] = _38 ;
}
}
if ( _38 . tagName . toLowerCase ( ) == "body" ) {
break ;
}
if ( _38 . tagName . toLowerCase ( ) == "table" ) {
break ;
}
}
_38 = _38 . parentNode ;
}
return _37 ;
2005-12-07 03:37:36 +00:00
} ;
2007-05-31 22:43:05 +00:00
Xinha . ripStylesFromCSSFile = function ( URL ) {
var css = Xinha . _geturlcontent ( URL ) ;
return Xinha . ripStylesFromCSSString ( css ) ;
2005-12-07 03:37:36 +00:00
} ;
2007-05-31 22:43:05 +00:00
Xinha . ripStylesFromCSSString = function ( css ) {
RE _comment = /\/\*(.|\r|\n)*?\*\//g ;
RE _rule = /\{(.|\r|\n)*?\}/g ;
css = css . replace ( RE _comment , "" ) ;
css = css . replace ( RE _rule , "," ) ;
css = css . split ( "," ) ;
var _41 = { } ;
for ( var x = 0 ; x < css . length ; x ++ ) {
if ( css [ x ] . trim ( ) ) {
_41 [ css [ x ] . trim ( ) ] = css [ x ] . trim ( ) ;
}
}
return _41 ;
2005-12-07 03:37:36 +00:00
} ;
2007-05-31 22:43:05 +00:00
function Stylist ( _43 , _44 ) {
this . editor = _43 ;
var _45 = this ;
}
Stylist . _pluginInfo = { name : "Stylist" , version : "1.0" , developer : "James Sleeman" , developer _url : "http://www.gogo.co.nz/" , c _owner : "Gogo Internet Services" , license : "HTMLArea" , sponsor : "Gogo Internet Services" , sponsor _url : "http://www.gogo.co.nz/" } ;
Stylist . prototype . onGenerateOnce = function ( ) {
var _46 = this . editor ;
var _47 = this ;
if ( typeof _46 . config . css _style != "undefined" && Xinha . objectProperties ( _46 . config . css _style ) . length != 0 ) {
_46 . _stylist = null ;
_46 . _stylist = _46 . addPanel ( "right" ) ;
Xinha . addClass ( _46 . _stylist , "stylist" ) ;
this . caption = document . createElement ( "h1" ) ;
this . caption . innerHTML = Xinha . _lc ( "Styles" , "Stylist" ) ;
_46 . _stylist . appendChild ( this . caption ) ;
this . main = document . createElement ( "div" ) ;
this . main . style . overflow = "auto" ;
this . main . style . height = this . editor . _framework . ed _cell . offsetHeight - this . caption . offsetHeight + "px" ;
_46 . _stylist . appendChild ( this . main ) ;
Xinha . freeLater ( this , "caption" ) ;
Xinha . freeLater ( this , "main" ) ;
_46 . notifyOn ( "modechange" , function ( e , _49 ) {
switch ( _49 . mode ) {
case "text" :
_46 . hidePanel ( _46 . _stylist ) ;
break ;
case "wysiwyg" :
_46 . showPanel ( _46 . _stylist ) ;
break ;
}
} ) ;
_46 . notifyOn ( "panel_change" , function ( e , _4b ) {
switch ( _4b . action ) {
case "show" :
var _4c = _47 . main . offsetHeight - _4b . panel . offsetHeight ;
_47 . main . style . height = ( ( _4c > 0 ) ? _47 . main . offsetHeight - _4b . panel . offsetHeight : 0 ) + "px" ;
_46 . _stylist . style . height = _47 . caption . offsetHeight + "px" ;
_46 . sizeEditor ( ) ;
break ;
case "hide" :
_47 . resize ( ) ;
break ;
}
} ) ;
_46 . notifyOn ( "before_resize" , function ( ) {
_46 . _stylist . style . height = _47 . caption . offsetHeight + "px" ;
} ) ;
_46 . notifyOn ( "resize" , function ( ) {
_47 . resize ( ) ;
} ) ;
}
2005-12-07 03:37:36 +00:00
} ;
2007-05-31 22:43:05 +00:00
Stylist . prototype . resize = function ( ) {
var _4d = this . editor ;
var _4e = _4d . _stylist . parentNode ;
var _4f = _4e . offsetHeight ;
for ( var i = 0 ; i < _4e . childNodes . length ; ++ i ) {
if ( _4e . childNodes [ i ] == _4d . _stylist || ! _4e . childNodes [ i ] . offsetHeight ) {
continue ;
}
_4f -= _4e . childNodes [ i ] . offsetHeight ;
}
_4d . _stylist . style . height = _4f + "px" ;
this . main . style . height = _4f - this . caption . offsetHeight + "px" ;
2005-09-30 02:25:07 +00:00
} ;
2007-05-31 22:43:05 +00:00
Stylist . prototype . onUpdateToolbar = function ( ) {
if ( this . editor . _stylist ) {
if ( this . _timeoutID ) {
window . clearTimeout ( this . _timeoutID ) ;
}
var e = this . editor ;
this . _timeoutID = window . setTimeout ( function ( ) {
e . _fillStylist ( ) ;
} , 250 ) ;
}
2005-12-07 03:37:36 +00:00
} ;
2007-05-31 22:43:05 +00:00