Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/karma/js/lesson.js
blob: 8a6591c82b66db9680ebc54ccb08d85c92e56ca5 (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
$(function(){

var k = Karma();
k.ready(function(){
  var url = ' ' + window.location;
  var temp = url.split('/')
  var course = temp.pop().slice(7,9); //course_xx.html
  var subject = temp.pop();
  subjectid = 'link' + subject;
  /* set title in head */
  $('head title')
      .empty()
      .text(subject);
  /* set navbar: linkHome link'subject', title,  linkQuit */
  $('<div>',{
      class:'linkHome topbtn_left',
      id:'linkHome',
      title:'Home',
      click:function(){
         window.location = 'http://localhost:8008/content/index.html';
      }
      })
      .appendTo('#header');
  cls = 'link' + subjectid + ' ' + 'topbtn_left';
  $('<div>',{
      class:cls,
      id:subjectid,
      title:subject,
      click:function(){
         location='http://localhost:8008/content/courses.html'
      }
      })
      .appendTo('#header');
  $('<div>',{
      id:'lesson_title'
      })
      .text(subject)
      .appendTo('#header');
  $('<img>',{
      src:'../karma/image/title_block_lt.png',
      class:'title_img'
      })
      .prependTo('#lesson_title');
  $('<img>',{
      src:'../karma/image/title_block_rt.png',
      class:'title_img'
      })
      .appendTo('#lesson_title');
  $('<div>',{
      class:'linkQuit topbtn_right',
      id:'linkQuit',
      title:'Quit',
      click:function(){
        window.close();
      } 
      })
      .appendTo('#header');

  function setPath(xy){
    pth = "unavailable.html";
    if (xy[3] == "EPaath"){
      pth = "../../../src/FrameWork.html#" + xy[4];
    };
    if (xy[3] == "basic"){
      pth = xy[4] + '/index.html';
    };
    if (xy[3] == 'Karma'){
      pth = xy[4] + '/index.html';
    };
    if (xy[3] == 'Sugar'){
      pth = xy[4] + '/index.html';
    };
    window.location = pth;
  };

  function drawMilestone(ctx, cellsize, x, y, capcolor, number){
    var capcolor;
    x = activity[6];
    y = activity[7];
    capcolor = activity[5];
    ctx.fillStyle = 'chartreuse';
    ctx.fillRect(x,y-cellsize,cellsize,cellsize);
    ctx.fillStyle = 'black';
    ctx.fillText(number, x + (cellsize * 0.3), y-(cellsize * 0.4), cellsize);
    ctx.beginPath();
    ctx.moveTo(x, y-cellsize);
    ctx.arc(x+0.5*cellsize,y-cellsize,0.5*cellsize,Math.PI,0,0);
    ctx.closePath();
    ctx.fillStyle = capcolor;
    ctx.fill();
    ctx.fillStyle = 'yellow';
  };

  function drawarrow(ctx, x, y, sz) {
    ctx.fillStyle = 'black'
    ctx.fillRect(x-sz*4/5,y+sz/8,sz/2,sz/8);
    ctx.moveTo(x-sz/2,y);
    ctx.lineTo(x-sz/5,y+sz/8);
    ctx.moveTo(x-sz/2,y+sz/2);
    ctx.lineTo(x-sz/5,y+sz/8);
    ctx.stroke();
  };

  function draw(){  
    var canvas = document.getElementById('ladder');  
    if (canvas.getContext){
      var ctx = canvas.getContext('2d');
      var cells = 6;
      var rows = 2 + (activities.length / cells);
      var maxx = 1200;
      var cellsize = 64;
      var sz = cellsize;
      var maxy = rows * 1.5 * cellsize;
      if (maxy < 673){
        maxy = 673;;
      };
      canvas.setAttribute('width', maxx);
      canvas.setAttribute('height', maxy);
      var x = 0;
      var y = 0;
      var odd = 1;
      var xstart = 1.7 * cellsize;
      var ystart = maxy - cellsize;
      var row = 0;
      var cell = 0;
      var id = -1;
      var ix = 0;
      var idm = 0;
      var activityNumber = 0;
      var flag = 0;
      var il = ""
      var xy;
      var pth;
      var count = 0;
      // set up callback           
      $("canvas").click(function($e) {
        // find out which activity in activities was clicked
        x = $e.pageX
        y = $e.pageY
        ctx.fillStyle = 'black'
        $.each(activities, function() {
          xy = this;
          //if a hit, download if necessary, go to unit
          hit =    (x > xy[6]) 
                && (x < xy[6] + cellsize) 
                && (y < xy[7])
                && (y > xy[7] - cellsize)
          if(hit) {
            if(mode == 'Faculty') {
              setPath(xy);
            }else if (xy[5] == 'red'){
              setPath(xy);
            };
          };
        });
      });
      // now draw ladder
      ctx.font = "14pt Arial";
      ctx.textAlign = "center";
      x = xstart;
      y = ystart;
      ctx.beginPath();
      sz = cellsize;
      drawarrow(ctx, x, y, sz);
      offset=0;
      delta = 1;
      for(row=0;row<rows;row++){
        if (activityNumber == activities.length) {
          break;
        };
        if (offset == 0){
          x = xstart;
        }else{
          x = xstart+offset-sz*3/2;
        };
        for(cell=0;cell<cells;cell++){
          xsave = x;
          if (activityNumber < activities.length){
            ctx.fillStyle = 'yellow';
            ctx.fillRect(x,y,sz*3/2, sz/4);
            activity = activities[activityNumber];
            activity.push(x)
            activity.push(y)
            activities[activityNumber] = activity;
            if(''+activity[0] == '0'){  
                drawMilestone(ctx, cellsize, x, y, activity[5],''+activity[1]);
            }else{
                // draw flag
                ctx.moveTo(x,y);
                ctx.lineTo(x,y-cellsize);
                ctx.strokeStyle = 'black';
                ctx.stroke();
                ctx.fillStyle = activity[5];
                ctx.fillRect(x,y-cellsize,cellsize,cellsize/20);
                ctx.textAlign='center';
                ctx.font = '20pt Arial';
                ctx.fillStyle = 'black';
                ctx.fillText(''+activity[1],x+cellsize/2,y-cellsize/2-10,cellsize);
            }
            activityNumber += 1;
            x = x + 3/2*sz;
            if (delta > 0) {
              if (cell+1 < cells) {
                ctx.fillstyle='yellow';
                ctx.fillRect(x,y,sz,sz/4);
                x = xsave + sz*5/2;
              }else{
                x = xsave + sz*3/2;
              };
            }else{
              if (cell > 0) {
                ctx.fillStyle = 'yellow';
                ctx.fillRect(x,y,sz,sz/4);
              };
              if (cell+1<cells){
                x = xsave - sz*5/2;
              }else{
                x = xsave-sz*3/2;
              };
            };
          };
        };
        if ((row + 1 < rows) && (activity < activities.length)) {
          if (row % 2 == 0) {
            ctx.beginPath();
            ctx.moveTo(x,y);
            ctx.arc(x, y-cellsize, cellsize, Math.PI/2, 0, 1);
            ctx.arc(x, y-cellsize, 1.25*cellsize, 0, Math.PI*3/2, 1);
            ctx.arc(x, y-cellsize, cellsize, Math.PI*3/2, 0, 0);
            ctx.arc(x, y-cellsize, 1.25*cellsize, 0, Math.PI/2, 0);
            ctx.closePath();
            ctx.fillStyle='yellow'
            ctx.fill()
          }else{
            x = xstart;
            ctx.beginPath();
            ctx.moveTo(x,y);
            ctx.arc(x, y-cellsize, cellsize, Math.PI/2, Math.PI, 0);
            ctx.arc(x, y-cellsize, 1.25*cellsize, Math.PI, Math.PI*3/2, 0);
            ctx.arc(x, y-cellsize, cellsize, Math.PI*3/2, Math.PI, 1);
            ctx.arc(x, y-cellsize, 1.25*cellsize, Math.PI, Math.PI/2, 1);
            ctx.closePath();
            ctx.fillStyle='yellow'
            ctx.fill()
          }
        }
        y = y - 2.25 * cellsize; 
        offset = x - xstart;
        delta = -delta;
      }
    }else{
      alert('canvas not defined');
    };
  };
 
  draw();

}); //end karma ready

}); // end document ready