Project

General

Profile

1
// Copyright 2006 Stepan Riha
2
// www.nonplus.net
3
// $Id: restore_pages.js 2 2006-04-18 03:04:39Z stepan $
4

    
5
// Array of ids that can be toggled using toggle_visibility()
6
JsAdmin.toggled_ids = function() {
7
	var links = document.getElementsByTagName('a');
8
	var ids = [];
9
	var reId = /toggle_visibility\s*\(\s*\'([^\']+)/;
10

    
11
	for(var i = 0; i < links.length; i++) {
12
		var href = links[i].href || '';
13
		var match = href.match(reId);
14
		if(!match) {
15
			continue;
16
		}
17
		var id = match[1];
18
		ids.push(id);
19
	}
20

    
21
	if(ids.length > 0) {
22
		return ids;
23
	} else {
24
		return false;
25
	}
26
};
27

    
28
// Expand sections stored in the wb_jsadmin_pages cookie
29
JsAdmin.restore_toggled = function() {
30
	var ids = this.toggled_ids();
31

    
32
	if(!ids) {
33
		return;
34
	}
35

    
36
	var saved = this.util.readCookie('wb_jsadmin_pages');
37
	if(!saved) {
38
		return;
39
	}
40

    
41
	var reNum = /(\d+)/;
42

    
43
	saved = ',' + saved + ',';
44

    
45
	for(var i = ids.length-1; i >= 0; i--) {
46
		var id = ids[i];
47
		if(saved.indexOf(',' + id + ',') >= 0) {
48
			toggle_visibility(id);
49
			var match = id.match(reNum);
50
			if(match)
51
				toggle_plus_minus(match[1]);
52
		}
53
	}
54
};
55

    
56
// Store expanded section ids in the wb_jsadmin_pages cookie
57
JsAdmin.save_toggled = function() {
58

    
59
	var ids = this.toggled_ids();
60

    
61
	if(!ids) {
62
		return;
63
	}
64

    
65
	var visible = [];
66
	for(var i = 0; i < ids.length; i++) {
67
		var id = ids[i];
68
		var elt = YAHOO.util.Dom.get(id);
69
		var display = elt.style.display;
70
		if(display == 'block') {
71
			visible.push(ids[i]);
72
		}
73
	}
74

    
75
	var ids = visible.join(",");
76
	this.util.createCookie('wb_jsadmin_pages', ids, 14);
77
};
78

    
(4-4/5)