Skip to content

Commit 6b2a4a9

Browse files
author
SamWM
committed
Update version number
1 parent 50ad385 commit 6b2a4a9

File tree

1 file changed

+29
-39
lines changed

1 file changed

+29
-39
lines changed

focusfields/jquery.focusfields.js

+29-39
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
/**
22
*
3-
* Copyright (c) 2007 Sam Collett (http://www.texotela.co.uk)
3+
* Copyright (c) 2007, 2009 Sam Collett (http://www.texotela.co.uk)
44
* Licensed under the MIT License:
55
* http://www.opensource.org/licenses/mit-license.php
66
*
7-
* Version 1.0
7+
* Version 2.0
88
* 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 $
129
*/
1310

1411
(function($) {
@@ -41,8 +38,8 @@ $.fn.focusFields = $.fn.focusfields = function(oColour, oWidth, bgColour, textCo
4138
oColour = oColour || "#9cc";
4239
oWidth = oWidth || 2;
4340
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");
4643
bgColour = bgColour || this.oldbgcolour;
4744
textColour = textColour || this.oldtextcolour;
4845
var isIE = false;
@@ -53,32 +50,27 @@ $.fn.focusFields = $.fn.focusfields = function(oColour, oWidth, bgColour, textCo
5350
{
5451
var outlineElement = document.createElement("span");
5552
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(
5759
function()
5860
{
59-
$(this.parentNode).css(this.parentNode.borderCss.on);
61+
$(this.parentNode).css($this.data("borderCssOn"));
6062
$(this).css({backgroundColor: bgColour, color: textColour});
6163
}
6264
)
6365
.blur(
6466
function()
6567
{
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")});
6870
}
6971
);
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"));
8274
// remove existing wrapper if reapplied
8375
if($this.parent()[0].className == "outline")
8476
{
@@ -91,18 +83,14 @@ $.fn.focusFields = $.fn.focusfields = function(oColour, oWidth, bgColour, textCo
9183
else
9284
{
9385
// 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+
});
10694
var $parent = $this.parent(), parentBG;
10795
do
10896
{
@@ -112,18 +100,20 @@ $.fn.focusFields = $.fn.focusfields = function(oColour, oWidth, bgColour, textCo
112100
}
113101
while (parentBG == "transparent")
114102
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"))
117107
.focus(
118108
function()
119109
{
120-
$(this).css(this.outlineCss.on).css({backgroundColor: bgColour, color: textColour});
110+
$(this).css($this.data("outlineCssOn")).css({backgroundColor: bgColour, color: textColour});
121111
}
122112
)
123113
.blur(
124114
function()
125115
{
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")});
127117
}
128118
);
129119
}

0 commit comments

Comments
 (0)