Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
50
gaia/apps/email/js/cards/mixins/data-event.js
Executable file
50
gaia/apps/email/js/cards/mixins/data-event.js
Executable file
|
|
@ -0,0 +1,50 @@
|
|||
'use strict';
|
||||
define(function () {
|
||||
var slice = Array.prototype.slice;
|
||||
|
||||
return {
|
||||
templateInsertedCallback: function () {
|
||||
slice.call(this.querySelectorAll('[data-event]'))
|
||||
.forEach(function (node) {
|
||||
var parent = node;
|
||||
// Make sure the node is not nested in another component.
|
||||
while ((parent = parent.parentNode)) {
|
||||
if (parent.nodeName.indexOf('-') !== -1) {
|
||||
if (parent !== this) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Value is of type 'name:value,name:value',
|
||||
// with the :value part optional.
|
||||
node.dataset.event.split(',').forEach(function (pair) {
|
||||
var evtName, method,
|
||||
parts = pair.split(':');
|
||||
|
||||
if (!parts[1]) {
|
||||
parts[1] = parts[0];
|
||||
}
|
||||
evtName = parts[0].trim();
|
||||
method = parts[1].trim();
|
||||
|
||||
if (typeof this[method] !== 'function') {
|
||||
throw new Error('"' + method +
|
||||
'" is not a function, cannot bind with data-event');
|
||||
}
|
||||
|
||||
node.addEventListener(evtName, function(evt) {
|
||||
// Treat these events as private to the
|
||||
// custom element.
|
||||
evt.stopPropagation();
|
||||
return this[method](evt);
|
||||
}.bind(this), false);
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
});
|
||||
28
gaia/apps/email/js/cards/mixins/data-prop.js
Executable file
28
gaia/apps/email/js/cards/mixins/data-prop.js
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
'use strict';
|
||||
define(function () {
|
||||
return {
|
||||
templateInsertedCallback: function () {
|
||||
var node, parent,
|
||||
nodes = this.querySelectorAll('[data-prop]'),
|
||||
length = nodes.length;
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
// Make sure the node is not nested in another component.
|
||||
node = nodes[i];
|
||||
parent = node;
|
||||
while ((parent = parent.parentNode)) {
|
||||
if (parent.nodeName.indexOf('-') !== -1) {
|
||||
if (parent !== this) {
|
||||
node = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (node && parent) {
|
||||
this[node.dataset.prop] = nodes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
39
gaia/apps/email/js/cards/mixins/dom_evt.js
Executable file
39
gaia/apps/email/js/cards/mixins/dom_evt.js
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
'use strict';
|
||||
define(function () {
|
||||
/**
|
||||
* domEvt can be used with data-event="" to translate internal template
|
||||
* events into custom events emitted from the custom element that contains
|
||||
* the template element that triggered the event. Use like so in the template:
|
||||
*
|
||||
* <a href="#" data-event="click:domEvt" data-domevt-name="headerClose">
|
||||
*
|
||||
* When that a tag receives a click event (from itself or its children) then
|
||||
* domEvt will convert that to a custom event "headerClose", dispatched on the
|
||||
* custom element.
|
||||
*
|
||||
* data-domevt-detail="something" allows passing a "detail" string in the
|
||||
* custom event that will have the value of "something".
|
||||
*/
|
||||
return {
|
||||
domEvt: function (event) {
|
||||
var target = event.currentTarget,
|
||||
eventName = target.dataset.domevtName,
|
||||
eventData = {},
|
||||
eventDetail = target.dataset.domevtDetail;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
if (!eventName) {
|
||||
throw new Error('No data-domevt-name on element <' +
|
||||
target.nodeName + ' class="' + target.className + '">');
|
||||
}
|
||||
|
||||
if (eventDetail) {
|
||||
eventData.detail = eventDetail;
|
||||
}
|
||||
|
||||
this.dispatchEvent(new CustomEvent(eventName, eventData));
|
||||
}
|
||||
};
|
||||
});
|
||||
Loading…
Reference in a new issue