Skip to content

Commit faae1c3

Browse files
committed
Reogranized project & deleted some cruft files
1 parent 3f34eaf commit faae1c3

23 files changed

Lines changed: 1072 additions & 411 deletions

Gruntfile.coffee

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
module.exports = (grunt) ->
22
require('load-grunt-tasks') grunt
33
grunt.file.readJSON('package.json')
4-
4+
5+
# !! Compile configurations
56
License = '/*!Copyright(c) CommentCoreLibrary (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */'
7+
FilterType = "Simple" # "Comment" || "Simple"
8+
# !! End of config area
69

710
CSS = [
811
'src/css/base.css',
912
'src/css/fontalias.css'
1013
]
1114

1215
SRC_CORE = [
13-
'src/CommentFilter.js'
16+
'src/Array.js'
17+
'src/filter/' + FilterType + 'Filter.js'
1418
'src/CommentSpaceAllocator.js'
1519
'src/CommentCoreLibrary.js'
1620
]

build/CommentCoreLibrary.js

Lines changed: 54 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
1-
/**
2-
Comment Filters/Filter Lang
3-
Licensed Under MIT License
4-
**/
1+
/**
2+
* Binary Search Stubs for JS Arrays
3+
* @license MIT
4+
* @author Jim Chen
5+
*/
6+
Array.prototype.bsearch = function(what,how){
7+
if(this.length == 0) return 0;
8+
if(how(what,this[0]) < 0) return 0;
9+
if(how(what,this[this.length - 1]) >=0) return this.length;
10+
var low =0;
11+
var i = 0;
12+
var count = 0;
13+
var high = this.length - 1;
14+
while(low<=high){
15+
i = Math.floor((high + low + 1)/2);
16+
count++;
17+
if(how(what,this[i-1])>=0 && how(what,this[i])<0){
18+
return i;
19+
}else if(how(what,this[i-1])<0){
20+
high = i-1;
21+
}else if(how(what,this[i])>=0){
22+
low = i;
23+
}else
24+
console.error('Program Error');
25+
if(count > 1500) console.error('Too many run cycles.');
26+
}
27+
return -1;
28+
};
529

