Skip to content

Instantly share code, notes, and snippets.

View c3ry5's full-sized avatar

Cerys Williams c3ry5

  • London, United Kingdom
View GitHub Profile
@c3ry5
c3ry5 / read.cookie.js
Last active November 4, 2018 11:26
Read and write cookies
@c3ry5
c3ry5 / backbone.replaceHash.js
Created July 5, 2013 10:25
override backbone.js _updateHash to replace location.replace for old devices with window.history.replaceState
var oldBrowser = (reContainsAll([/mozilla\/5.0/i, /android/i, /applewebkit/i], navigator.userAgent)
|| reContainsAll([/mozilla\/5.0/i, /iphone os (5|4|3|2|1){1}/i, /applewebkit/i], navigator.userAgent))
&& !reContainsAll([/chrome/i], navigator.userAgent);
Backbone.History.prototype._updateHash = function(location, fragment, replace) {
var base = location.toString().replace(/(javascript:|#).*$/, '') + '#';
if (replace) {
if (oldBrowser) {
window.history.replaceState({}, document.title, base + fragment);
} else {
@c3ry5
c3ry5 / mixins.sass
Last active December 19, 2015 04:58
Retina sprite generation using sass
@mixin sprite-background($name)
background-repeat: no-repeat
background-image: $standardImg
background-position: sprite-position($sprites, $name)
height: image-height(sprite-file($sprites, $name))
width: image-width(sprite-file($sprites, $name))
@media (-webkit-min-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-device-pixel-ratio: 1.5)
background-image: $retinaImg
background-position: 0 round(nth(sprite-position($sprites2x, $name), 2) / 2)
height: round(image-height(sprite-file($sprites2x, $name)) / 2)
@c3ry5
c3ry5 / detect-touch.js
Created June 18, 2013 15:18
To detect if i device supports touch events with a jquery scroll function
var isTouch = function () {
return 'ontouchend' in document;
}
@c3ry5
c3ry5 / ga-error-tracking.js
Last active November 4, 2018 11:27
crossbrowser tracking js errors using google analytics
window.onerror = (message, filename, lineno, colno, error) => {
function stack() {
return (`${(error.stack).replace(/(\r\n|\n|\r)/gm," ")} in ${navigator.userAgent}`)
}
function nostack() {
return (`${message} on line ${lineno} for ${filename} in ${navigator.userAgent}`)
}
@c3ry5
c3ry5 / detect-webapp.js
Last active November 4, 2018 11:27
detect if the website has been saved as a webapp
const webappDetect = () => ("standalone" in window.navigator) && window.navigator.standalone;