aboutsummaryrefslogtreecommitdiff
path: root/mod/dokuwiki/vendors/dokuwiki/lib/plugins/s5reloaded/ui/effects_support/presentacular.js
blob: d6ec5cd63675ecc4f88c98f07c548a9ad1c79538 (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
/*
Presentacular. v 0.1
http://labs.cavorite.com/presentacular/
(c) 2005, Juan Manuel Caicedo

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

See http://www.gnu.org/copyleft/gpl.html for more information

*/

/*
Creates a chain function. 

Todo: 
	Handle return values
	Add a chained property with a reference to the original function

Static method
*/
Function.chain = function(from,ext){
	return function() {
		from.apply(this,arguments)
		ext.apply(this,arguments)
	}
}

/*
Creates a chained function
Instance method
*/
Function.prototype.chain = function(){
	var __source = this
	var exts = arguments
	return function(){
		__source.apply(this,arguments)
		for (e = 0; e < exts.length; e++){
			exts[e].apply(this,arguments)
		}
	}
}

/*
Applies function f to each element of the list
*/
function Map(list,f){
	var r = []
	for (var i=0; i < list.length; i++){
		r.push(f.call(this,list[i]))
	}
	return r
}



var Presentacular = {}

/*
Available effects
TODO: Provide a function to add effects
*/
Presentacular.effects = {
	blinddown: Effect.BlindDown,
	blindup: Effect.BlindUp,
	appear: Effect.Appear,
	puff: Effect.Puff,
	shake: Effect.Shake,
	pulsate: Effect.Pulsate,
	slidedown: Effect.SlideDown,
	slideup: Effect.SlideUp,
	highlight: Effect.Highlight,
	grow: Effect.Grow,
	fade: Effect.Fade,
	fold: Effect.Fold,
	shrink: Effect.Shrink,
        dropout: Effect.DropOut,
        switchoff: Effect.SwitchOff,
        squish: Effect.Squish
}

/*
Apply effects to element elm.

parentClasses: If true, include effects defined in the parent element. Used for lists (ul, ol)

*/
Presentacular.applyEffects = function(elm,parentClasses){
	
	var c = []
	if (parentClasses && elm.className)
                try {
			c = c.concat(elm.parentNode.className.split(' '))
			c = c.concat(elm.className.split(' '))
                } catch (exc) {
			return;
		}
		Map(c, function(cl){
		if (!cl) return


		//Proof of concept. this code could (and should) be more elegant
		cl = cl.toLowerCase().split('_')
		
		var opts = {duration: 1}
		if (cl.length > 1){
			opts.duration = cl[1]
		}

		if (Presentacular.effects[cl[0]]){
			Presentacular.effects[cl[0]].call(this,elm,opts)
		}
		return
	})
}


/*
Chained function
*/
function ChangeSlide(step){

	var ce = DOKUid('slide' + snum)
	
	//Apply slide effects
	Presentacular.applyEffects(ce)

	//Apply effects to all elements but the incrementals
	Map(ce.getElementsByTagName('*'), function(elm){
		if (!hasClass(elm,"incremental")){
			Presentacular.applyEffects(elm)
		}
	})
}


/*
Chained function
*/
function ApplyCurrentElement(elm,className){
	if (className == "current"){
		Presentacular.applyEffects(elm,true)
	}
}

/*
Function chaining: execute the second function after the first one has finished

This was necesary in order to keep the same function names and because I want
to *extend* S5 instead of *edit* it.

*/
window.addClass = addClass.chain(ApplyCurrentElement)
window.go = go.chain(ChangeSlide)