Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
update commonplace (bug 1072998)
  • Loading branch information
ngokevin committed Sep 25, 2014
1 parent 68ea4b7 commit 4900d06
Show file tree
Hide file tree
Showing 54 changed files with 6,544 additions and 5,261 deletions.
2 changes: 1 addition & 1 deletion src/.commonplace
@@ -1 +1 @@
{"version":"0.2.1","ignore":["media/js/urls.js"]}
{"version":"0.4.22","ignore":["media/js/urls.js"]}
114 changes: 0 additions & 114 deletions src/media/js/cache.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/media/js/assert.js → src/media/js/commonplace/assert.js
Expand Up @@ -41,10 +41,10 @@ define('assert', ['underscore'], function(_) {
}

function _contain(haystack, needle) {
if (_.isObject(haystack)) {
return needle in haystack;
} else if (_.isString(haystack)) {
if (_.isString(haystack) || _.isArray(haystack)) {
return haystack.indexOf(needle) !== -1;
} else if (_.isObject(haystack)) {
return needle in haystack;
} else {
return _.contains(haystack, needle);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ define('assert', ['underscore'], function(_) {
// If it's an array, convert it to an array-like object.
// Require.js freaks out when you give it an array, but this
// should work in (almost) all circumstances.
x[1] = _.extend({}, x[1])
x[1] = _.extend({}, x[1]);
}

return x;
Expand Down
119 changes: 119 additions & 0 deletions src/media/js/commonplace/buckets.js
@@ -0,0 +1,119 @@
define('buckets', [], function() {

function build() {
function noop() {return '';}

var aelem = document.createElement('audio');
var velem = document.createElement('video');

// Compatibilty with PhantomJS, which doesn't implement canPlayType
if (!('canPlayType' in aelem)) {
velem = aelem = {canPlayType: noop};
}

var prefixes = ['moz', 'webkit', 'ms'];

function prefixed(property, context) {
if (!context) {
context = window;
}
try {
if (context[property] !== undefined) {
return context[property];
}
} catch(e) {
return false;
}
// Camel-case it.
property = property[0].toUpperCase() + property.substr(1);

for (var i = 0, e; e = prefixes[i++];) {
try {
if (context[e + property] !== undefined) {
return context[e + property];
}
} catch(err) {
return false;
}
}
}

var has_gum = prefixed('getUserMedia', navigator);
if (has_gum && navigator.mozGetUserMedia) {
// Gecko 18's gum is a noop.
try {
navigator.mozGetUserMedia(); // Should throw a TypeError.
has_gum = false;
} catch(e) {}
}

var audiocontext = window.webkitAudioContext || window.AudioContext;
var has_audiocontext = !!(audiocontext);

return [
navigator.mozApps !== undefined,
navigator.mozApps !== undefined && navigator.mozApps.installPackage !== undefined,
navigator.mozPay !== undefined,
// FF 18 and earlier throw an exception on this key
(function() {try{return !!window.MozActivity;} catch(e) {return false;}})(),
window.ondevicelight !== undefined,
window.ArchiveReader !== undefined,
navigator.battery !== undefined,
navigator.mozBluetooth !== undefined,
navigator.mozContacts !== undefined,
navigator.getDeviceStorage !== undefined,
(function() { try{return window.mozIndexedDB || window.indexedDB;} catch(e) {return false;}})(),
navigator.geolocation !== undefined && navigator.geolocation.getCurrentPosition !== undefined,
navigator.addIdleObserver !== undefined && navigator.removeIdleObserver,
navigator.mozConnection !== undefined && (navigator.mozConnection.metered === true || navigator.mozConnection.metered === false),
navigator.mozNetworkStats !== undefined,
window.ondeviceproximity !== undefined,
navigator.mozPush !== undefined || navigator.push !== undefined,
window.ondeviceorientation !== undefined,
navigator.mozTime !== undefined,
navigator.vibrate !== undefined,
navigator.mozFM !== undefined || navigator.mozFMRadio !== undefined,
navigator.mozSms !== undefined,
!!((window.ontouchstart !== undefined) || window.DocumentTouch && document instanceof DocumentTouch),
window.screen.width <= 540 && window.screen.height <= 960, // qHD support
!!aelem.canPlayType('audio/mpeg').replace(/^no$/, ''), // mp3 support
!!(window.Audio), // Audio Data API
has_audiocontext, // Web Audio API
!!velem.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/,''), // H.264
!!velem.canPlayType('video/webm; codecs="vp8"').replace(/^no$/,''), // WebM
!!prefixed('cancelFullScreen', document), // Full Screen API
!!prefixed('getGamepads', navigator), // Gamepad API
!!(prefixed('persistentStorage') || window.StorageInfo), // Quota Management API
// WebRTC:
has_gum && !prefixed('cameras', navigator), // Can take photos
has_gum && has_audiocontext &&
!!((new audiocontext()).createMediaStreamSource), // Can record audio
has_gum && false, // XXX: Google WebRTC issue 2088
window.MediaStream !== undefined,
window.DataChannel !== undefined,
prefixed('RTCPeerConnection'),
prefixed('SpeechSynthesisEvent'), // WebSpeech Synthesis
prefixed('SpeechInputEvent'), // WebSpeech Input
prefixed('requestPointerLock', document.documentElement), // Pointer lock
prefixed('notification', navigator), // TODO: window.webkitNotifications?
prefixed('alarms', navigator), // Alarms
(new XMLHttpRequest()).mozSystem !== undefined, // mozSystemXHR
prefixed('TCPSocket', navigator), // mozTCPSocket/mozTCPSocketServer
prefixed('mozInputMethod', navigator),
prefixed('mozMobileConnections', navigator)
];
}

var capabilities = []; // build(); - deactivated for now because of false positives and performance problems on some devices. See bug 1003266.
var profile = parseInt(capabilities.map(function(x) {return !!x ? '1' : '0';}).join(''), 2).toString(16);
// Add a count.
profile += '.' + capabilities.length;
// Add a version number.
profile += '.4';

return {
capabilities: capabilities,
profile: profile
};

});
38 changes: 25 additions & 13 deletions src/media/js/builder.js → src/media/js/commonplace/builder.js
@@ -1,6 +1,6 @@
define('builder',
['log', 'templates', 'models', 'requests', 'settings', 'z', 'nunjucks.compat'],
function(log, nunjucks, models, requests, settings, z) {
['log', 'jquery', 'templates', 'models', 'requests', 'settings', 'z', 'nunjucks.compat'],
function(log, $, nunjucks, models, requests, settings, z) {

var console = log('builder');
var SafeString = nunjucks.require('runtime').SafeString;
Expand Down Expand Up @@ -38,12 +38,8 @@ define('builder',
parent.removeChild(to_replace);
}

function fire(el, event_name) {
var args = Array.prototype.slice.call(arguments, 2);
var e = document.createEvent('Event');
e.initEvent.apply(e, [event_name, true, false].concat(args));
el.dispatchEvent(e);
return e;
function fire(el, event_name, data) {
$(el).trigger(event_name, data);
}

function Builder() {
Expand Down Expand Up @@ -89,8 +85,11 @@ define('builder',
}, false);
}

function trigger_fragment_loaded(id) {
fire(page, 'fragment_loaded', id || null);
function trigger_fragment_loaded(data) {
fire(page, 'fragment_loaded', data);
}
function trigger_fragment_load_failed(data) {
fire(page, 'fragment_load_failed', data);
}

// This pretends to be the nunjucks extension that does the magic.
Expand All @@ -104,7 +103,7 @@ define('builder',
if ('as' in signature && 'key' in signature) {
request = models(signature.as).get(url, signature.key, pool.get);
} else {
request = pool.get(url);
request = pool.get(url, !!signature.nocache);
}

if ('id' in signature) {
Expand Down Expand Up @@ -175,6 +174,11 @@ define('builder',
}
// We can't do this for requests which have no pluck
// and aren't an array. :(

// Update the model cache in the background (bug 995288).
pool.get(url).done(function(data) {
models(signature.as).cast(data);
});
}
});

Expand All @@ -186,7 +190,9 @@ define('builder',

if (signature.paginate) {
pool.done(function() {
make_paginatable(injector, document.getElementById(uid), signature.paginate);
setTimeout(function() {
make_paginatable(injector, document.getElementById(uid), signature.paginate);
});
});
}
return request;
Expand All @@ -208,7 +214,7 @@ define('builder',
make_paginatable(injector, el, signature.paginate);
}

trigger_fragment_loaded(signature.id || null);
trigger_fragment_loaded({context: context, signature: signature});

}).fail(function(xhr, text, code, response) {
if (!replace) {
Expand All @@ -220,6 +226,7 @@ define('builder',
context.ctx.error = code;
el.innerHTML = except ? except() : error_template;
}
trigger_fragment_load_failed({context: context, signature: signature});
});
return request;
};
Expand Down Expand Up @@ -248,6 +255,11 @@ define('builder',
});
} else {
var done = function(data) {
if (signature.filters) {
signature.filters.forEach(function(filterName) {
data = env.filters[filterName](data);
});
}
document.getElementById(uid).innerHTML = data;
};
request.done(done).fail(function() {
Expand Down

0 comments on commit 4900d06

Please sign in to comment.