30+
Array.prototype.binsert = function(what,how){
31+
this.splice(this.bsearch(what,how),0,what);
32+
};
33+
34+
/**
35+
* Comment Filters Module Simplified (only supports modifiers & types)
36+
* @license MIT
37+
* @author Jim Chen
38+
*/
639
function CommentFilter(){
7-
this.rulebook = {"all":[]};
840
this.modifiers = [];
941
this.runtime = null;
1042
this.allowTypes = {
@@ -22,86 +54,16 @@ function CommentFilter(){
2254
}
2355
return cmt;
2456
};
25-
this.isMatchRule = function(cmtData,rule){
26-
switch(rule['operator']){
27-
case '==':if(cmtData[rule['subject']] == rule['value']){return false;};break;
28-
case '>':if(cmtData[rule['subject']] > rule['value']){return false;};break;
29-
case '<':if(cmtData[rule['subject']] < rule['value']){return false;};break;
30-
case 'range':if(cmtData[rule['subject']] > rule.value.min && cmtData[rule['subject']] < rule.value.max){return false;};break;
31-
case '!=':if(cmtData[rule['subject']] != rule.value){return false;}break;
32-
case '~':if(new RegExp(rule.value).test(cmtData[rule[subject]])){return false;}break;
33-
case '!~':if(!(new RegExp(rule.value).test(cmtData[rule[subject]]))){return false;}break;
34-
}
35-
return true;
36-
};
3757
this.beforeSend = function(cmt){
38-
//Check with the rules upon size
39-
var cmtMode = cmt.data.mode;
40-
if(this.rulebook[cmtMode]!=null){
41-
for(var i=0;i<this.rulebook[cmtMode].length;i++){
42-
if(this.rulebook[cmtMode][i].subject == 'width' || this.rulebook[cmtMode][i].subject == 'height'){
43-
if(this.rulebook[cmtMode][i].subject == 'width'){
44-
switch(this.rulebook[cmtMode][i].operator){
45-
case '>':if(this.rulebook[cmtMode][i].value < cmt.offsetWidth)return false;break;
46-
case '<':if(this.rulebook[cmtMode][i].value > cmt.offsetWidth)return false;break;
47-
case 'range':if(this.rulebook[cmtMode][i].value.max > cmt.offsetWidth && this.rulebook[cmtMode][i].min < cmt.offsetWidth)return false;break;
48-
case '==':if(this.rulebook[cmtMode][i].value == cmt.offsetWidth)return false;break;
49-
default:break;
50-
}
51-
}else{
52-
switch(this.rulebook[cmtMode][i].operator){
53-
case '>':if(this.rulebook[cmtMode][i].value < cmt.offsetHeight)return false;break;
54-
case '<':if(this.rulebook[cmtMode][i].value > cmt.offsetHeight)return false;break;
55-
case 'range':if(this.rulebook[cmtMode][i].value.max > cmt.offsetHeight && this.rulebook[cmtMode][i].min < cmt.offsetHeight)return false;break;
56-
case '==':if(this.rulebook[cmtMode][i].value == cmt.offsetHeight)return false;break;
57-
default:break;
58-
}
59-
}
60-
}
61-
}
62-
return true;
63-
}else{return true;}
58+
return cmt;
6459
}
6560
this.doValidate = function(cmtData){
6661
if(!this.allowTypes[cmtData.mode])
6762
return false;
68-
/** Create abstract cmt data **/
69-
var abstCmtData = {
70-
text:cmtData.text,
71-
mode:cmtData.mode,
72-
color:cmtData.color,
73-
size:cmtData.size,
74-
stime:cmtData.stime,
75-
hash:cmtData.hash,
76-
}
77-
if(this.rulebook[cmtData.mode] != null && this.rulebook[cmtData.mode].length > 0){
78-
for(var i=0;i<this.rulebook[cmtData.mode];i++){
79-
if(!this.isMatchRule(abstCmtData,this.rulebook[cmtData.mode][i]))
80-
return false;
81-
}
82-
}
83-
for(var i=0;i<this.rulebook[cmtData.mode];i++){
84-
if(!this.isMatchRule(abstCmtData,this.rulebook[cmtData.mode][i]))
85-
return false;
86-
}
8763
return true;
8864
};
8965
this.addRule = function(rule){
90-
if(this.rulebook[rule.mode + ""] == null)
91-
this.rulebook[rule.mode + ""] = [];
92-
/** Normalize Operators **/
93-
switch(rule.operator){
94-
case 'eq':
95-
case 'equals':
96-
case '=':rule.operator='==';break;
97-
case 'ineq':rule.operator='!=';break;
98-
case 'regex':
99-
case 'matches':rule.operator='~';break;
100-
case 'notmatch':
101-
case 'iregex':rule.operator='!~';break;
102-
}
103-
this.rulebook[rule.mode].push(rule);
104-
return (this.rulebook[rule.mode].length - 1);
66+
10567
};
10668
this.addModifier = function(f){
10769
this.modifiers.push(f);
@@ -139,7 +101,9 @@ function CommentSpaceAllocator(w,h){
139101
};
140102
this.remove = function(cmt){
141103
var tpool = this.pools[cmt.cindex];
142-
tpool.remove(cmt);
104+
var index = tpool.indexOf(cmt);
105+
if(index < 0) return;
106+
tpool.splice(index, 1);
143107
};
144108
this.validateCmt = function(cmt){
145109
cmt.bottom = cmt.offsetTop + cmt.offsetHeight;
@@ -354,44 +318,12 @@ function BottomScrollCommentSpaceAllocator(w,h){
354318
this.remove = function(d){csa.remove(d);};
355319
}
356320

357-
/******
358-
* Comment Core For HTML5 VideoPlayers
359-
* Author : Jim Chen
360-
* Licensing : MIT License
361-
******/
362-
Array.prototype.remove = function(obj){
363-
for(var a = 0; a < this.length;a++)
364-
if(this[a] == obj){
365-
this.splice(a,1);
366-
break;
367-
}
368-
};
369-
Array.prototype.bsearch = function(what,how){
370-
if(this.length == 0) return 0;
371-
if(how(what,this[0]) < 0) return 0;
372-
if(how(what,this[this.length - 1]) >=0) return this.length;
373-
var low =0;
374-
var i = 0;
375-
var count = 0;
376-
var high = this.length - 1;
377-
while(low<=high){
378-
i = Math.floor((high + low + 1)/2);
379-
count++;
380-
if(how(what,this[i-1])>=0 && how(what,this[i])<0){
381-
return i;
382-
}else if(how(what,this[i-1])<0){
383-
high = i-1;
384-
}else if(how(what,this[i])>=0){
385-
low = i;
386-
}else
387-
console.error('Program Error');
388-
if(count > 1500) console.error('Too many run cycles.');
389-
}
390-
return -1;
391-
};
392-
Array.prototype.binsert = function(what,how){
393-
this.splice(this.bsearch(what,how),0,what);
394-
};
321+
/*!
322+
* Comment Core For HTML5 VideoPlayers
323+
* Copyright (c) 2014 Jim Chen
324+
* License: MIT
325+
*/
326+
395327
/****** Load Core Engine Classes ******/
396328
function CommentManager(stageObject){
397329
var __timer = 0;
@@ -423,7 +355,7 @@ function CommentManager(stageObject){
423355
cmt.mode = data.mode;
424356
cmt.data = data;
425357
if(cmt.mode === 17){
426-
358+
427359
}else{
428360
cmt.appendChild(document.createTextNode(data.text));
429361
cmt.innerText = data.text;
@@ -469,7 +401,7 @@ function CommentManager(stageObject){
469401
__timer = 0;
470402
};
471403
}
472-
404+
473405
/** Public **/
474406
CommentManager.prototype.seek = function(time){
475407
this.position = this.timeline.bsearch(time,function(a,b){
@@ -568,7 +500,7 @@ CommentManager.prototype.sendComment = function(data){
568500
//cmt.style.width = (cmt.width + 1) + "px";
569501
//cmt.style.height = (cmt.height - 3) + "px";
570502
cmt.style.left = this.stage.width + "px";
571-
503+
572504
if(this.filter != null && !this.filter.beforeSend(cmt)){
573505
this.stage.removeChild(cmt);
574506
cmt = null;
@@ -602,8 +534,8 @@ CommentManager.prototype.sendComment = function(data){
602534
var COS = Math.cos;
603535
var SIN = Math.sin;
604536
var matrix = [
605-
COS(yr) * COS(zr) , COS(yr) * SIN(zr) , SIN(yr) , 0,
606-
(-SIN(zr)) , COS(zr) , 0 , 0,
537+
COS(yr) * COS(zr) , COS(yr) * SIN(zr) , SIN(yr) , 0,
538+
(-SIN(zr)) , COS(zr) , 0 , 0,
607539
(-SIN(yr) * COS(zr)) , (-SIN(yr) * SIN(zr)) , COS(yr) , 0,
608540
0 , 0 , 0 , 1
609541
];
@@ -657,7 +589,7 @@ CommentManager.prototype.onTimerEvent = function(timePassed,cmObj){
657589
if(cmt.dur == null)
658590
cmt.dur = 4000;
659591
if(cmt.data.alphaFrom != null && cmt.data.alphaTo != null){
660-
cmt.style.opacity = (cmt.data.alphaFrom - cmt.data.alphaTo) *
592+
cmt.style.opacity = (cmt.data.alphaFrom - cmt.data.alphaTo) *
661593
(cmt.ttl/cmt.dur) + cmt.data.alphaTo;
662594
}
663595
if(cmt.mode == 7 && cmt.data.movable){

build/CommentCoreLibrary.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Array.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Binary Search Stubs for JS Arrays
3+
* @license MIT
4+
* @author Jim Chen
5+
*/
6+
Array.prototype.bsearch = function(what,how){
7+
if(this.length == 0) return 0;
8+
if(how(what,this[0]) < 0) return 0;
9+
if(how(what,this[this.length - 1]) >=0) return this.length;
10+
var low =0;
11+
var i = 0;
12+
var count = 0;
13+
var high = this.length - 1;
14+
while(low<=high){
15+
i = Math.floor((high + low + 1)/2);
16+
count++;
17+
if(how(what,this[i-1])>=0 && how(what,this[i])<0){
18+
return i;
19+
}else if(how(what,this[i-1])<0){
20+
high = i-1;
21+
}else if(how(what,this[i])>=0){
22+
low = i;
23+
}else
24+
console.error('Program Error');
25+
if(count > 1500) console.error('Too many run cycles.');
26+
}
27+
return -1;
28+
};
29+
30+
Array.prototype.binsert = function(what,how){
31+
this.splice(this.bsearch(what,how),0,what);
32+
};

src/CCLComment.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/CommentCoreLibrary.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,7 @@
33
* Copyright (c) 2014 Jim Chen
44
* License: MIT
55
*/
6-
Array.prototype.remove = function(obj){
7-
for(var a = 0; a < this.length;a++)
8-
if(this[a] == obj){
9-
this.splice(a,1);
10-
break;
11-
}
12-
};
13-
Array.prototype.bsearch = function(what,how){
14-
if(this.length == 0) return 0;
15-
if(how(what,this[0]) < 0) return 0;
16-
if(how(what,this[this.length - 1]) >=0) return this.length;
17-
var low =0;
18-
var i = 0;
19-
var count = 0;
20-
var high = this.length - 1;
21-
while(low<=high){
22-
i = Math.floor((high + low + 1)/2);
23-
count++;
24-
if(how(what,this[i-1])>=0 && how(what,this[i])<0){
25-
return i;
26-
}else if(how(what,this[i-1])<0){
27-
high = i-1;
28-
}else if(how(what,this[i])>=0){
29-
low = i;
30-
}else
31-
console.error('Program Error');
32-
if(count > 1500) console.error('Too many run cycles.');
33-
}
34-
return -1;
35-
};
36-
Array.prototype.binsert = function(what,how){
37-
this.splice(this.bsearch(what,how),0,what);
38-
};
6+
397
/****** Load Core Engine Classes ******/
408
function CommentManager(stageObject){
419
var __timer = 0;

0 commit comments

Comments
 (0)