-
Notifications
You must be signed in to change notification settings - Fork 0
/
coursePluginDemo.html
122 lines (80 loc) · 3.12 KB
/
coursePluginDemo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Course Editor</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="kaushik ganguly">
<link href='http://fonts.googleapis.com/css?family=Strait' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="courseEditor.js"></script>
<script type="text/javascript" src="coursePlayer.js"></script>
<script type="text/javascript">
var courses=new Array();
var courseEdit;
var coursePlay;
$(document).ready(function(){
refreshCourses();
$("#addNewCourse").click(function(){
courseEdit=new courseEditor(null,function(course){
console.log(course);
courses.push(course);
localStorage.setItem("courses",JSON.stringify(courses));
refreshCourses();
});
});
});
function refreshCourses()
{
$("#courseListing").empty();
courses=new Array();
if(localStorage.getItem("courses"))
{
var cc=JSON.parse(localStorage.getItem("courses")) ;
$.each(cc,function(i,v){
courses.push(v);
});
}
$.each(courses,function(i,v){
var li=document.createElement("li");
$("<label>"+(i+1)+".</label><label dataindex=\""+i+"\">"+v.courseName+"</label><button dataindex=\""+i+"\" class=\"editCourse\">edit</button><button dataindex=\""+i+"\" class=\"playCourse\">play</button>").appendTo($(li));
$(li).children(".editCourse").css({'background-color':'gray','border':'1px solid gray','color':'white'}).click(function(){
var index=parseInt($(this).prev().attr("dataindex"));
console.log(parseInt($(this).prev().attr("dataindex")));
courseEdit=new courseEditor(courses[index],function(course){
console.log(course);
var tmp=new Array();
self=this;
$.each(courses,function(i,v){
console.log("i:"+i+" dataindex: "+index)
if(i==index)
tmp.push(course);
else
tmp.push(v);
});
localStorage.removeItem("courses");
console.log('tmp :'+tmp);
localStorage.setItem("courses",JSON.stringify(tmp));
console.log(localStorage.getItem("courses"));
refreshCourses();
});
});
$(li).children(".playCourse").css({'background-color':'green','border':'1px solid green','color':'white'}).click(function(){
coursePlay=new coursePlayer(courses[parseInt($(this).prev().prev().attr("dataindex"))],function(coursee){
//document.location=document.location;
});
});
$(li).css({'padding':'10px','width':'800px','background-color':'#eee'});
$(li).children().css({'margin':'5px'});
$(li).appendTo("#courseListing");
});
}
</script>
</head>
<body>
<button id="addNewCourse" style="background-color:green;border:1px solid green;color:white;">+add new course</button>
<ul id="courseListing" style="list-style:none;margin:0px;padding:0px;width:800px;height:600px;overflow:auto;">
</ul>
</body>
</html>