Skip to content

Instantly share code, notes, and snippets.

@ne-sachirou
Created February 24, 2011 03:33
Show Gist options
  • Save ne-sachirou/841702 to your computer and use it in GitHub Desktop.
Save ne-sachirou/841702 to your computer and use it in GitHub Desktop.
AzureaUtil.js #AzureaScript
// @author = http://c4se.sakura.ne.jp/profile/ne.html
// @date = 2011-02-24
// @site =
// @license = public domain
var AzureaUtil = {};
AzureaUtil.event = {};
AzureaUtil.time = {};
(function() {
function mixin(hash1, // @param Hash:
hash2, // @param Hash:
overwrite) { // @param Boolean=true:
var key;
if (typeof overwrite === 'undefined') {
overwrite = true;
}
for (key in hash2) {
if (overwrite || typeof hash1[key] === 'undefined') {
hash1[key] = hash2[key];
}
}
}
AzureaUtil.mixin = mixin;
var PreProcessTimelineStatuses = [],
PreProcessTimelineStatus = [],
PreFilterProcessTimelineStatus = [],
PostFilterProcessTimelineStatus = [],
PostProcessTimelineStatus = [],
PostProcessTimelineStatuses = [],
PreSendUpdateStatus = [],
PostSendUpdateStatus = [],
ReceiveFavorite = [];
function addEventListener(eventname, // @param String:
fun) { // @param Function:
var listener = eval(eventname),
i = -1;
while (listener[++i]) {
if (listener[i] === fun) {
listener.splice(i, 1);
}
}
listener.push(fun);
}
function removeEventListener(eventname, // @param String:
fun) { // @param Function:
var listener = eval(eventname),
i = -1;
while (listener[++i]) {
if (listener[i] === fun) {
listener.splice(i, 1);
break;
}
}
}
mixin(AzureaUtil.event, {
'PreProcessTimelineStatuses': PreProcessTimelineStatuses,
'PreProcessTimelineStatus': PreProcessTimelineStatus,
'PreFilterProcessTimelineStatus': PreFilterProcessTimelineStatus,
'PostFilterProcessTimelineStatus': PostFilterProcessTimelineStatus,
'PostProcessTimelineStatus': PostProcessTimelineStatus,
'PostProcessTimelineStatuses': PostProcessTimelineStatuses,
'PreSendUpdateStatus': PreSendUpdateStatus,
'PostSendUpdateStatus': PostSendUpdateStatus,
'ReceiveFavorite': ReceiveFavorite,
'addEventListener': addEventListener,
'removeEventListener': removeEventListener
});
var timeout_list = {},// {id: [time, fun]}
timeinterval_list = {};// {id: [time, fun, interval]}
// timeevent_list = (function() {
// var timeevent_list,
// timeEvent;
//
// for () {
// timeEvent = System.settings.getValue('user.AzureaUtil', 'TimeEvent' + i);
// timeevent_list[]
// }
// return timeevent_list;
//})();
function attainSchedule() {
var now = new Date().getTime(),
id;
for (id in timeout_list) {
if (timeout_list[id][0] <= now) {
timeout_list[id][1]();
delete timeout_list[id];
}
}
for (id in timeinterval_list) {
if (timeinterval_list[id][0] <= now) {
timeinterval_list[id][0] += timeinterval_list[id][2];
timeinterval_list[id][1]();
}
}
//for (id in timeevent_list) {
// if (timeevent_list[id][0] <= now) {
// timeevent_list[id][1]();
// delete timeevent_list[id];
// System.settings.getValue('user.AzureaUtil', 'TimeEvent' + i);
// }
//
//}
}
addEventListener('PreProcessTimelineStatus', function(status) {
attainSchedule();
});
addEventListener('ReceiveFavorite', function(source, target, target_object) {
attainSchedule();
});
function setTimeOut(fun, // @param Function:
ms) { // @param Number:
// @return Number:
var id = Math.floor(Math.random() * new Date().getTime()).toString(36);
timeout_list[id] = [new Date().getTime() + ms, fun];
return id;
}
function clearTimeOut(id) { // @param Number:
delete timeout_list[id];
}
function setTimeInterval(fun, // @param Function:
ms) { // @param Number:
// @return Number:
var id = Math.floor(Math.random() * new Date().getTime()).toString(36);
timeinterval_list[id] = [new Date().getTime() + ms, fun, ms];
return id
}
function clearTimeInterval(id) { // @param Number:
delete timeinterval_list[id];
}
//function setTimeEvent(fun, // @param Function:
// ms) { // @param Number:
// // @return Number:
//
//}
//
//
//function clearTimeEvent() {}
mixin(AzureaUtil.time, {
'setTimeOut': setTimeOut,
'clearTimeOut': clearTimeOut,
'setTimeInterval': setTimeInterval,
'clearTimeInterval': clearTimeInterval
});
})();
//function PreProcessTimelineStatuses() {}
function PreProcessTimelineStatus(status) {
var listener = AzureaUtil.event.PreProcessTimelineStatus,
i = -1;
while (listener[++i]) {
listener[i](status);
}
}
function PreFilterProcessTimelineStatus(status) {
var listener = AzureaUtil.event.PreFilterProcessTimelineStatus,
i = -1, r, flag = false;
while (listener[++i]) {
r = listener[i](status);
flag = flag || r;
}
return flag;
}
//function PostFilterProcessTimelineStatus() {}
//function PostProcessTimelineStatus() {}
//function PostProcessTimelineStatuses() {}
function PreSendUpdateStatus(status) {
var listener = AzureaUtil.event.PreSendUpdateStatus,
i = -1, r, flag = false;
while (listener[++i]) {
r = listener[i](status);
flag = flag || r;
}
return flag;
}
function PostSendUpdateStatus() {
var listener = AzureaUtil.event.PostSendUpdateStatus,
i = -1;
while (listener[++i]) {
listener[i]();
}
}
function ReceiveFavorite(source,
target,
target_object) {
var listener = AzureaUtil.event.ReceiveFavorites,
i = -1;
while (listener[++i]) {
listener[i](source, target, target_object);
}
}
@ne-sachirou
Copy link
Author

https://gist.github.com/841702/fa494e581ce770430a7dfec9e77eae5f9c9c9a7d
単独で使うAzureaScriptではありません。各AzureaScriptの先頭辺りに、直接此のScriptを書きこんで使って下さい。
event管理とtimer管理の機能が有ります。
TODO: 解説記事を書く。

@ne-sachirou
Copy link
Author

AzureaUtil作りました #AzureaScript #js - c4se記:さっちゃんですよ☆ http://d.hatena.ne.jp/Kureduki_Maari/20110226/1298651872
解説記事

ne-sachirou/AzureaVim - GitHub https://github.com/ne-sachirou/AzureaVim にprojectを移動しました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment