Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
Fixes sibling placement issue with politespace proxy.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed May 11, 2016
1 parent f99faa3 commit 2ce813c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions demo/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
Default <code>input[type=number]</code> with <code>maxlength="7"</code>.
<input type="number" data-politespace maxlength="7" value="123456">
</label>
<label>
Default <code>input[type=number]</code> with <code>maxlength="7"</code> and a <code>placeholder</code>.
<p>This should be before the form element</p>
<input type="number" data-politespace maxlength="7" placeholder="00000">
<p>This should be after the form element</p>
</label>
<label>
Default textarea
<textarea data-politespace></textarea>
Expand Down
2 changes: 2 additions & 0 deletions src/politespace-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
test( "Input and blur updates proxy", function() {
$( this.pspace.element ).val( "12345678" ).trigger( "input" );
equal( $( this.pspace.element ).val(), "12345678" );
ok( $( this.pspace.element ).prev().is( ".politespace-proxy-val" ), "Proxy value exists." );
ok( $( this.pspace.element ).parent().is( ".politespace-proxy" ), "Proxy exists." );
equal( $( this.pspace.element ).prev().html(), "123 456 78" );
});

Expand Down
10 changes: 8 additions & 2 deletions src/politespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,23 @@
}

var $el = $( "<div>" ).addClass( "politespace-proxy active" );
var $nextSibling = this.$proxyAnchor.next();
var $parent = this.$proxyAnchor.parent();

this.$proxy = $( "<div>" ).css({
this.$proxy = $( "<div>" ).addClass( "politespace-proxy-val" ).css({
font: this.$element.css( "font" ),
"padding-left": sumStyles( this.element, [ "padding-left", "border-left-width" ] ) + "px",
"padding-right": sumStyles( this.element, [ "padding-right", "border-right-width" ] ) + "px",
top: sumStyles( this.element, [ "padding-top", "border-top-width", "margin-top" ] ) + "px"
});
$el.append( this.$proxy );
$el.append( this.$proxyAnchor );
$parent.append( $el );

if( $nextSibling.length ) {
$el.insertBefore( $nextSibling );
} else {
$parent.append( $el );
}

this.updateProxy();
};
Expand Down

0 comments on commit 2ce813c

Please sign in to comment.