Skip to content

Commit bb88a26

Browse files
committed
Fix use of width configuration option
Fetches the $cardContainer using QJ and configured selector before setting the transform style.
1 parent fa0c7eb commit bb88a26

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

example/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
<script>
4040
new Card({
4141
form: document.querySelector('form'),
42-
container: '.card-wrapper'
42+
container: '.card-wrapper',
43+
width: 350
4344
});
4445
</script>
4546
</body>
46-
</html>
47+
</html>

lib/js/card.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ Card = (function() {
11841184
}
11851185

11861186
Card.prototype.render = function() {
1187-
var baseWidth, name, obj, selector, ua, _ref, _ref1;
1187+
var $cardContainer, baseWidth, name, obj, selector, ua, _ref, _ref1;
11881188
QJ.append(this.$container, this.template(this.cardTemplate, extend({}, this.options.messages, this.options.values)));
11891189
_ref = this.options.cardSelectors;
11901190
for (name in _ref) {
@@ -1209,8 +1209,9 @@ Card = (function() {
12091209
}
12101210
}
12111211
if (this.options.width) {
1212-
baseWidth = parseInt(this.$cardContainer.css('width'));
1213-
this.$cardContainer.style.transform = "scale(" + (this.options.width / baseWidth) + ")";
1212+
$cardContainer = QJ(this.options.cardSelectors.cardContainer)[0];
1213+
baseWidth = parseInt($cardContainer.clientWidth);
1214+
$cardContainer.style.transform = "scale(" + (this.options.width / baseWidth) + ")";
12141215
}
12151216
if (typeof navigator !== "undefined" && navigator !== null ? navigator.userAgent : void 0) {
12161217
ua = navigator.userAgent.toLowerCase();

lib/js/jquery.card.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ Card = (function() {
11841184
}
11851185

11861186
Card.prototype.render = function() {
1187-
var baseWidth, name, obj, selector, ua, _ref, _ref1;
1187+
var $cardContainer, baseWidth, name, obj, selector, ua, _ref, _ref1;
11881188
QJ.append(this.$container, this.template(this.cardTemplate, extend({}, this.options.messages, this.options.values)));
11891189
_ref = this.options.cardSelectors;
11901190
for (name in _ref) {
@@ -1209,8 +1209,9 @@ Card = (function() {
12091209
}
12101210
}
12111211
if (this.options.width) {
1212-
baseWidth = parseInt(this.$cardContainer.css('width'));
1213-
this.$cardContainer.style.transform = "scale(" + (this.options.width / baseWidth) + ")";
1212+
$cardContainer = QJ(this.options.cardSelectors.cardContainer)[0];
1213+
baseWidth = parseInt($cardContainer.clientWidth);
1214+
$cardContainer.style.transform = "scale(" + (this.options.width / baseWidth) + ")";
12141215
}
12151216
if (typeof navigator !== "undefined" && navigator !== null ? navigator.userAgent : void 0) {
12161217
ua = navigator.userAgent.toLowerCase();

src/coffee/card.coffee

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ class Card
116116
Payment.formatCardExpiry(@$expiryInput)
117117

118118
if @options.width
119-
baseWidth = parseInt @$cardContainer.css('width')
120-
@$cardContainer.style.transform = "scale(#{@options.width / baseWidth})"
119+
$cardContainer = QJ(@options.cardSelectors.cardContainer)[0]
120+
baseWidth = parseInt($cardContainer.clientWidth)
121+
122+
$cardContainer.style.transform = "scale(#{@options.width / baseWidth})"
121123

122124
# safari can't handle transparent radial gradient right now
123125
if navigator?.userAgent

0 commit comments

Comments
 (0)