1
1
/**
2
2
*
3
- * Copyright (c) 2007 Sam Collett (http://www.texotela.co.uk)
3
+ * Copyright (c) 2007, 2009 Sam Collett (http://www.texotela.co.uk)
4
4
* Licensed under the MIT License:
5
5
* http://www.opensource.org/licenses/mit-license.php
6
6
*
7
- * Version 1 .0
7
+ * Version 2 .0
8
8
* Demo: http://www.texotela.co.uk/code/jquery/focusfields/
9
- *
10
- * $LastChangedDate: 2007-06-19 10:29:30 +0100 (Tue, 19 Jun 2007) $
11
- * $Rev: 2108 $
12
9
*/
13
10
14
11
( function ( $ ) {
@@ -41,8 +38,8 @@ $.fn.focusFields = $.fn.focusfields = function(oColour, oWidth, bgColour, textCo
41
38
oColour = oColour || "#9cc" ;
42
39
oWidth = oWidth || 2 ;
43
40
var $this = $ ( this ) ;
44
- this . oldbgcolour = $this . css ( "background-color" ) || "#fff" ;
45
- this . oldtextcolour = $this . css ( "color" ) || "#000" ;
41
+ $ this. data ( "oldbgcolor" , $this . css ( "background-color" ) || "#fff" )
42
+ . data ( " oldtextcolour" , $this . css ( "color" ) || "#000" ) ;
46
43
bgColour = bgColour || this . oldbgcolour ;
47
44
textColour = textColour || this . oldtextcolour ;
48
45
var isIE = false ;
@@ -53,32 +50,27 @@ $.fn.focusFields = $.fn.focusfields = function(oColour, oWidth, bgColour, textCo
53
50
{
54
51
var outlineElement = document . createElement ( "span" ) ;
55
52
outlineElement . className = "outline" ;
56
- $this . focus (
53
+ $this . data ( "borderCssOff" , {
54
+ "background-color" : $this . parent ( ) . css ( "background-color" ) || "#fff" ,
55
+ "padding" : oWidth + "px"
56
+ } )
57
+ . data ( "borderCssOn" , { "background-color" : oColour } )
58
+ . focus (
57
59
function ( )
58
60
{
59
- $ ( this . parentNode ) . css ( this . parentNode . borderCss . on ) ;
61
+ $ ( this . parentNode ) . css ( $ this. data ( "borderCssOn" ) ) ;
60
62
$ ( this ) . css ( { backgroundColor : bgColour , color : textColour } ) ;
61
63
}
62
64
)
63
65
. blur (
64
66
function ( )
65
67
{
66
- $ ( this . parentNode ) . css ( this . parentNode . borderCss . off ) ;
67
- $ ( this ) . css ( { backgroundColor : this . oldbgcolour , color : this . oldtextcolour } ) ;
68
+ $ ( this . parentNode ) . css ( $ this. data ( "borderCssOff" ) ) ;
69
+ $ ( this ) . css ( { backgroundColor : $ this. data ( "oldbgcolor" ) , color : $ this. data ( " oldtextcolour" ) } ) ;
68
70
}
69
71
) ;
70
- outlineElement . borderCss = {
71
- off :
72
- {
73
- backgroundColor : $this . parent ( ) . css ( "background-color" ) || "#fff" ,
74
- padding : oWidth + "px"
75
- }
76
- , on :
77
- {
78
- backgroundColor : oColour
79
- }
80
- } ;
81
- $ ( outlineElement ) . css ( outlineElement . borderCss . off ) ;
72
+
73
+ $ ( outlineElement ) . css ( $this . data ( "borderCssOff" ) ) ;
82
74
// remove existing wrapper if reapplied
83
75
if ( $this . parent ( ) [ 0 ] . className == "outline" )
84
76
{
@@ -91,18 +83,14 @@ $.fn.focusFields = $.fn.focusfields = function(oColour, oWidth, bgColour, textCo
91
83
else
92
84
{
93
85
// apply a margin equal to the width of the outline (to prevent overlap)
94
- $this . css ( { margin : oWidth + "px" } ) ;
95
- this . outlineCss = {
96
- off :
97
- {
98
- outlineStyle : "solid" ,
99
- outlineWidth : oWidth + "px"
100
- }
101
- , on :
102
- {
103
- outlineColor : oColour
104
- }
105
- } ;
86
+ $this . css ( { margin : oWidth + "px" } )
87
+ . data ( "outlineCssOff" , {
88
+ "outline-style" : "solid" ,
89
+ "outline-width" : oWidth + "px"
90
+ } )
91
+ . data ( "outlineCssOn" , {
92
+ "outline-color" : oColour
93
+ } ) ;
106
94
var $parent = $this . parent ( ) , parentBG ;
107
95
do
108
96
{
@@ -112,18 +100,20 @@ $.fn.focusFields = $.fn.focusfields = function(oColour, oWidth, bgColour, textCo
112
100
}
113
101
while ( parentBG == "transparent" )
114
102
if ( parentBG == "transparent" ) parentBG = "#fff" ;
115
- this . outlineCss . off . outlineColor = parentBG ;
116
- $this . css ( this . outlineCss . off )
103
+ $this . data ( "outlineCssOff" , {
104
+ "outline-color" : parentBG
105
+ } )
106
+ . css ( $this . data ( "outlineCssOff" ) )
117
107
. focus (
118
108
function ( )
119
109
{
120
- $ ( this ) . css ( this . outlineCss . on ) . css ( { backgroundColor : bgColour , color : textColour } ) ;
110
+ $ ( this ) . css ( $ this. data ( "outlineCssOn" ) ) . css ( { backgroundColor : bgColour , color : textColour } ) ;
121
111
}
122
112
)
123
113
. blur (
124
114
function ( )
125
115
{
126
- $ ( this ) . css ( this . outlineCss . off ) . css ( { backgroundColor : this . oldbgcolour , color : this . oldtextcolour } ) ;
116
+ $ ( this ) . css ( $ this. data ( "outlineCssOff" ) ) . css ( { backgroundColor : $ this. data ( " oldbgcolour" ) , color : $ this. data ( " oldtextcolour" ) } ) ;
127
117
}
128
118
) ;
129
119
}
0 commit comments