Skip to content

Instantly share code, notes, and snippets.

View mockee's full-sized avatar

Yan Shi mockee

View GitHub Profile
@mockee
mockee / gist:3708247
Created September 12, 2012 17:13
Using `define.js` with `Do.js`
// Using new `define.js`
// https://gist.github.com/3699759
// Set namespace & module exports aliases
define.ns('Ark');
define.config({
'mods/cookie': 'Ark.cookie',
'mods/ajax': 'Ark.ajax'
});
@mockee
mockee / media_capture_api.html
Created October 4, 2012 13:40
iOS6 Media Capture API test
<!doctype html>
<html>
<head>
<title>Media Cpature API</title>
</head>
<body>
<input type="file" accept="image/*" capture="camera">
<input type="file" accept="video/*" capture="camcorder">
<input type="file" accept="audio/*" capture="microphone">
</body>
@mockee
mockee / profile.js
Created October 31, 2012 09:15
mod/profile
define('widget/profile', [
'jquery'
, 'mod/cookie'
, 'mod/template'
], function($, cookie, template) {
var body = $('body')
, base = $('#ark-console')
, header = $('.profile-hd')
, dataContainer = $('.profile-bd')
, statusBar = $('.profile-ft')
@mockee
mockee / backbone-sync.js
Created October 31, 2012 09:14
Override Backbone.sync
define('mod/bbsync', [
'underscore'
, 'mod/ajax'
], function(_, Ajax) {
function sync(method, model, options) {
var url = model.url, data
url = _.isFunction(url) ? model.url() : url
data = method === 'create' || method === 'update'
? model.toJSON() : {}
@mockee
mockee / ajax.js
Created October 31, 2012 09:16
mod/ajax
define('mod/ajax', [
'jquery',
'mod/cookie'
], function($, cookie) {
$ = $ || window.$;
cookie = cookie || Ark.cookie;
function ajax() {
var args = arguments,
options = args[args.length - 1] || {};
@mockee
mockee / uaParser.js
Last active October 12, 2015 07:27
/*jshint node:true*/
function parse(uaStr) {
var agent = {
platform: {}
, browser: {}
, engine: {}
}
var ua = uaStr
@mockee
mockee / random_avatars.js
Created November 2, 2012 17:21
Showing avatars in random positions.
;(function() {
var doc = document
, frag = doc.createDocumentFragment()
, ids = [
{ id: 'tifafa', name: 'tifa' }
, { id: 'godlikejay', name: 'Jay' }
, { id: 'mockee', name: 'mockee' }
].sort(function() {
return Math.random() > 0.5
})
@mockee
mockee / gist:4232210
Created December 7, 2012 09:52
Replace `click` with `tap`
/*global _:true, Backbone:true*/
define('backbone', ['backbone-src'], function() {
if (!('ontouchstart' in window)) { return Backbone }
require('mod/touch', function(){})
var delegateEventSplitter = /^(\S+)\s*(.*)$/
function getValue(object, prop) {
if (!(object && object[prop])) { return null }
return _.isFunction(object[prop]) ? object[prop]() : object[prop]
/*jshint eqnull:true*/
define('jquery', ['jquery-src'], function() {
if (!('ontouchstart' in window)) { return jQuery }
require('mod/touch', function(){})
function returnFalse() {
return false
}
jQuery.fn.extend({
define(function() {
var bodyTag
, win = window
, doc = document
, docElement = doc.documentElement
function hideAddressBar(isPad) {
if (screen.width > 980 || screen.height > 980) { return }
if (win.navigator.standalone === true) { return }