fix Makefile and move utilities to js/utils.js

pull/16/head
posativ 12 years ago
parent a753045f8b
commit 525a2828c5

@ -1,13 +1,14 @@
all:
ISSO = "isso/js"
all: js
init:
cd isso/js
ender build jeesh
git clone https://github.com/posativ/promisejs.git
ender add promisejs
git clone https://github.com/posativ/promisejs.git $(ISSO)/promise.js
(cd $(ISSO) && ender build jeesh)
(cd $(ISSO) && ender add promise.js)
rm -rf $(ISSO)/promise.js
js:
cat isso/js/ender.js isso/js/isso.js > _.js
yuicompressor --type js --charset utf-8 _.js -o isso/js/embed.js
rm _.js
cat $(ISSO)/ender.js $(ISSO)/isso.js $(ISSO)/utils.js > $(ISSO)/_.js
yuicompressor --type js --charset utf-8 $(ISSO)/_.js -o $(ISSO)/embed.js
rm $(ISSO)/_.js

@ -9,75 +9,10 @@
* with `isso`.
*/
/* utility functions -- JS Y U SO STUPID?
*
* read(cookie): return `cookie` string if set
* format(date): human-readable date formatting
* brew(array): similar to DOMinate essentials
*/
// var prefix = "/comments";
var prefix = "";
function read(cookie) {
return (document.cookie.match('(^|; )' + cookie + '=([^;]*)') || 0)[2]
};
function format(date) {
/*!
* JavaScript Pretty Date
* Copyright (c) 2011 John Resig (ejohn.org)
* Licensed under the MIT and GPL licenses.
*/
var diff = (((new Date()).getTime() - date.getTime()) / 1000),
day_diff = Math.floor(diff / 86400);
if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31)
return;
return day_diff == 0 && (
diff < 60 && "just now" ||
diff < 120 && "1 minute ago" ||
diff < 3600 && Math.floor(diff / 60) + " minutes ago" ||
diff < 7200 && "1 hour ago" ||
diff < 86400 && Math.floor(diff / 3600) + " hours ago") ||
day_diff == 1 && "Yesterday" ||
day_diff < 7 && day_diff + " days ago" ||
day_diff < 31 && Math.ceil(day_diff / 7) + " weeks ago";
}
function brew(arr) {
/*
* Element creation utility. Similar to DOMinate, but with a slightly different syntax:
* brew([TAG, {any: attribute, ...}, 'Hello World', ' Foo Bar', ['TAG', 'Hello World'], ...])
* --> <TAG any="attribute">Hello World Foo Bar<TAG>Hello World</TAG></TAG>
*/
var rv = document.createElement(arr[0]);
for (var i = 1; i < arr.length; i++) {
if (arr[i] instanceof Array) {
rv.appendChild(brew(arr[i]));
} else if (typeof(arr[i]) == "string") {
rv.appendChild(document.createTextNode(arr[i]));
} else {
attrs = arr[i] || {};
for (var k in attrs) {
if (!attrs.hasOwnProperty(k)) continue;
rv.setAttribute(k, attrs[k]);
}
}
};
return rv;
}
/*
* isso specific helpers to create, modify, delete and receive comments
*/

@ -0,0 +1,65 @@
/* Copyright 2012, Martin Zimmermann <info@posativ.org>. All rights reserved.
* License: BSD Style, 2 clauses. See isso/__init__.py.
*
* utility functions -- JS Y U SO STUPID?
*
* read(cookie): return `cookie` string if set
* format(date): human-readable date formatting
* brew(array): similar to DOMinate essentials
*/
function read(cookie) {
return (document.cookie.match('(^|; )' + cookie + '=([^;]*)') || 0)[2]
};
function format(date) {
/*!
* JavaScript Pretty Date
* Copyright (c) 2011 John Resig (ejohn.org)
* Licensed under the MIT and GPL licenses.
*/
var diff = (((new Date()).getTime() - date.getTime()) / 1000),
day_diff = Math.floor(diff / 86400);
if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31)
return;
return day_diff == 0 && (
diff < 60 && "just now" ||
diff < 120 && "1 minute ago" ||
diff < 3600 && Math.floor(diff / 60) + " minutes ago" ||
diff < 7200 && "1 hour ago" ||
diff < 86400 && Math.floor(diff / 3600) + " hours ago") ||
day_diff == 1 && "Yesterday" ||
day_diff < 7 && day_diff + " days ago" ||
day_diff < 31 && Math.ceil(day_diff / 7) + " weeks ago";
}
function brew(arr) {
/*
* Element creation utility. Similar to DOMinate, but with a slightly different syntax:
* brew([TAG, {any: attribute, ...}, 'Hello World', ' Foo Bar', ['TAG', 'Hello World'], ...])
* --> <TAG any="attribute">Hello World Foo Bar<TAG>Hello World</TAG></TAG>
*/
var rv = document.createElement(arr[0]);
for (var i = 1; i < arr.length; i++) {
if (arr[i] instanceof Array) {
rv.appendChild(brew(arr[i]));
} else if (typeof(arr[i]) == "string") {
rv.appendChild(document.createTextNode(arr[i]));
} else {
attrs = arr[i] || {};
for (var k in attrs) {
if (!attrs.hasOwnProperty(k)) continue;
rv.setAttribute(k, attrs[k]);
}
}
};
return rv;
}

@ -6,6 +6,7 @@
<!-- script type="text/javascript" src="/js/embed.js"></script -->
<script type="text/javascript" src="/js/ender.js"></script>
<script type="text/javascript" src="/js/isso.js"></script>
<script type="text/javascript" src="/js/utils.js"></script>
<style type="text/css">
body {
margin: 0 auto;

Loading…
Cancel
Save