mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-27 20:36:33 -04:00
Add hide/show method to manipulators.
This commit is contained in:
+2
-2
@@ -10,9 +10,9 @@ module.exports = function() {
|
|||||||
*/
|
*/
|
||||||
function toggleBackground() {
|
function toggleBackground() {
|
||||||
if (this.get()) {
|
if (this.get()) {
|
||||||
Clay.getItemByAppKey('background').enable();
|
Clay.getItemByAppKey('colorTest').show();
|
||||||
} else {
|
} else {
|
||||||
Clay.getItemByAppKey('background').disable();
|
Clay.getItemByAppKey('colorTest').hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,22 @@ function enable() {
|
|||||||
return this.trigger('enabled');
|
return this.trigger('enabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {ClayEvents}
|
||||||
|
*/
|
||||||
|
function hide() {
|
||||||
|
this.$element.set('+hide');
|
||||||
|
return this.trigger('hide');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {ClayEvents}
|
||||||
|
*/
|
||||||
|
function show() {
|
||||||
|
this.$element.set('-hide');
|
||||||
|
return this.trigger('show');
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
html: {
|
html: {
|
||||||
get: function() {
|
get: function() {
|
||||||
@@ -26,7 +42,9 @@ module.exports = {
|
|||||||
set: function(value) {
|
set: function(value) {
|
||||||
this.$manipulatorTarget.set('innerHTML', value);
|
this.$manipulatorTarget.set('innerHTML', value);
|
||||||
return this.trigger('change');
|
return this.trigger('change');
|
||||||
}
|
},
|
||||||
|
hide: hide,
|
||||||
|
show: show
|
||||||
},
|
},
|
||||||
val: {
|
val: {
|
||||||
get: function() {
|
get: function() {
|
||||||
@@ -37,7 +55,9 @@ module.exports = {
|
|||||||
return this.trigger('change');
|
return this.trigger('change');
|
||||||
},
|
},
|
||||||
disable: disable,
|
disable: disable,
|
||||||
enable: enable
|
enable: enable,
|
||||||
|
hide: hide,
|
||||||
|
show: show
|
||||||
},
|
},
|
||||||
checked: {
|
checked: {
|
||||||
get: function() {
|
get: function() {
|
||||||
@@ -48,7 +68,9 @@ module.exports = {
|
|||||||
return this.trigger('change');
|
return this.trigger('change');
|
||||||
},
|
},
|
||||||
disable: disable,
|
disable: disable,
|
||||||
enable: enable
|
enable: enable,
|
||||||
|
hide: hide,
|
||||||
|
show: show
|
||||||
},
|
},
|
||||||
radiogroup: {
|
radiogroup: {
|
||||||
get: function() {
|
get: function() {
|
||||||
@@ -61,7 +83,9 @@ module.exports = {
|
|||||||
return this.trigger('change');
|
return this.trigger('change');
|
||||||
},
|
},
|
||||||
disable: disable,
|
disable: disable,
|
||||||
enable: enable
|
enable: enable,
|
||||||
|
hide: hide,
|
||||||
|
show: show
|
||||||
},
|
},
|
||||||
checkboxgroup: {
|
checkboxgroup: {
|
||||||
get: function() {
|
get: function() {
|
||||||
@@ -83,7 +107,9 @@ module.exports = {
|
|||||||
return self.trigger('change');
|
return self.trigger('change');
|
||||||
},
|
},
|
||||||
disable: disable,
|
disable: disable,
|
||||||
enable: enable
|
enable: enable,
|
||||||
|
hide: hide,
|
||||||
|
show: show
|
||||||
},
|
},
|
||||||
color: {
|
color: {
|
||||||
get: function() {
|
get: function() {
|
||||||
@@ -99,6 +125,8 @@ module.exports = {
|
|||||||
return this.trigger('change');
|
return this.trigger('change');
|
||||||
},
|
},
|
||||||
disable: disable,
|
disable: disable,
|
||||||
enable: enable
|
enable: enable,
|
||||||
|
hide: hide,
|
||||||
|
show: show
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+17
-14
@@ -50,6 +50,19 @@ h6 {
|
|||||||
@include font-size(0.8);
|
@include font-size(0.8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strong {
|
||||||
|
@include font-pfdin(medium);
|
||||||
|
color: $color-orange;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: $color-gray-8;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
label {
|
label {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
@@ -83,9 +96,12 @@ label {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hide {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.component {
|
.component {
|
||||||
padding-bottom: $item-spacing-v;
|
padding-bottom: $item-spacing-v;
|
||||||
@include tap-highlight();
|
|
||||||
|
|
||||||
&.disabled {
|
&.disabled {
|
||||||
opacity: 0.25;
|
opacity: 0.25;
|
||||||
@@ -134,19 +150,6 @@ label {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strong {
|
|
||||||
@include font-pfdin(medium);
|
|
||||||
color: $color-orange;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: $color-gray-8;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.inputs {
|
.inputs {
|
||||||
display: block;
|
display: block;
|
||||||
width:100%;
|
width:100%;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var fixture = require('../../fixture');
|
|||||||
describe('manipulators', function() {
|
describe('manipulators', function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string|Clay~ConfigItem} itemType
|
* @param {string|Object} itemType
|
||||||
* @param {*} value
|
* @param {*} value
|
||||||
* @param {*} [expected]
|
* @param {*} [expected]
|
||||||
* @return {void}
|
* @return {void}
|
||||||
@@ -31,7 +31,7 @@ describe('manipulators', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string|Clay~ConfigItem} itemType
|
* @param {string|Object} itemType
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
function testDisable(itemType) {
|
function testDisable(itemType) {
|
||||||
@@ -57,7 +57,7 @@ describe('manipulators', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} itemType
|
* @param {string|Object} itemType
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
function testEnable(itemType) {
|
function testEnable(itemType) {
|
||||||
@@ -84,14 +84,71 @@ describe('manipulators', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string|Object} itemType
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
function testHide(itemType) {
|
||||||
|
describe('.hide()', function() {
|
||||||
|
it('hides the field then triggers a "hide" event', function() {
|
||||||
|
var handlerSpy = sinon.spy();
|
||||||
|
var clayItem = fixture.clayItem(itemType);
|
||||||
|
clayItem.on('hide', handlerSpy);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
clayItem.$element[0].classList.contains('hide'),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
clayItem.hide();
|
||||||
|
assert.strictEqual(
|
||||||
|
clayItem.$element[0].classList.contains('hide'),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
assert.strictEqual(handlerSpy.callCount, 1, 'handler not called once');
|
||||||
|
assert(handlerSpy.calledOn(clayItem), 'handler not called on clayItem');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string|Object} itemType
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
function testShow(itemType) {
|
||||||
|
describe('.show()', function() {
|
||||||
|
it('shows the field then triggers a "show" event', function() {
|
||||||
|
var handlerSpy = sinon.spy();
|
||||||
|
var clayItem = fixture.clayItem(itemType);
|
||||||
|
clayItem.on('show', handlerSpy);
|
||||||
|
|
||||||
|
clayItem.hide();
|
||||||
|
assert.strictEqual(
|
||||||
|
clayItem.$element[0].classList.contains('hide'),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
clayItem.show();
|
||||||
|
assert.strictEqual(
|
||||||
|
clayItem.$element[0].classList.contains('hide'),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
assert.strictEqual(handlerSpy.callCount, 1, 'handler not called once');
|
||||||
|
assert(handlerSpy.calledOn(clayItem), 'handler not called on clayItem');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe('html', function() {
|
describe('html', function() {
|
||||||
testSetGet('footer', 'test123');
|
testSetGet('text', 'test123');
|
||||||
|
testShow('text');
|
||||||
|
testHide('text');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('val', function() {
|
describe('val', function() {
|
||||||
testSetGet('input', 'test321');
|
testSetGet('input', 'test321');
|
||||||
testDisable('input');
|
testDisable('input');
|
||||||
testEnable('input');
|
testEnable('input');
|
||||||
|
testShow('text');
|
||||||
|
testHide('text');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('checked', function() {
|
describe('checked', function() {
|
||||||
@@ -101,6 +158,8 @@ describe('manipulators', function() {
|
|||||||
testSetGet('toggle', 0);
|
testSetGet('toggle', 0);
|
||||||
testDisable('toggle');
|
testDisable('toggle');
|
||||||
testEnable('toggle');
|
testEnable('toggle');
|
||||||
|
testShow('toggle');
|
||||||
|
testHide('toggle');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('radiogroup', function() {
|
describe('radiogroup', function() {
|
||||||
@@ -118,6 +177,8 @@ describe('manipulators', function() {
|
|||||||
testSetGet(item, 'three "quote');
|
testSetGet(item, 'three "quote');
|
||||||
testDisable(item);
|
testDisable(item);
|
||||||
testEnable(item);
|
testEnable(item);
|
||||||
|
testShow(item);
|
||||||
|
testHide(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('checkboxgroup', function() {
|
describe('checkboxgroup', function() {
|
||||||
@@ -136,6 +197,8 @@ describe('manipulators', function() {
|
|||||||
testSetGet(item, false, []);
|
testSetGet(item, false, []);
|
||||||
testDisable(item);
|
testDisable(item);
|
||||||
testEnable(item);
|
testEnable(item);
|
||||||
|
testShow(item);
|
||||||
|
testHide(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('color', function() {
|
describe('color', function() {
|
||||||
@@ -149,5 +212,7 @@ describe('manipulators', function() {
|
|||||||
testSetGet('color', undefined, 0x000000);
|
testSetGet('color', undefined, 0x000000);
|
||||||
testDisable('color');
|
testDisable('color');
|
||||||
testEnable('color');
|
testEnable('color');
|
||||||
|
testShow('color');
|
||||||
|
testHide('color');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user