1 /************************************************************************/
3 /************************************************************************/
4 /* Copyright (c) 2002 - 2010 */
5 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
14 var ATutor = ATutor || {};
15 ATutor.users = ATutor.users || {};
16 ATutor.users.preferences = ATutor.users.preferences || {};
20 * A function to open a popup window
22 ATutor.poptastic = function (url) {
23 var newwindow=window.open(url,'popup','height=600,width=600,scrollbars=yes,resizable=yes');
32 var getexpirydate = function (nodays) {
33 var Today = new Date();
34 var nomilli = Date.parse(Today);
35 Today.setTime(nomilli + nodays * 24 * 60 * 60 * 1000);
36 return Today.toUTCString();
39 ATutor.setcookie = function (name, value, duration) {
40 document.cookie = name + "=" + escape(value) + ";path=/;expires=" + getexpirydate(duration);;
41 if( !ATutor.getcookie(name) ){
48 ATutor.getcookie = function (cookiename) {
49 var cookiestring = "" + document.cookie;
50 var index1 = cookiestring.indexOf(cookiename);
51 if (index1 == -1 || cookiename == "") {
54 var index2 = cookiestring.indexOf( ';', index1);
56 index2 = cookiestring.length;
58 return unescape(cookiestring.substring(index1 + cookiename.length + 1, index2));
61 //styles block for user preferences
62 //used by ATutor.users.preferences.setStyles
63 ATutor.users.preferences.user_styles =
64 '<style id="pref_style" type="text/css">' +
67 'FG_COLOR BG_COLOR FONT_SIZE FONT_FAMILY' +
69 'h1, h2, h3, h4, h5, h6 {' +
78 '.editor_buttontab {' +
81 '.editor_tab_selected {' +
94 'FG_COLOR BG_COLOR FONT_SIZE FONT_FAMILY' +
100 'FG_COLOR BG_COLOR' +
102 '.test_instruction {' +
103 'FG_COLOR BG_COLOR' +
106 'FG_COLOR BG_COLOR FONT_SIZE FONT_FAMILY'+
109 'FG_COLOR BG_COLOR' +
112 'FG_COLOR BG_COLOR' +
114 'a:link, a:visited, a:active { ' +
115 'FG_COLOR BG_COLOR ' +
117 'a.dropdown-title {' +
118 'FG_COLOR BG_COLOR' +
120 '.button, .button2 {' +
121 'FG_COLOR BG_COLOR' +
123 '.editorsmallbox, .editorlargebox {' +
124 'FG_COLOR BG_COLOR' +
127 'FG_COLOR BG_COLOR FONT_SIZE FONT_FAMILY' +
129 '.prefs_buttontab {' +
130 'FG_COLOR BG_COLOR FONT_SIZE FONT_FAMILY' +
133 'FG_COLOR BG_COLOR FONT_FAMILY' +
135 '.prefs_tab_selected {' +
136 'FG_COLOR BG_COLOR FONT_SIZE FONT_FAMILY' +
139 'FG_COLOR BG_COLOR FONT_FAMILY' +
142 'FG_COLOR BG_COLOR FONT_FAMILY' +
145 'FG_COLOR BG_COLOR' +
148 'FG_COLOR BG_COLOR' +
151 'FG_COLOR BG_COLOR' +
154 'FG_COLOR BG_COLOR' +
157 'FG_COLOR BG_COLOR' +
160 'FG_COLOR BG_COLOR' +
162 'td.dropdown-heading {' +
163 'FG_COLOR BG_COLOR' +
166 'FG_COLOR BG_COLOR' +
168 'td.dropdown a, td.dropdown a:visited {' +
169 'FG_COLOR BG_COLOR' +
171 'td.dropdown strong {' +
172 'FG_COLOR BG_COLOR' +
174 'h5.search-results {' +
175 'FG_COLOR BG_COLOR' +
177 'small.search-info {' +
178 'FG_COLOR BG_COLOR' +
180 'p.search-description {' +
181 'FG_COLOR BG_COLOR' +
184 'FG_COLOR BG_COLOR' +
186 'table.tabbed-table th.tab {' +
187 'FG_COLOR BG_COLOR' +
189 'table.tabbed-table th.selected {' +
190 'FG_COLOR BG_COLOR' +
192 'div#sub-navigation {' +
193 'FG_COLOR BG_COLOR' +
195 'div#sub-navigation strong {' +
196 'FG_COLOR BG_COLOR' +
199 'FG_COLOR BG_COLOR' +
202 'FG_COLOR BG_COLOR' +
205 'FG_COLOR BG_COLOR' +
208 'FG_COLOR BG_COLOR' +
211 'FG_COLOR BG_COLOR' +
214 'FG_COLOR BG_COLOR' +
217 'FG_COLOR BG_COLOR' +
219 'table.data th a {' +
220 'FG_COLOR BG_COLOR' +
222 'table.data tbody th {' +
223 'FG_COLOR BG_COLOR' +
225 'table.data tbody tr.selected {' +
226 'FG_COLOR BG_COLOR' +
228 'table.data tfoot {' +
229 'FG_COLOR BG_COLOR' +
231 'table.data tfoot tr:first-child td {' +
232 'FG_COLOR BG_COLOR' +
234 'table.data tfoot input {' +
235 'FG_COLOR BG_COLOR' +
238 'FG_COLOR BG_COLOR' +
241 'FG_COLOR BG_COLOR' +
244 'FG_COLOR BG_COLOR' +
247 'FG_COLOR BG_COLOR' +
250 'FG_COLOR BG_COLOR' +
253 'FG_COLOR BG_COLOR' +
255 'div.news span.date {' +
256 'FG_COLOR BG_COLOR' +
259 'FG_COLOR BG_COLOR' +
261 'div.dropdown-heading {' +
262 'FG_COLOR BG_COLOR' +
265 'FG_COLOR BG_COLOR' +
268 'FG_COLOR BG_COLOR' +
271 'FG_COLOR BG_COLOR' +
274 'FG_COLOR BG_COLOR' +
276 'div.tabs a.selected {' +
277 'FG_COLOR BG_COLOR' +
280 'FG_COLOR BG_COLOR' +
283 'FG_COLOR BG_COLOR' +
285 'div.box a:visited {' +
286 'FG_COLOR BG_COLOR' +
289 'FG_COLOR BG_COLOR' +
292 'FG_COLOR BG_COLOR' +
295 'FG_COLOR BG_COLOR' +
297 'fieldset#shortcuts {' +
298 'FG_COLOR BG_COLOR' +
301 'FG_COLOR BG_COLOR' +
303 'div#content-test ol ul li{' +
304 'FG_COLOR BG_COLOR' +
306 'div#content-info {' +
307 'FG_COLOR BG_COLOR' +
310 'FG_COLOR BG_COLOR' +
313 'FG_COLOR BG_COLOR' +
315 '#forum-thread li {' +
316 'FG_COLOR BG_COLOR' +
318 '#forum-thread li.even {' +
319 'FG_COLOR BG_COLOR' +
321 '#forum-thread li.odd {' +
322 'FG_COLOR BG_COLOR' +
324 'div.forum-post-ctrl span {' +
325 'FG_COLOR BG_COLOR' +
327 'div.forum-post-content p.date {' +
328 'FG_COLOR BG_COLOR' +
330 'div.forum-paginator{' +
331 'FG_COLOR BG_COLOR' +
333 'div#topnavlistcontainer {' +
334 'FG_COLOR BG_COLOR' +
336 'ul#topnavlist li a {' +
337 'FG_COLOR BG_COLOR' +
340 'FG_COLOR BG_COLOR' +
342 '.crumbcontainer {' +
343 'FG_COLOR BG_COLOR' +
346 'FG_COLOR BG_COLOR' +
348 'ul#topnavlist li a.selected {' +
349 'FG_COLOR BG_COLOR' +
351 'ol#tools>li:hover {' +
352 'FG_COLOR BG_COLOR' +
355 'FG_COLOR BG_COLOR' +
357 'dl.browse-course {' +
358 'FG_COLOR BG_COLOR' +
360 'legend.group_form{' +
361 'FG_COLOR BG_COLOR' +
363 'div.column_equivalent{' +
364 'FG_COLOR BG_COLOR' +
366 'div.resource_box{' +
367 'FG_COLOR BG_COLOR' +
369 'h2.alternatives_to{' +
370 'FG_COLOR BG_COLOR' +
372 'div.alternative_box{' +
373 'FG_COLOR BG_COLOR' +
375 'div.alternative_box legend {' +
376 'FG_COLOR BG_COLOR' +
378 'div.resource_box legend {' +
379 'FG_COLOR BG_COLOR' +
382 'FG_COLOR BG_COLOR' +
385 'FG_COLOR BG_COLOR' +
387 'div.input-form div.row {' +
388 'FG_COLOR BG_COLOR' +
390 'input[type=checkbox]{' +
391 'FG_COLOR BG_COLOR' +
393 'div.input-form div.buttons input {' +
394 'FG_COLOR BG_COLOR' +
396 'div.input-form div.row_alternatives {' +
397 'FG_COLOR BG_COLOR' +
399 'a:active, a:hover, a:focus, .highlight, a.highlight {' +
400 'HL_COLOR FG_COLOR }' +
401 'ul#topnavlist li a:hover, ul#topnavlist li a:focus, ul#topnavlist li a.active {' +
402 'HL_COLOR FG_COLOR' +
405 'background-color: #FF0000; ; FG_COLOR' +
407 '.button:focus, .button2:focus {' +
408 'background-color: #FF0000; ; FG_COLOR' +
410 'table.data tfoot {' +
411 'HL_COLOR FG_COLOR' +
414 'HL_COLOR FG_COLOR FONT_SIZE FONT_FAMILY' +
416 '.buttontab selected {' +
417 'HL_COLOR FG_COLOR' +
419 'td.dropdown a:hover {' +
420 'HL_COLOR FG_COLOR' +
422 'table.tabbed-table th.tab:hover {' +
423 'HL_COLOR FG_COLOR' +
425 'table.tabbed-table th.tab a:focus {' +
426 'HL_COLOR FG_COLOR' +
428 'table.tabbed-table a, table.tabbed-table a:visited, table.tabbed-table a:hover {' +
429 'HL_COLOR FG_COLOR' +
431 'div#top-links a:focus{' +
432 'HL_COLOR FG_COLOR' +
434 'a#editor-link:hover {' +
435 'HL_COLOR FG_COLOR' +
437 'table.data tbody tr:hover {' +
438 'HL_COLOR FG_COLOR' +
440 'table.data tfoot input:focus {' +
441 'HL_COLOR FG_COLOR' +
443 'div.home-link:hover {' +
444 'HL_COLOR FG_COLOR' +
446 '#header a:hover {' +
447 'HL_COLOR FG_COLOR' +
449 'div.tabs a:hover, div.tabs a.active {' +
450 'HL_COLOR FG_COLOR' +
452 'div.course:hover {' +
453 'HL_COLOR FG_COLOR' +
455 '#navlist li a:hover, #navlist li a:active {' +
456 'HL_COLOR FG_COLOR' +
458 'input[type=image].fl-force-right {' +
459 'BG_COLOR FG_COLOR' +
470 '#topnavlist li a{' +
473 '#topnavlist li a{' +
485 '.add_profile_photo {' +
494 '.etabbed-list li {' +
497 'input[type=submit] {' +
500 'input[type=reset] {' +
503 'input[type=text] {' +
506 'input[type=file] {' +
527 '.forum-paginator {' +
530 '#forum-thread li {' +
533 '.forum-post-ctrl {' +
536 '.profile-picture {' +
542 '.dropdown-heading {' +
545 /** Armin 23.09.2010 */
547 'BG_COLOR FG_COLOR' +
549 'div.recent_activity_box {' +
550 'BG_COLOR FG_COLOR' +
552 'div.current_box {' +
553 'BG_COLOR FG_COLOR' +
556 'BG_COLOR FG_COLOR' +
559 'BG_COLOR FG_COLOR' +
562 /** Armin 23.09.2010 */
567 * Substitutes styles into styles block above and then places those styles on the page
569 ATutor.users.preferences.setStyles = function (bg_color, fg_color, hl_color, font, font_size) {
570 var font_style = font ? 'font-family:' + font + ' !important;\n' : '';
571 var font_size_style = font_size ? 'font-size:' + font_size + 'em !important;\n' : '';
572 var bg_color_style = bg_color ? 'background-color: #' + bg_color + ' !important;\n' + 'background-image: none !important;\n' : '';
573 var fg_color_style = fg_color ? 'color: #' + fg_color + ' !important;\n' : '';
574 var hl_color_style = hl_color ? 'background-color: #' + hl_color + '! important;\n' : '';
575 var bd_color_style = fg_color ? 'border-color: #' + fg_color + '! important;\n' : '';
577 //var pref_style = ATutor.users.preferences.user_styles.replace(/FONT_FAMILY/g, font_style).replace(/FONT_SIZE/g, font_size_style).replace(/BG_COLOR/g, bg_color_style).replace(/FG_COLOR/g, fg_color_style).replace(/HL_COLOR/g, hl_color_style);
578 var pref_style = ATutor.users.preferences.user_styles.replace(/FONT_FAMILY/g, font_style).replace(/FONT_SIZE/g, font_size_style).replace(/BG_COLOR/g, bg_color_style).replace(/FG_COLOR/g, fg_color_style).replace(/HL_COLOR/g, hl_color_style).replace(/BORDER/g, bd_color_style);
580 jQuery('#pref_style').replaceWith(pref_style);
581 if (window.opener) jQuery('#pref_style', window.opener.document).replaceWith(pref_style);
585 * Adds click hander to links with id pref_wiz_launcher
587 ATutor.users.preferences.addPrefWizClickHandler = function () {
588 var launcherArray = jQuery(".pref_wiz_launcher");
589 launcherArray.click(function() {
590 var query_string = "";
591 if (ATutor.users.preferences.course_id !== "") {
592 query_string = 'course_id=' + ATutor.users.preferences.course_id;
594 if (query_string !== "") {
595 query_string = "?" + query_string;
597 window.open(ATutor.base_href + 'users/pref_wizard/index.php' + query_string,'prefWizWindow','menubar=0,scrollbars=1,resizable=1,width=640,height=580');
603 * Allow adding javascript from javascript
604 * @param: jsname - the javascript to include. Make sure the path to the js file is correct
605 * tagToAppendJS - Optional. The tag where you want the js file to be included. For example: head, body
606 * Refrence: http://javascript.about.com/library/bladdjs.htm
608 ATutor.addJavascript = function(jsname,tagToAppendJS) {
610 if (tagToAppendJS === undefined) {
611 tagToAppendJS = 'head';
613 var th = document.getElementsByTagName(tagToAppendJS)[0];
614 var s = document.createElement('script');
615 s.setAttribute('type','text/javascript');
616 s.setAttribute('src',jsname);