Skip to content

Instantly share code, notes, and snippets.

// I need to use $progress into a callback like this:
callbacks.update = function(data) {
if (data.response !== null) {
if (data.response < 100) {
$progress.custom.update({
completed: data.response
});
return true;
} else {
var DOM = (function() {
var maps = {};
maps.$progressMap = {};
maps.$previewMap = {};
function updateProgress(options) {
if (typeof options !== 'object') {
return;
}
(function($) {
var $uploader = $('#uploader')
, $feedback = $('#feedback')
, $uploadForm = $('#upload-form')
, $imagePreviews = $('#image-previews')
, $imageErrors = $('#image-errors')
, $imageOrder = $('#image-order')
, $files = $('#files')
, $uid = $('#uid')
, $uploaded = $('#uploaded')
function handleFileSelect(event) {
// upload files
$uploadForm.submit();
var requestId = $('#uid').val();
setTimeout(function () {
updateProgress(requestId);
}, 10);
$feedback.fadeIn();
@rich97
rich97 / gist:1308837
Created October 24, 2011 11:43
CMS concept.

Introduction

Today’s CMS systems work by providing an environment for a developer to work in. You modify the data in the admin panel and them CMS provides a method of inserting the HTML it generates into your templates.

However, therein lies the problem -- the output is generated by the CMS. The CMS should exist to provide a user friendly abstraction to the websites dynamic content. It should not tell the frontend how to represent that content.

To anyone reading this, please be aware that any examples I give will be framed within the context of the MVC pattern and more specifically the Lithium PHP framework. Why? Because these are the tools I love to use at the time of writing this document, although there is no reason that this couldn’t be adapted.

Proposed solution

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Test</title>
<style type="text/css" media="screen">
#list {
list-style:none;
// SERVER
var gameSet = new GameSet();
var io = require('socket.io')
, express = require('express')
, app = express.createServer();
app.listen(8080);
var sio = io.listen(app);
// ...
function image(path, fn) {
$(new Image()).load(function() {
if (typeof fn === 'function') {
fn($(this));
}
})
.error(function () {
console.error('Unable to load image: ' + imgBasePath + path);
// This is what v.next looks like: ["What is the nickname of Newcastle United?", Object { 7056f36f-43a1-4cca-8f6a-1766fc137cbd="The Birds", 61596ba8-ce83-47d2-a5d0-faed180e387a="The Seagulls", f8e95d46-4898-499d-b81c-2110a8583725="The Magpies"}]
var o = {};
console.log(v.next);
var next = v.next;
o.question = next[0];
o.answer = next[1];
/**
* next is undefined
// I don't like this:
/*
socket.on('answer', function(answer, fn) {
socket.get('game', function(ge, g) {
socket.get('score', function(se, score) {
*/
// this is much nicer, I could even make a function to keep it DRY
var test;
socket.get('socket_var', function(err, socket_variable) {
test = socket_variable;