Skip to content

Instantly share code, notes, and snippets.

@pwilms
Created March 23, 2016 18:28
Show Gist options
  • Save pwilms/1382d606c05671584c58 to your computer and use it in GitHub Desktop.
Save pwilms/1382d606c05671584c58 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
attributeBindings: ["draggable"],
classNames: ["a-handle"],
draggable: true,
dragStart(e) {
this.set("origX", e.originalEvent.clientX);
this.set("origWidth", parseInt(this.$().closest("th,td").css("width").replace(/px$/, ""), 10));
},
drag(e) {
const newX = e.originalEvent.clientX;
if (newX > 0) {
this.sendAction("resize",
this.get("origWidth") - this.get("origX") + newX);
}
},
dragEnd(e) {
this.set("origX", false);
}
});
import Ember from 'ember';
const {
computed
} = Ember;
export default Ember.Controller.extend({
actions: {
resize(column, width) {
if (width > 10) {
const fullWidth = this.get("fullWidth");
if (column === "a") {
let newBWidth = fullWidth - this.get("cWidthPx") - width;
if (newBWidth > 10) {
this.set("aWidthPx", width);
this.set("bWidthPx", newBWidth);
}
} else {
let newCWidth = fullWidth - this.get("aWidthPx") - width;
if (newCWidth > 10) {
this.set("bWidthPx", width);
this.set("cWidthPx", newCWidth);
}
}
}
}
},
aWidthPx: 150,
aWidth: computed("aWidthPx", function() {
return `width: ${this.get("aWidthPx")}px`;
}),
bWidthPx: 150,
bWidth: computed("bWidthPx", function() {
return `width: ${this.get("bWidthPx")}px`;
}),
cWidthPx: 150,
cWidth: computed("cWidthPx", function() {
return `width: ${this.get("cWidthPx")}px`;
}),
fullWidth: 450,
fullWidthStyle: computed("fullWidth", function() {
return `width: ${this.get("fullWidth")}px`;
}),
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<table style={{fullWidthStyle}}>
<tr>
<th style={{aWidth}}>a{{a-handle resize=(action "resize" "a")}}</th>
<th style={{bWidth}}>b{{a-handle resize=(action "resize" "b")}}</th>
<th style={{cWidth}}>c</th>
</tr>
<tr>
<td><div class="ellipsis" style={{aWidth}}>Lorem Ipsum Lorem Ipsum Lorem Ipsum</div></td>
<td>B</td>
<td>C</td>
</tr>
</table>
{{outlet}}
<br>
<br>
* {
box-sizing: border-box;
}
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.a-handle {
display:block;
width:1px;
height: 100%;
background: transparent;
float: right;
cursor: ew-resize
}
table {
border-collapse: collapse;
}
table, td, th, tr {
padding: 0;
margin: 0;
}
td, th {
border: 1px solid black
}
.ellipsis{
width: auto;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
{
"version": "0.6.5",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment