Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivWeb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivWeb
Commits
0394433d
Commit
0394433d
authored
Aug 22, 2023
by
张瑶
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: edit conflict
parent
73c6bb47
Pipeline
#77817
passed with stages
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
260 additions
and
305 deletions
+260
-305
jquery.ripples.js
src/assets/js/ripples/jquery.ripples.js
+190
-206
ripples.js
src/assets/js/ripples/ripples.js
+70
-99
No files found.
src/assets/js/ripples/jquery.ripples.js
View file @
0394433d
...
@@ -4,22 +4,23 @@
...
@@ -4,22 +4,23 @@
* @author sirxemic / https://sirxemic.com/
* @author sirxemic / https://sirxemic.com/
*/
*/
(
function
(
global
,
factory
)
{
(
function
(
global
,
factory
)
{
typeof
exports
===
'object'
&&
typeof
module
!==
'undefined'
?
factory
(
require
(
'jquery'
))
:
typeof
exports
===
'object'
&&
typeof
module
!==
'undefined'
typeof
define
===
'function'
&&
define
.
amd
?
define
([
'jquery'
],
factory
)
:
?
factory
(
require
(
'jquery'
))
(
factory
(
global
.
$
));
:
typeof
define
===
'function'
&&
define
.
amd
}(
this
,
(
function
(
$
)
{
'use strict'
;
?
define
([
'jquery'
],
factory
)
:
factory
(
global
.
$
);
$
=
$
&&
'default'
in
$
?
$
[
'default'
]
:
$
;
})(
this
,
function
(
$
)
{
$
=
$
&&
'default'
in
$
?
$
.
default
:
$
;
var
gl
;
var
$window
=
$
(
window
);
// There is only one window, so why not cache the jQuery-wrapped window?
let
gl
;
const
$window
=
$
(
window
);
// There is only one window, so why not cache the jQuery-wrapped window?
function
isPercentage
(
str
)
{
function
isPercentage
(
str
)
{
return
str
[
str
.
length
-
1
]
==
'%'
;
return
str
[
str
.
length
-
1
]
==
'%'
;
}
}
/**
/**
* Load a configuration of GL settings which the browser supports.
* Load a configuration of GL settings which the browser supports.
* For example:
* For example:
* - not all browsers support WebGL
* - not all browsers support WebGL
...
@@ -28,8 +29,8 @@ function isPercentage(str) {
...
@@ -28,8 +29,8 @@ function isPercentage(str) {
* - not all browsers support rendering to floating point textures
* - not all browsers support rendering to floating point textures
* - some browsers *do* support rendering to half-floating point textures instead.
* - some browsers *do* support rendering to half-floating point textures instead.
*/
*/
function
loadConfig
()
{
function
loadConfig
()
{
var
canvas
=
document
.
createElement
(
'canvas'
);
const
canvas
=
document
.
createElement
(
'canvas'
);
gl
=
canvas
.
getContext
(
'webgl'
)
||
canvas
.
getContext
(
'experimental-webgl'
);
gl
=
canvas
.
getContext
(
'webgl'
)
||
canvas
.
getContext
(
'experimental-webgl'
);
if
(
!
gl
)
{
if
(
!
gl
)
{
...
@@ -38,14 +39,14 @@ function loadConfig() {
...
@@ -38,14 +39,14 @@ function loadConfig() {
}
}
// Load extensions
// Load extensions
var
extensions
=
{};
const
extensions
=
{};
[
[
'OES_texture_float'
,
'OES_texture_float'
,
'OES_texture_half_float'
,
'OES_texture_half_float'
,
'OES_texture_float_linear'
,
'OES_texture_float_linear'
,
'OES_texture_half_float_linear'
'OES_texture_half_float_linear'
,
].
forEach
(
function
(
name
)
{
].
forEach
(
function
(
name
)
{
var
extension
=
gl
.
getExtension
(
name
);
const
extension
=
gl
.
getExtension
(
name
);
if
(
extension
)
{
if
(
extension
)
{
extensions
[
name
]
=
extension
;
extensions
[
name
]
=
extension
;
}
}
...
@@ -56,13 +57,13 @@ function loadConfig() {
...
@@ -56,13 +57,13 @@ function loadConfig() {
return
null
;
return
null
;
}
}
var
configs
=
[];
const
configs
=
[];
function
createConfig
(
type
,
glType
,
arrayType
)
{
function
createConfig
(
type
,
glType
,
arrayType
)
{
var
name
=
'OES_texture_'
+
type
,
const
name
=
`OES_texture_
${
type
}
`
;
nameLinear
=
name
+
'_linear'
,
const
nameLinear
=
`
${
name
}
_linear`
;
linearSupport
=
nameLinear
in
extensions
,
const
linearSupport
=
nameLinear
in
extensions
;
configExtensions
=
[
name
];
const
configExtensions
=
[
name
];
if
(
linearSupport
)
{
if
(
linearSupport
)
{
configExtensions
.
push
(
nameLinear
);
configExtensions
.
push
(
nameLinear
);
...
@@ -70,28 +71,26 @@ function loadConfig() {
...
@@ -70,28 +71,26 @@ function loadConfig() {
return
{
return
{
type
:
glType
,
type
:
glType
,
arrayType
:
arrayType
,
arrayType
,
linearSupport
:
linearSupport
,
linearSupport
,
extensions
:
configExtensions
extensions
:
configExtensions
,
};
};
}
}
configs
.
push
(
configs
.
push
(
createConfig
(
'float'
,
gl
.
FLOAT
,
Float32Array
));
createConfig
(
'float'
,
gl
.
FLOAT
,
Float32Array
)
);
if
(
extensions
.
OES_texture_half_float
)
{
if
(
extensions
.
OES_texture_half_float
)
{
configs
.
push
(
configs
.
push
(
// Array type should be Uint16Array, but at least on iOS that breaks. In that case we
// Array type should be Uint16Array, but at least on iOS that breaks. In that case we
// just initialize the textures with data=null, instead of data=new Uint16Array(...).
// just initialize the textures with data=null, instead of data=new Uint16Array(...).
// This makes initialization a tad slower, but it's still negligible.
// This makes initialization a tad slower, but it's still negligible.
createConfig
(
'half_float'
,
extensions
.
OES_texture_half_float
.
HALF_FLOAT_OES
,
null
)
createConfig
(
'half_float'
,
extensions
.
OES_texture_half_float
.
HALF_FLOAT_OES
,
null
),
);
);
}
}
// Setup the texture and framebuffer
// Setup the texture and framebuffer
var
texture
=
gl
.
createTexture
();
const
texture
=
gl
.
createTexture
();
var
framebuffer
=
gl
.
createFramebuffer
();
const
framebuffer
=
gl
.
createFramebuffer
();
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
framebuffer
);
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
framebuffer
);
gl
.
bindTexture
(
gl
.
TEXTURE_2D
,
texture
);
gl
.
bindTexture
(
gl
.
TEXTURE_2D
,
texture
);
...
@@ -101,9 +100,9 @@ function loadConfig() {
...
@@ -101,9 +100,9 @@ function loadConfig() {
gl
.
texParameteri
(
gl
.
TEXTURE_2D
,
gl
.
TEXTURE_WRAP_T
,
gl
.
CLAMP_TO_EDGE
);
gl
.
texParameteri
(
gl
.
TEXTURE_2D
,
gl
.
TEXTURE_WRAP_T
,
gl
.
CLAMP_TO_EDGE
);
// Check for each supported texture type if rendering to it is supported
// Check for each supported texture type if rendering to it is supported
var
config
=
null
;
let
config
=
null
;
for
(
var
i
=
0
;
i
<
configs
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
configs
.
length
;
i
++
)
{
gl
.
texImage2D
(
gl
.
TEXTURE_2D
,
0
,
gl
.
RGBA
,
32
,
32
,
0
,
gl
.
RGBA
,
configs
[
i
].
type
,
null
);
gl
.
texImage2D
(
gl
.
TEXTURE_2D
,
0
,
gl
.
RGBA
,
32
,
32
,
0
,
gl
.
RGBA
,
configs
[
i
].
type
,
null
);
gl
.
framebufferTexture2D
(
gl
.
FRAMEBUFFER
,
gl
.
COLOR_ATTACHMENT0
,
gl
.
TEXTURE_2D
,
texture
,
0
);
gl
.
framebufferTexture2D
(
gl
.
FRAMEBUFFER
,
gl
.
COLOR_ATTACHMENT0
,
gl
.
TEXTURE_2D
,
texture
,
0
);
...
@@ -114,21 +113,20 @@ function loadConfig() {
...
@@ -114,21 +113,20 @@ function loadConfig() {
}
}
return
config
;
return
config
;
}
}
function
createImageData
(
width
,
height
)
{
function
createImageData
(
width
,
height
)
{
try
{
try
{
return
new
ImageData
(
width
,
height
);
return
new
ImageData
(
width
,
height
);
}
}
catch
(
e
)
{
catch
(
e
)
{
// Fallback for IE
// Fallback for IE
var
canvas
=
document
.
createElement
(
'canvas'
);
const
canvas
=
document
.
createElement
(
'canvas'
);
return
canvas
.
getContext
(
'2d'
).
createImageData
(
width
,
height
);
return
canvas
.
getContext
(
'2d'
).
createImageData
(
width
,
height
);
}
}
}
}
function
translateBackgroundPosition
(
value
)
{
function
translateBackgroundPosition
(
value
)
{
var
parts
=
value
.
split
(
' '
);
const
parts
=
value
.
split
(
' '
);
if
(
parts
.
length
===
1
)
{
if
(
parts
.
length
===
1
)
{
switch
(
value
)
{
switch
(
value
)
{
...
@@ -145,8 +143,7 @@ function translateBackgroundPosition(value) {
...
@@ -145,8 +143,7 @@ function translateBackgroundPosition(value) {
default
:
default
:
return
[
value
,
'50%'
];
return
[
value
,
'50%'
];
}
}
}
}
else
{
else
{
return
parts
.
map
(
function
(
part
)
{
return
parts
.
map
(
function
(
part
)
{
switch
(
value
)
{
switch
(
value
)
{
case
'center'
:
case
'center'
:
...
@@ -162,27 +159,27 @@ function translateBackgroundPosition(value) {
...
@@ -162,27 +159,27 @@ function translateBackgroundPosition(value) {
}
}
});
});
}
}
}
}
function
createProgram
(
vertexSource
,
fragmentSource
,
uniformValues
)
{
function
createProgram
(
vertexSource
,
fragmentSource
,
uniformValues
)
{
function
compileSource
(
type
,
source
)
{
function
compileSource
(
type
,
source
)
{
var
shader
=
gl
.
createShader
(
type
);
const
shader
=
gl
.
createShader
(
type
);
gl
.
shaderSource
(
shader
,
source
);
gl
.
shaderSource
(
shader
,
source
);
gl
.
compileShader
(
shader
);
gl
.
compileShader
(
shader
);
if
(
!
gl
.
getShaderParameter
(
shader
,
gl
.
COMPILE_STATUS
))
{
if
(
!
gl
.
getShaderParameter
(
shader
,
gl
.
COMPILE_STATUS
))
{
throw
new
Error
(
'compile error: '
+
gl
.
getShaderInfoLog
(
shader
)
);
throw
new
Error
(
`compile error:
${
gl
.
getShaderInfoLog
(
shader
)}
`
);
}
}
return
shader
;
return
shader
;
}
}
var
program
=
{};
const
program
=
{};
program
.
id
=
gl
.
createProgram
();
program
.
id
=
gl
.
createProgram
();
gl
.
attachShader
(
program
.
id
,
compileSource
(
gl
.
VERTEX_SHADER
,
vertexSource
));
gl
.
attachShader
(
program
.
id
,
compileSource
(
gl
.
VERTEX_SHADER
,
vertexSource
));
gl
.
attachShader
(
program
.
id
,
compileSource
(
gl
.
FRAGMENT_SHADER
,
fragmentSource
));
gl
.
attachShader
(
program
.
id
,
compileSource
(
gl
.
FRAGMENT_SHADER
,
fragmentSource
));
gl
.
linkProgram
(
program
.
id
);
gl
.
linkProgram
(
program
.
id
);
if
(
!
gl
.
getProgramParameter
(
program
.
id
,
gl
.
LINK_STATUS
))
{
if
(
!
gl
.
getProgramParameter
(
program
.
id
,
gl
.
LINK_STATUS
))
{
throw
new
Error
(
'link error: '
+
gl
.
getProgramInfoLog
(
program
.
id
)
);
throw
new
Error
(
`link error:
${
gl
.
getProgramInfoLog
(
program
.
id
)}
`
);
}
}
// Fetch the uniform and attribute locations
// Fetch the uniform and attribute locations
...
@@ -190,44 +187,47 @@ function createProgram(vertexSource, fragmentSource, uniformValues) {
...
@@ -190,44 +187,47 @@ function createProgram(vertexSource, fragmentSource, uniformValues) {
program
.
locations
=
{};
program
.
locations
=
{};
gl
.
useProgram
(
program
.
id
);
gl
.
useProgram
(
program
.
id
);
gl
.
enableVertexAttribArray
(
0
);
gl
.
enableVertexAttribArray
(
0
);
var
match
,
name
,
regex
=
/uniform
(\w
+
)
(\w
+
)
/g
,
shaderCode
=
vertexSource
+
fragmentSource
;
let
match
;
let
name
;
const
regex
=
/uniform
(\w
+
)
(\w
+
)
/g
;
const
shaderCode
=
vertexSource
+
fragmentSource
;
while
((
match
=
regex
.
exec
(
shaderCode
))
!=
null
)
{
while
((
match
=
regex
.
exec
(
shaderCode
))
!=
null
)
{
name
=
match
[
2
];
name
=
match
[
2
];
program
.
locations
[
name
]
=
gl
.
getUniformLocation
(
program
.
id
,
name
);
program
.
locations
[
name
]
=
gl
.
getUniformLocation
(
program
.
id
,
name
);
}
}
return
program
;
return
program
;
}
}
function
bindTexture
(
texture
,
unit
)
{
function
bindTexture
(
texture
,
unit
)
{
gl
.
activeTexture
(
gl
.
TEXTURE0
+
(
unit
||
0
));
gl
.
activeTexture
(
gl
.
TEXTURE0
+
(
unit
||
0
));
gl
.
bindTexture
(
gl
.
TEXTURE_2D
,
texture
);
gl
.
bindTexture
(
gl
.
TEXTURE_2D
,
texture
);
}
}
function
extractUrl
(
value
)
{
function
extractUrl
(
value
)
{
var
urlMatch
=
/url
\([
"'
]?([^
"'
]
*
)[
"'
]?\)
/
.
exec
(
value
);
const
urlMatch
=
/url
\([
"'
]?([^
"'
]
*
)[
"'
]?\)
/
.
exec
(
value
);
if
(
urlMatch
==
null
)
{
if
(
urlMatch
==
null
)
{
return
null
;
return
null
;
}
}
return
urlMatch
[
1
];
return
urlMatch
[
1
];
}
}
function
isDataUri
(
url
)
{
function
isDataUri
(
url
)
{
return
url
.
match
(
/^data:/
);
return
url
.
match
(
/^data:/
);
}
}
var
config
=
loadConfig
();
const
config
=
loadConfig
();
var
transparentPixels
=
createImageData
(
32
,
32
);
const
transparentPixels
=
createImageData
(
32
,
32
);
// Extend the css
// Extend the css
$
(
'head'
).
prepend
(
'<style>.jquery-ripples { position: relative; z-index: 0; }</style>'
);
$
(
'head'
).
prepend
(
'<style>.jquery-ripples { position: relative; z-index: 0; }</style>'
);
// RIPPLES CLASS DEFINITION
// RIPPLES CLASS DEFINITION
// =========================
// =========================
var
Ripples
=
function
(
el
,
options
)
{
const
Ripples
=
function
(
el
,
options
)
{
var
that
=
this
;
const
that
=
this
;
this
.
$el
=
$
(
el
);
this
.
$el
=
$
(
el
);
...
@@ -243,7 +243,7 @@ var Ripples = function (el, options) {
...
@@ -243,7 +243,7 @@ var Ripples = function (el, options) {
this
.
imageUrl
=
options
.
imageUrl
;
this
.
imageUrl
=
options
.
imageUrl
;
// Init WebGL canvas
// Init WebGL canvas
var
canvas
=
document
.
createElement
(
'canvas'
);
const
canvas
=
document
.
createElement
(
'canvas'
);
canvas
.
width
=
this
.
$el
.
innerWidth
();
canvas
.
width
=
this
.
$el
.
innerWidth
();
canvas
.
height
=
this
.
$el
.
innerHeight
();
canvas
.
height
=
this
.
$el
.
innerHeight
();
this
.
canvas
=
canvas
;
this
.
canvas
=
canvas
;
...
@@ -254,7 +254,7 @@ var Ripples = function (el, options) {
...
@@ -254,7 +254,7 @@ var Ripples = function (el, options) {
top
:
0
,
top
:
0
,
right
:
0
,
right
:
0
,
bottom
:
0
,
bottom
:
0
,
zIndex
:
-
1
zIndex
:
-
1
,
});
});
this
.
$el
.
addClass
(
'jquery-ripples'
).
append
(
canvas
);
this
.
$el
.
addClass
(
'jquery-ripples'
).
append
(
canvas
);
...
@@ -275,12 +275,12 @@ var Ripples = function (el, options) {
...
@@ -275,12 +275,12 @@ var Ripples = function (el, options) {
this
.
bufferWriteIndex
=
0
;
this
.
bufferWriteIndex
=
0
;
this
.
bufferReadIndex
=
1
;
this
.
bufferReadIndex
=
1
;
var
arrayType
=
config
.
arrayType
;
const
{
arrayType
}
=
config
;
var
textureData
=
arrayType
?
new
arrayType
(
this
.
resolution
*
this
.
resolution
*
4
)
:
null
;
const
textureData
=
arrayType
?
new
arrayType
(
this
.
resolution
*
this
.
resolution
*
4
)
:
null
;
for
(
var
i
=
0
;
i
<
2
;
i
++
)
{
for
(
let
i
=
0
;
i
<
2
;
i
++
)
{
var
texture
=
gl
.
createTexture
();
const
texture
=
gl
.
createTexture
();
var
framebuffer
=
gl
.
createFramebuffer
();
const
framebuffer
=
gl
.
createFramebuffer
();
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
framebuffer
);
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
framebuffer
);
...
@@ -300,12 +300,7 @@ var Ripples = function (el, options) {
...
@@ -300,12 +300,7 @@ var Ripples = function (el, options) {
// Init GL stuff
// Init GL stuff
this
.
quad
=
gl
.
createBuffer
();
this
.
quad
=
gl
.
createBuffer
();
gl
.
bindBuffer
(
gl
.
ARRAY_BUFFER
,
this
.
quad
);
gl
.
bindBuffer
(
gl
.
ARRAY_BUFFER
,
this
.
quad
);
gl
.
bufferData
(
gl
.
ARRAY_BUFFER
,
new
Float32Array
([
gl
.
bufferData
(
gl
.
ARRAY_BUFFER
,
new
Float32Array
([
-
1
,
-
1
,
+
1
,
-
1
,
+
1
,
+
1
,
-
1
,
+
1
]),
gl
.
STATIC_DRAW
);
-
1
,
-
1
,
+
1
,
-
1
,
+
1
,
+
1
,
-
1
,
+
1
]),
gl
.
STATIC_DRAW
);
this
.
initShaders
();
this
.
initShaders
();
this
.
initTexture
();
this
.
initTexture
();
...
@@ -336,22 +331,21 @@ var Ripples = function (el, options) {
...
@@ -336,22 +331,21 @@ var Ripples = function (el, options) {
}
}
requestAnimationFrame
(
step
);
requestAnimationFrame
(
step
);
};
};
Ripples
.
DEFAULTS
=
{
Ripples
.
DEFAULTS
=
{
imageUrl
:
null
,
imageUrl
:
null
,
resolution
:
256
,
resolution
:
256
,
dropRadius
:
20
,
dropRadius
:
20
,
perturbance
:
0.03
,
perturbance
:
0.03
,
interactive
:
true
,
interactive
:
true
,
crossOrigin
:
''
crossOrigin
:
''
,
};
};
Ripples
.
prototype
=
{
Ripples
.
prototype
=
{
// Set up pointer (mouse + touch) events
// Set up pointer (mouse + touch) events
setupPointerEvents
:
function
()
{
setupPointerEvents
()
{
var
that
=
this
;
const
that
=
this
;
function
pointerEventsEnabled
()
{
function
pointerEventsEnabled
()
{
return
that
.
visible
&&
that
.
running
&&
that
.
interactive
;
return
that
.
visible
&&
that
.
running
&&
that
.
interactive
;
...
@@ -359,11 +353,7 @@ Ripples.prototype = {
...
@@ -359,11 +353,7 @@ Ripples.prototype = {
function
dropAtPointer
(
pointer
,
big
)
{
function
dropAtPointer
(
pointer
,
big
)
{
if
(
pointerEventsEnabled
())
{
if
(
pointerEventsEnabled
())
{
that
.
dropAtPointer
(
that
.
dropAtPointer
(
pointer
,
that
.
dropRadius
*
(
big
?
1.5
:
1
),
big
?
0.14
:
0.01
);
pointer
,
that
.
dropRadius
*
(
big
?
1.5
:
1
),
(
big
?
0.14
:
0.01
)
);
}
}
}
}
...
@@ -375,8 +365,8 @@ Ripples.prototype = {
...
@@ -375,8 +365,8 @@ Ripples.prototype = {
dropAtPointer
(
e
);
dropAtPointer
(
e
);
})
})
.
on
(
'touchmove.ripples touchstart.ripples'
,
function
(
e
)
{
.
on
(
'touchmove.ripples touchstart.ripples'
,
function
(
e
)
{
var
touches
=
e
.
originalEvent
.
changedTouches
;
const
touches
=
e
.
originalEvent
.
changedTouches
;
for
(
var
i
=
0
;
i
<
touches
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
touches
.
length
;
i
++
)
{
dropAtPointer
(
touches
[
i
]);
dropAtPointer
(
touches
[
i
]);
}
}
})
})
...
@@ -388,14 +378,13 @@ Ripples.prototype = {
...
@@ -388,14 +378,13 @@ Ripples.prototype = {
},
},
// Load the image either from the options or the element's CSS rules.
// Load the image either from the options or the element's CSS rules.
loadImage
:
function
()
{
loadImage
()
{
var
that
=
this
;
const
that
=
this
;
gl
=
this
.
context
;
gl
=
this
.
context
;
var
newImageSource
=
this
.
imageUrl
||
const
newImageSource
=
extractUrl
(
this
.
originalCssBackgroundImage
)
||
this
.
imageUrl
||
extractUrl
(
this
.
originalCssBackgroundImage
)
||
extractUrl
(
this
.
$el
.
css
(
'backgroundImage'
));
extractUrl
(
this
.
$el
.
css
(
'backgroundImage'
));
// If image source is unchanged, don't reload it.
// If image source is unchanged, don't reload it.
if
(
newImageSource
==
this
.
imageSource
)
{
if
(
newImageSource
==
this
.
imageSource
)
{
...
@@ -411,7 +400,7 @@ Ripples.prototype = {
...
@@ -411,7 +400,7 @@ Ripples.prototype = {
}
}
// Load the texture from a new image.
// Load the texture from a new image.
var
image
=
new
Image
;
const
image
=
new
Image
()
;
image
.
onload
=
function
()
{
image
.
onload
=
function
()
{
gl
=
that
.
context
;
gl
=
that
.
context
;
...
@@ -420,7 +409,7 @@ Ripples.prototype = {
...
@@ -420,7 +409,7 @@ Ripples.prototype = {
return
(
x
&
(
x
-
1
))
==
0
;
return
(
x
&
(
x
-
1
))
==
0
;
}
}
var
wrapping
=
(
isPowerOfTwo
(
image
.
width
)
&&
isPowerOfTwo
(
image
.
height
)
)
?
gl
.
REPEAT
:
gl
.
CLAMP_TO_EDGE
;
const
wrapping
=
isPowerOfTwo
(
image
.
width
)
&&
isPowerOfTwo
(
image
.
height
)
?
gl
.
REPEAT
:
gl
.
CLAMP_TO_EDGE
;
gl
.
bindTexture
(
gl
.
TEXTURE_2D
,
that
.
backgroundTexture
);
gl
.
bindTexture
(
gl
.
TEXTURE_2D
,
that
.
backgroundTexture
);
gl
.
texParameteri
(
gl
.
TEXTURE_2D
,
gl
.
TEXTURE_WRAP_S
,
wrapping
);
gl
.
texParameteri
(
gl
.
TEXTURE_2D
,
gl
.
TEXTURE_WRAP_S
,
wrapping
);
...
@@ -447,7 +436,7 @@ Ripples.prototype = {
...
@@ -447,7 +436,7 @@ Ripples.prototype = {
image
.
src
=
this
.
imageSource
;
image
.
src
=
this
.
imageSource
;
},
},
step
:
function
()
{
step
()
{
gl
=
this
.
context
;
gl
=
this
.
context
;
if
(
!
this
.
visible
)
{
if
(
!
this
.
visible
)
{
...
@@ -463,13 +452,13 @@ Ripples.prototype = {
...
@@ -463,13 +452,13 @@ Ripples.prototype = {
this
.
render
();
this
.
render
();
},
},
drawQuad
:
function
()
{
drawQuad
()
{
gl
.
bindBuffer
(
gl
.
ARRAY_BUFFER
,
this
.
quad
);
gl
.
bindBuffer
(
gl
.
ARRAY_BUFFER
,
this
.
quad
);
gl
.
vertexAttribPointer
(
0
,
2
,
gl
.
FLOAT
,
false
,
0
,
0
);
gl
.
vertexAttribPointer
(
0
,
2
,
gl
.
FLOAT
,
false
,
0
,
0
);
gl
.
drawArrays
(
gl
.
TRIANGLE_FAN
,
0
,
4
);
gl
.
drawArrays
(
gl
.
TRIANGLE_FAN
,
0
,
4
);
},
},
render
:
function
()
{
render
()
{
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
null
);
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
null
);
gl
.
viewport
(
0
,
0
,
this
.
canvas
.
width
,
this
.
canvas
.
height
);
gl
.
viewport
(
0
,
0
,
this
.
canvas
.
width
,
this
.
canvas
.
height
);
...
@@ -493,7 +482,7 @@ Ripples.prototype = {
...
@@ -493,7 +482,7 @@ Ripples.prototype = {
gl
.
disable
(
gl
.
BLEND
);
gl
.
disable
(
gl
.
BLEND
);
},
},
update
:
function
()
{
update
()
{
gl
.
viewport
(
0
,
0
,
this
.
resolution
,
this
.
resolution
);
gl
.
viewport
(
0
,
0
,
this
.
resolution
,
this
.
resolution
);
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
this
.
framebuffers
[
this
.
bufferWriteIndex
]);
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
this
.
framebuffers
[
this
.
bufferWriteIndex
]);
...
@@ -505,25 +494,24 @@ Ripples.prototype = {
...
@@ -505,25 +494,24 @@ Ripples.prototype = {
this
.
swapBufferIndices
();
this
.
swapBufferIndices
();
},
},
swapBufferIndices
:
function
()
{
swapBufferIndices
()
{
this
.
bufferWriteIndex
=
1
-
this
.
bufferWriteIndex
;
this
.
bufferWriteIndex
=
1
-
this
.
bufferWriteIndex
;
this
.
bufferReadIndex
=
1
-
this
.
bufferReadIndex
;
this
.
bufferReadIndex
=
1
-
this
.
bufferReadIndex
;
},
},
computeTextureBoundaries
:
function
()
{
computeTextureBoundaries
()
{
var
backgroundSize
=
this
.
$el
.
css
(
'background-size'
);
let
backgroundSize
=
this
.
$el
.
css
(
'background-size'
);
var
backgroundAttachment
=
this
.
$el
.
css
(
'background-attachment'
);
const
backgroundAttachment
=
this
.
$el
.
css
(
'background-attachment'
);
var
backgroundPosition
=
translateBackgroundPosition
(
this
.
$el
.
css
(
'background-position'
));
const
backgroundPosition
=
translateBackgroundPosition
(
this
.
$el
.
css
(
'background-position'
));
// Here the 'container' is the element which the background adapts to
// Here the 'container' is the element which the background adapts to
// (either the chrome window or some element, depending on attachment)
// (either the chrome window or some element, depending on attachment)
var
container
;
let
container
;
if
(
backgroundAttachment
==
'fixed'
)
{
if
(
backgroundAttachment
==
'fixed'
)
{
container
=
{
left
:
window
.
pageXOffset
,
top
:
window
.
pageYOffset
};
container
=
{
left
:
window
.
pageXOffset
,
top
:
window
.
pageYOffset
};
container
.
width
=
$window
.
width
();
container
.
width
=
$window
.
width
();
container
.
height
=
$window
.
height
();
container
.
height
=
$window
.
height
();
}
}
else
{
else
{
container
=
this
.
$el
.
offset
();
container
=
this
.
$el
.
offset
();
container
.
width
=
this
.
$el
.
innerWidth
();
container
.
width
=
this
.
$el
.
innerWidth
();
container
.
height
=
this
.
$el
.
innerHeight
();
container
.
height
=
this
.
$el
.
innerHeight
();
...
@@ -535,37 +523,32 @@ Ripples.prototype = {
...
@@ -535,37 +523,32 @@ Ripples.prototype = {
var
backgroundWidth
=
this
.
backgroundWidth
*
scale
;
var
backgroundWidth
=
this
.
backgroundWidth
*
scale
;
var
backgroundHeight
=
this
.
backgroundHeight
*
scale
;
var
backgroundHeight
=
this
.
backgroundHeight
*
scale
;
}
}
else
if
(
backgroundSize
==
'contain'
)
{
else
if
(
backgroundSize
==
'contain'
)
{
var
scale
=
Math
.
min
(
container
.
width
/
this
.
backgroundWidth
,
container
.
height
/
this
.
backgroundHeight
);
var
scale
=
Math
.
min
(
container
.
width
/
this
.
backgroundWidth
,
container
.
height
/
this
.
backgroundHeight
);
var
backgroundWidth
=
this
.
backgroundWidth
*
scale
;
var
backgroundWidth
=
this
.
backgroundWidth
*
scale
;
var
backgroundHeight
=
this
.
backgroundHeight
*
scale
;
var
backgroundHeight
=
this
.
backgroundHeight
*
scale
;
}
}
else
{
else
{
backgroundSize
=
backgroundSize
.
split
(
' '
);
backgroundSize
=
backgroundSize
.
split
(
' '
);
var
backgroundWidth
=
backgroundSize
[
0
]
||
''
;
var
backgroundWidth
=
backgroundSize
[
0
]
||
''
;
var
backgroundHeight
=
backgroundSize
[
1
]
||
backgroundWidth
;
var
backgroundHeight
=
backgroundSize
[
1
]
||
backgroundWidth
;
if
(
isPercentage
(
backgroundWidth
))
{
if
(
isPercentage
(
backgroundWidth
))
{
backgroundWidth
=
container
.
width
*
parseFloat
(
backgroundWidth
)
/
100
;
backgroundWidth
=
(
container
.
width
*
parseFloat
(
backgroundWidth
))
/
100
;
}
}
else
if
(
backgroundWidth
!=
'auto'
)
{
else
if
(
backgroundWidth
!=
'auto'
)
{
backgroundWidth
=
parseFloat
(
backgroundWidth
);
backgroundWidth
=
parseFloat
(
backgroundWidth
);
}
}
if
(
isPercentage
(
backgroundHeight
))
{
if
(
isPercentage
(
backgroundHeight
))
{
backgroundHeight
=
container
.
height
*
parseFloat
(
backgroundHeight
)
/
100
;
backgroundHeight
=
(
container
.
height
*
parseFloat
(
backgroundHeight
))
/
100
;
}
}
else
if
(
backgroundHeight
!=
'auto'
)
{
else
if
(
backgroundHeight
!=
'auto'
)
{
backgroundHeight
=
parseFloat
(
backgroundHeight
);
backgroundHeight
=
parseFloat
(
backgroundHeight
);
}
}
if
(
backgroundWidth
==
'auto'
&&
backgroundHeight
==
'auto'
)
{
if
(
backgroundWidth
==
'auto'
&&
backgroundHeight
==
'auto'
)
{
backgroundWidth
=
this
.
backgroundWidth
;
backgroundWidth
=
this
.
backgroundWidth
;
backgroundHeight
=
this
.
backgroundHeight
;
backgroundHeight
=
this
.
backgroundHeight
;
}
}
else
{
else
{
if
(
backgroundWidth
==
'auto'
)
{
if
(
backgroundWidth
==
'auto'
)
{
backgroundWidth
=
this
.
backgroundWidth
*
(
backgroundHeight
/
this
.
backgroundHeight
);
backgroundWidth
=
this
.
backgroundWidth
*
(
backgroundHeight
/
this
.
backgroundHeight
);
}
}
...
@@ -577,53 +560,53 @@ Ripples.prototype = {
...
@@ -577,53 +560,53 @@ Ripples.prototype = {
}
}
// Compute backgroundX and backgroundY in page coordinates
// Compute backgroundX and backgroundY in page coordinates
var
backgroundX
=
backgroundPosition
[
0
];
let
backgroundX
=
backgroundPosition
[
0
];
var
backgroundY
=
backgroundPosition
[
1
];
let
backgroundY
=
backgroundPosition
[
1
];
if
(
isPercentage
(
backgroundX
))
{
if
(
isPercentage
(
backgroundX
))
{
backgroundX
=
container
.
left
+
(
container
.
width
-
backgroundWidth
)
*
parseFloat
(
backgroundX
)
/
100
;
backgroundX
=
container
.
left
+
((
container
.
width
-
backgroundWidth
)
*
parseFloat
(
backgroundX
))
/
100
;
}
}
else
{
else
{
backgroundX
=
container
.
left
+
parseFloat
(
backgroundX
);
backgroundX
=
container
.
left
+
parseFloat
(
backgroundX
);
}
}
if
(
isPercentage
(
backgroundY
))
{
if
(
isPercentage
(
backgroundY
))
{
backgroundY
=
container
.
top
+
(
container
.
height
-
backgroundHeight
)
*
parseFloat
(
backgroundY
)
/
100
;
backgroundY
=
container
.
top
+
((
container
.
height
-
backgroundHeight
)
*
parseFloat
(
backgroundY
))
/
100
;
}
}
else
{
else
{
backgroundY
=
container
.
top
+
parseFloat
(
backgroundY
);
backgroundY
=
container
.
top
+
parseFloat
(
backgroundY
);
}
}
var
elementOffset
=
this
.
$el
.
offset
();
const
elementOffset
=
this
.
$el
.
offset
();
this
.
renderProgram
.
uniforms
.
topLeft
=
new
Float32Array
([
this
.
renderProgram
.
uniforms
.
topLeft
=
new
Float32Array
([
(
elementOffset
.
left
-
backgroundX
)
/
backgroundWidth
,
(
elementOffset
.
left
-
backgroundX
)
/
backgroundWidth
,
(
elementOffset
.
top
-
backgroundY
)
/
backgroundHeight
(
elementOffset
.
top
-
backgroundY
)
/
backgroundHeight
,
]);
]);
this
.
renderProgram
.
uniforms
.
bottomRight
=
new
Float32Array
([
this
.
renderProgram
.
uniforms
.
bottomRight
=
new
Float32Array
([
this
.
renderProgram
.
uniforms
.
topLeft
[
0
]
+
this
.
$el
.
innerWidth
()
/
backgroundWidth
,
this
.
renderProgram
.
uniforms
.
topLeft
[
0
]
+
this
.
$el
.
innerWidth
()
/
backgroundWidth
,
this
.
renderProgram
.
uniforms
.
topLeft
[
1
]
+
this
.
$el
.
innerHeight
()
/
backgroundHeight
this
.
renderProgram
.
uniforms
.
topLeft
[
1
]
+
this
.
$el
.
innerHeight
()
/
backgroundHeight
,
]);
]);
var
maxSide
=
Math
.
max
(
this
.
canvas
.
width
,
this
.
canvas
.
height
);
const
maxSide
=
Math
.
max
(
this
.
canvas
.
width
,
this
.
canvas
.
height
);
this
.
renderProgram
.
uniforms
.
containerRatio
=
new
Float32Array
([
this
.
renderProgram
.
uniforms
.
containerRatio
=
new
Float32Array
([
this
.
canvas
.
width
/
maxSide
,
this
.
canvas
.
width
/
maxSide
,
this
.
canvas
.
height
/
maxSide
this
.
canvas
.
height
/
maxSide
,
]);
]);
},
},
initShaders
:
function
()
{
initShaders
()
{
var
vertexShader
=
[
const
vertexShader
=
[
'attribute vec2 vertex;'
,
'attribute vec2 vertex;'
,
'varying vec2 coord;'
,
'varying vec2 coord;'
,
'void main() {'
,
'void main() {'
,
'coord = vertex * 0.5 + 0.5;'
,
'coord = vertex * 0.5 + 0.5;'
,
'gl_Position = vec4(vertex, 0.0, 1.0);'
,
'gl_Position = vec4(vertex, 0.0, 1.0);'
,
'}'
'}'
,
].
join
(
'
\
n'
);
].
join
(
'
\
n'
);
this
.
dropProgram
=
createProgram
(
vertexShader
,
[
this
.
dropProgram
=
createProgram
(
vertexShader
,
[
'precision highp float;'
,
'precision highp float;'
,
'const float PI = 3.141592653589793;'
,
'const float PI = 3.141592653589793;'
,
...
@@ -643,10 +626,13 @@ Ripples.prototype = {
...
@@ -643,10 +626,13 @@ Ripples.prototype = {
'info.r += drop * strength;'
,
'info.r += drop * strength;'
,
'gl_FragColor = info;'
,
'gl_FragColor = info;'
,
'}'
'}'
,
].
join
(
'
\
n'
));
].
join
(
'
\
n'
),
);
this
.
updateProgram
=
createProgram
(
vertexShader
,
[
this
.
updateProgram
=
createProgram
(
vertexShader
,
[
'precision highp float;'
,
'precision highp float;'
,
'uniform sampler2D texture;'
,
'uniform sampler2D texture;'
,
...
@@ -672,11 +658,13 @@ Ripples.prototype = {
...
@@ -672,11 +658,13 @@ Ripples.prototype = {
'info.r += info.g;'
,
'info.r += info.g;'
,
'gl_FragColor = info;'
,
'gl_FragColor = info;'
,
'}'
'}'
,
].
join
(
'
\
n'
));
].
join
(
'
\
n'
),
);
gl
.
uniform2fv
(
this
.
updateProgram
.
locations
.
delta
,
this
.
textureDelta
);
gl
.
uniform2fv
(
this
.
updateProgram
.
locations
.
delta
,
this
.
textureDelta
);
this
.
renderProgram
=
createProgram
([
this
.
renderProgram
=
createProgram
(
[
'precision highp float;'
,
'precision highp float;'
,
'attribute vec2 vertex;'
,
'attribute vec2 vertex;'
,
...
@@ -690,8 +678,9 @@ Ripples.prototype = {
...
@@ -690,8 +678,9 @@ Ripples.prototype = {
'backgroundCoord.y = 1.0 - backgroundCoord.y;'
,
'backgroundCoord.y = 1.0 - backgroundCoord.y;'
,
'ripplesCoord = vec2(vertex.x, -vertex.y) * containerRatio * 0.5 + 0.5;'
,
'ripplesCoord = vec2(vertex.x, -vertex.y) * containerRatio * 0.5 + 0.5;'
,
'gl_Position = vec4(vertex.x, -vertex.y, 0.0, 1.0);'
,
'gl_Position = vec4(vertex.x, -vertex.y, 0.0, 1.0);'
,
'}'
'}'
,
].
join
(
'
\
n'
),
[
].
join
(
'
\
n'
),
[
'precision highp float;'
,
'precision highp float;'
,
'uniform sampler2D samplerBackground;'
,
'uniform sampler2D samplerBackground;'
,
...
@@ -711,12 +700,13 @@ Ripples.prototype = {
...
@@ -711,12 +700,13 @@ Ripples.prototype = {
'vec2 offset = -normalize(cross(dy, dx)).xz;'
,
'vec2 offset = -normalize(cross(dy, dx)).xz;'
,
'float specular = pow(max(0.0, dot(offset, normalize(vec2(-0.6, 1.0)))), 4.0);'
,
'float specular = pow(max(0.0, dot(offset, normalize(vec2(-0.6, 1.0)))), 4.0);'
,
'gl_FragColor = texture2D(samplerBackground, backgroundCoord + offset * perturbance) + specular;'
,
'gl_FragColor = texture2D(samplerBackground, backgroundCoord + offset * perturbance) + specular;'
,
'}'
'}'
,
].
join
(
'
\
n'
));
].
join
(
'
\
n'
),
);
gl
.
uniform2fv
(
this
.
renderProgram
.
locations
.
delta
,
this
.
textureDelta
);
gl
.
uniform2fv
(
this
.
renderProgram
.
locations
.
delta
,
this
.
textureDelta
);
},
},
initTexture
:
function
()
{
initTexture
()
{
this
.
backgroundTexture
=
gl
.
createTexture
();
this
.
backgroundTexture
=
gl
.
createTexture
();
gl
.
bindTexture
(
gl
.
TEXTURE_2D
,
this
.
backgroundTexture
);
gl
.
bindTexture
(
gl
.
TEXTURE_2D
,
this
.
backgroundTexture
);
gl
.
pixelStorei
(
gl
.
UNPACK_FLIP_Y_WEBGL
,
1
);
gl
.
pixelStorei
(
gl
.
UNPACK_FLIP_Y_WEBGL
,
1
);
...
@@ -724,15 +714,14 @@ Ripples.prototype = {
...
@@ -724,15 +714,14 @@ Ripples.prototype = {
gl
.
texParameteri
(
gl
.
TEXTURE_2D
,
gl
.
TEXTURE_MIN_FILTER
,
gl
.
LINEAR
);
gl
.
texParameteri
(
gl
.
TEXTURE_2D
,
gl
.
TEXTURE_MIN_FILTER
,
gl
.
LINEAR
);
},
},
setTransparentTexture
:
function
()
{
setTransparentTexture
()
{
gl
.
bindTexture
(
gl
.
TEXTURE_2D
,
this
.
backgroundTexture
);
gl
.
bindTexture
(
gl
.
TEXTURE_2D
,
this
.
backgroundTexture
);
gl
.
texImage2D
(
gl
.
TEXTURE_2D
,
0
,
gl
.
RGBA
,
gl
.
RGBA
,
gl
.
UNSIGNED_BYTE
,
transparentPixels
);
gl
.
texImage2D
(
gl
.
TEXTURE_2D
,
0
,
gl
.
RGBA
,
gl
.
RGBA
,
gl
.
UNSIGNED_BYTE
,
transparentPixels
);
},
},
hideCssBackground
:
function
()
{
hideCssBackground
()
{
// Check whether we're changing inline CSS or overriding a global CSS rule.
// Check whether we're changing inline CSS or overriding a global CSS rule.
var
inlineCss
=
this
.
$el
[
0
].
style
.
backgroundImage
;
const
inlineCss
=
this
.
$el
[
0
].
style
.
backgroundImage
;
if
(
inlineCss
==
'none'
)
{
if
(
inlineCss
==
'none'
)
{
return
;
return
;
...
@@ -744,41 +733,37 @@ Ripples.prototype = {
...
@@ -744,41 +733,37 @@ Ripples.prototype = {
this
.
$el
.
css
(
'backgroundImage'
,
'none'
);
this
.
$el
.
css
(
'backgroundImage'
,
'none'
);
},
},
restoreCssBackground
:
function
()
{
restoreCssBackground
()
{
// Restore background by either changing the inline CSS rule to what it was, or
// Restore background by either changing the inline CSS rule to what it was, or
// simply remove the inline CSS rule if it never was inlined.
// simply remove the inline CSS rule if it never was inlined.
this
.
$el
.
css
(
'backgroundImage'
,
this
.
originalInlineCss
||
''
);
this
.
$el
.
css
(
'backgroundImage'
,
this
.
originalInlineCss
||
''
);
},
},
dropAtPointer
:
function
(
pointer
,
radius
,
strength
)
{
dropAtPointer
(
pointer
,
radius
,
strength
)
{
var
borderLeft
=
parseInt
(
this
.
$el
.
css
(
'border-left-width'
))
||
0
,
const
borderLeft
=
parseInt
(
this
.
$el
.
css
(
'border-left-width'
))
||
0
;
borderTop
=
parseInt
(
this
.
$el
.
css
(
'border-top-width'
))
||
0
;
const
borderTop
=
parseInt
(
this
.
$el
.
css
(
'border-top-width'
))
||
0
;
this
.
drop
(
this
.
drop
(
pointer
.
pageX
-
this
.
$el
.
offset
().
left
-
borderLeft
,
pointer
.
pageX
-
this
.
$el
.
offset
().
left
-
borderLeft
,
pointer
.
pageY
-
this
.
$el
.
offset
().
top
-
borderTop
,
pointer
.
pageY
-
this
.
$el
.
offset
().
top
-
borderTop
,
radius
,
radius
,
strength
strength
,
);
);
},
},
/**
/**
* Public methods
* Public methods
*/
*/
drop
:
function
(
x
,
y
,
radius
,
strength
)
{
drop
(
x
,
y
,
radius
,
strength
)
{
gl
=
this
.
context
;
gl
=
this
.
context
;
var
elWidth
=
this
.
$el
.
innerWidth
();
const
elWidth
=
this
.
$el
.
innerWidth
();
var
elHeight
=
this
.
$el
.
innerHeight
();
const
elHeight
=
this
.
$el
.
innerHeight
();
var
longestSide
=
Math
.
max
(
elWidth
,
elHeight
);
const
longestSide
=
Math
.
max
(
elWidth
,
elHeight
);
radius
=
radius
/
longestSide
;
radius
/=
longestSide
;
var
dropPosition
=
new
Float32Array
([
const
dropPosition
=
new
Float32Array
([(
2
*
x
-
elWidth
)
/
longestSide
,
(
elHeight
-
2
*
y
)
/
longestSide
]);
(
2
*
x
-
elWidth
)
/
longestSide
,
(
elHeight
-
2
*
y
)
/
longestSide
]);
gl
.
viewport
(
0
,
0
,
this
.
resolution
,
this
.
resolution
);
gl
.
viewport
(
0
,
0
,
this
.
resolution
,
this
.
resolution
);
...
@@ -795,9 +780,9 @@ Ripples.prototype = {
...
@@ -795,9 +780,9 @@ Ripples.prototype = {
this
.
swapBufferIndices
();
this
.
swapBufferIndices
();
},
},
updateSize
:
function
()
{
updateSize
()
{
var
newWidth
=
this
.
$el
.
innerWidth
(),
const
newWidth
=
this
.
$el
.
innerWidth
();
newHeight
=
this
.
$el
.
innerHeight
();
const
newHeight
=
this
.
$el
.
innerHeight
();
if
(
newWidth
!=
this
.
canvas
.
width
||
newHeight
!=
this
.
canvas
.
height
)
{
if
(
newWidth
!=
this
.
canvas
.
width
||
newHeight
!=
this
.
canvas
.
height
)
{
this
.
canvas
.
width
=
newWidth
;
this
.
canvas
.
width
=
newWidth
;
...
@@ -805,7 +790,7 @@ Ripples.prototype = {
...
@@ -805,7 +790,7 @@ Ripples.prototype = {
}
}
},
},
destroy
:
function
()
{
destroy
()
{
this
.
$el
this
.
$el
.
off
(
'.ripples'
)
.
off
(
'.ripples'
)
.
removeClass
(
'jquery-ripples'
)
.
removeClass
(
'jquery-ripples'
)
...
@@ -822,29 +807,29 @@ Ripples.prototype = {
...
@@ -822,29 +807,29 @@ Ripples.prototype = {
this
.
destroyed
=
true
;
this
.
destroyed
=
true
;
},
},
show
:
function
()
{
show
()
{
this
.
visible
=
true
;
this
.
visible
=
true
;
this
.
$canvas
.
show
();
this
.
$canvas
.
show
();
this
.
hideCssBackground
();
this
.
hideCssBackground
();
},
},
hide
:
function
()
{
hide
()
{
this
.
visible
=
false
;
this
.
visible
=
false
;
this
.
$canvas
.
hide
();
this
.
$canvas
.
hide
();
this
.
restoreCssBackground
();
this
.
restoreCssBackground
();
},
},
pause
:
function
()
{
pause
()
{
this
.
running
=
false
;
this
.
running
=
false
;
},
},
play
:
function
()
{
play
()
{
this
.
running
=
true
;
this
.
running
=
true
;
},
},
set
:
function
(
property
,
value
)
{
set
(
property
,
value
)
{
switch
(
property
)
{
switch
(
property
)
{
case
'dropRadius'
:
case
'dropRadius'
:
case
'perturbance'
:
case
'perturbance'
:
...
@@ -857,47 +842,46 @@ Ripples.prototype = {
...
@@ -857,47 +842,46 @@ Ripples.prototype = {
this
.
loadImage
();
this
.
loadImage
();
break
;
break
;
}
}
}
},
};
};
// RIPPLES PLUGIN DEFINITION
// RIPPLES PLUGIN DEFINITION
// ==========================
// ==========================
var
old
=
$
.
fn
.
ripples
;
const
old
=
$
.
fn
.
ripples
;
$
.
fn
.
ripples
=
function
(
option
)
{
$
.
fn
.
ripples
=
function
(
option
)
{
if
(
!
config
)
{
if
(
!
config
)
{
throw
new
Error
(
'Your browser does not support WebGL, the OES_texture_float extension or rendering to floating point textures.'
);
throw
new
Error
(
'Your browser does not support WebGL, the OES_texture_float extension or rendering to floating point textures.'
,
);
}
}
var
args
=
(
arguments
.
length
>
1
)
?
Array
.
prototype
.
slice
.
call
(
arguments
,
1
)
:
undefined
;
const
args
=
arguments
.
length
>
1
?
Array
.
prototype
.
slice
.
call
(
arguments
,
1
)
:
undefined
;
return
this
.
each
(
function
()
{
return
this
.
each
(
function
()
{
var
$this
=
$
(
this
),
const
$this
=
$
(
this
);
data
=
$this
.
data
(
'ripples'
),
let
data
=
$this
.
data
(
'ripples'
);
options
=
$
.
extend
({},
Ripples
.
DEFAULTS
,
$this
.
data
(),
typeof
option
==
'object'
&&
option
);
const
options
=
$
.
extend
({},
Ripples
.
DEFAULTS
,
$this
.
data
(),
typeof
option
=
==
'object'
&&
option
);
if
(
!
data
&&
typeof
option
==
'string'
)
{
if
(
!
data
&&
typeof
option
=
==
'string'
)
{
return
;
return
;
}
}
if
(
!
data
)
{
if
(
!
data
)
{
$this
.
data
(
'ripples'
,
(
data
=
new
Ripples
(
this
,
options
)));
$this
.
data
(
'ripples'
,
(
data
=
new
Ripples
(
this
,
options
)));
}
}
else
if
(
typeof
option
===
'string'
)
{
else
if
(
typeof
option
==
'string'
)
{
Ripples
.
prototype
[
option
].
apply
(
data
,
args
);
Ripples
.
prototype
[
option
].
apply
(
data
,
args
);
}
}
});
});
};
};
$
.
fn
.
ripples
.
Constructor
=
Ripples
;
$
.
fn
.
ripples
.
Constructor
=
Ripples
;
// RIPPLES NO CONFLICT
// RIPPLES NO CONFLICT
// ====================
// ====================
$
.
fn
.
ripples
.
noConflict
=
function
()
{
$
.
fn
.
ripples
.
noConflict
=
function
()
{
$
.
fn
.
ripples
=
old
;
$
.
fn
.
ripples
=
old
;
return
this
;
return
this
;
};
};
});
})));
src/assets/js/ripples/ripples.js
View file @
0394433d
...
@@ -2,26 +2,20 @@
...
@@ -2,26 +2,20 @@
/* globals jQuery, navigator */
/* globals jQuery, navigator */
(
function
(
$
,
window
,
document
,
undefined
)
{
(
function
(
$
,
window
,
document
,
undefined
)
{
"use strict"
;
/**
/**
* Define the name of the plugin
* Define the name of the plugin
*/
*/
var
ripples
=
"ripples"
;
const
ripples
=
'ripples'
;
/**
/**
* Get an instance of the plugin
* Get an instance of the plugin
*/
*/
var
self
=
null
;
let
self
=
null
;
/**
/**
* Define the defaults of the plugin
* Define the defaults of the plugin
*/
*/
var
defaults
=
{};
const
defaults
=
{};
/**
/**
* Create the main plugin function
* Create the main plugin function
...
@@ -39,90 +33,79 @@
...
@@ -39,90 +33,79 @@
this
.
init
();
this
.
init
();
}
}
/**
/**
* Initialize the plugin
* Initialize the plugin
*/
*/
Ripples
.
prototype
.
init
=
function
()
{
Ripples
.
prototype
.
init
=
function
()
{
var
$element
=
this
.
element
;
const
$element
=
this
.
element
;
$element
.
on
(
"mousedown touchstart"
,
function
(
event
)
{
$element
.
on
(
'mousedown touchstart'
,
function
(
event
)
{
/**
/**
* Verify if the user is just touching on a device and return if so
* Verify if the user is just touching on a device and return if so
*/
*/
if
(
self
.
isTouch
()
&&
event
.
type
===
"mousedown"
)
{
if
(
self
.
isTouch
()
&&
event
.
type
===
'mousedown'
)
{
return
;
return
;
}
}
/**
/**
* Verify if the current element already has a ripple wrapper element and
* Verify if the current element already has a ripple wrapper element and
* creates if it doesn't
* creates if it doesn't
*/
*/
if
(
!
(
$element
.
find
(
".ripple-container"
).
length
)
)
{
if
(
!
$element
.
find
(
'.ripple-container'
).
length
)
{
$element
.
append
(
"<div class=
\"
ripple-container
\"
></div>"
);
$element
.
append
(
'<div class="ripple-container"></div>'
);
}
}
/**
/**
* Find the ripple wrapper
* Find the ripple wrapper
*/
*/
var
$wrapper
=
$element
.
children
(
".ripple-container"
);
const
$wrapper
=
$element
.
children
(
'.ripple-container'
);
/**
/**
* Get relY and relX positions
* Get relY and relX positions
*/
*/
var
relY
=
self
.
getRelY
(
$wrapper
,
event
);
const
relY
=
self
.
getRelY
(
$wrapper
,
event
);
var
relX
=
self
.
getRelX
(
$wrapper
,
event
);
const
relX
=
self
.
getRelX
(
$wrapper
,
event
);
/**
/**
* If relY and/or relX are false, return the event
* If relY and/or relX are false, return the event
*/
*/
if
(
!
relY
&&
!
relX
)
{
if
(
!
relY
&&
!
relX
)
{
return
;
return
;
}
}
/**
/**
* Get the ripple color
* Get the ripple color
*/
*/
var
rippleColor
=
self
.
getRipplesColor
(
$element
);
const
rippleColor
=
self
.
getRipplesColor
(
$element
);
/**
/**
* Create the ripple element
* Create the ripple element
*/
*/
var
$ripple
=
$
(
"<div></div>"
);
const
$ripple
=
$
(
'<div></div>'
);
$ripple
$ripple
.
addClass
(
'ripple'
).
css
({
.
addClass
(
"ripple"
)
left
:
relX
,
.
css
({
top
:
relY
,
"left"
:
relX
,
'background-color'
:
rippleColor
,
"top"
:
relY
,
"background-color"
:
rippleColor
});
});
/**
/**
* Append the ripple to the wrapper
* Append the ripple to the wrapper
*/
*/
$wrapper
.
append
(
$ripple
);
$wrapper
.
append
(
$ripple
);
/**
/**
* Make sure the ripple has the styles applied (ugly hack but it works)
* Make sure the ripple has the styles applied (ugly hack but it works)
*/
*/
(
function
()
{
return
window
.
getComputedStyle
(
$ripple
[
0
]).
opacity
;
})();
(
function
()
{
return
window
.
getComputedStyle
(
$ripple
[
0
]).
opacity
;
})();
/**
/**
* Turn on the ripple animation
* Turn on the ripple animation
*/
*/
self
.
rippleOn
(
$element
,
$ripple
);
self
.
rippleOn
(
$element
,
$ripple
);
/**
/**
* Call the rippleEnd function when the transition "on" ends
* Call the rippleEnd function when the transition "on" ends
*/
*/
...
@@ -130,115 +113,104 @@
...
@@ -130,115 +113,104 @@
self
.
rippleEnd
(
$ripple
);
self
.
rippleEnd
(
$ripple
);
},
500
);
},
500
);
/**
/**
* Detect when the user leaves the element
* Detect when the user leaves the element
*/
*/
$element
.
on
(
"mouseup mouseleave touchend"
,
function
()
{
$element
.
on
(
'mouseup mouseleave touchend'
,
function
()
{
$ripple
.
data
(
"mousedown"
,
"off"
);
$ripple
.
data
(
'mousedown'
,
'off'
);
if
(
$ripple
.
data
(
"animating"
)
===
"off"
)
{
if
(
$ripple
.
data
(
'animating'
)
===
'off'
)
{
self
.
rippleOut
(
$ripple
);
self
.
rippleOut
(
$ripple
);
}
}
});
});
});
});
};
};
/**
/**
* Get the new size based on the element height/width and the ripple width
* Get the new size based on the element height/width and the ripple width
*/
*/
Ripples
.
prototype
.
getNewSize
=
function
(
$element
,
$ripple
)
{
Ripples
.
prototype
.
getNewSize
=
function
(
$element
,
$ripple
)
{
return
(
Math
.
max
(
$element
.
outerWidth
(),
$element
.
outerHeight
())
/
$ripple
.
outerWidth
())
*
2.5
;
return
(
Math
.
max
(
$element
.
outerWidth
(),
$element
.
outerHeight
())
/
$ripple
.
outerWidth
())
*
2.5
;
};
};
/**
/**
* Get the relX
* Get the relX
*/
*/
Ripples
.
prototype
.
getRelX
=
function
(
$wrapper
,
event
)
{
Ripples
.
prototype
.
getRelX
=
function
(
$wrapper
,
event
)
{
var
wrapperOffset
=
$wrapper
.
offset
();
const
wrapperOffset
=
$wrapper
.
offset
();
if
(
!
self
.
isTouch
())
{
if
(
!
self
.
isTouch
())
{
/**
/**
* Get the mouse position relative to the ripple wrapper
* Get the mouse position relative to the ripple wrapper
*/
*/
return
event
.
pageX
-
wrapperOffset
.
left
;
return
event
.
pageX
-
wrapperOffset
.
left
;
}
else
{
}
/**
/**
* Make sure the user is using only one finger and then get the touch
* Make sure the user is using only one finger and then get the touch
* position relative to the ripple wrapper
* position relative to the ripple wrapper
*/
*/
event
=
event
.
originalEvent
;
event
=
event
.
originalEvent
;
if
(
event
.
touches
.
length
===
1
)
{
if
(
event
.
touches
.
length
===
1
)
{
return
event
.
touches
[
0
].
pageX
-
wrapperOffset
.
left
;
return
event
.
touches
[
0
].
pageX
-
wrapperOffset
.
left
;
}
}
return
false
;
return
false
;
}
};
};
/**
/**
* Get the relY
* Get the relY
*/
*/
Ripples
.
prototype
.
getRelY
=
function
(
$wrapper
,
event
)
{
Ripples
.
prototype
.
getRelY
=
function
(
$wrapper
,
event
)
{
var
wrapperOffset
=
$wrapper
.
offset
();
const
wrapperOffset
=
$wrapper
.
offset
();
if
(
!
self
.
isTouch
())
{
if
(
!
self
.
isTouch
())
{
/**
/**
* Get the mouse position relative to the ripple wrapper
* Get the mouse position relative to the ripple wrapper
*/
*/
return
event
.
pageY
-
wrapperOffset
.
top
;
return
event
.
pageY
-
wrapperOffset
.
top
;
}
else
{
}
/**
/**
* Make sure the user is using only one finger and then get the touch
* Make sure the user is using only one finger and then get the touch
* position relative to the ripple wrapper
* position relative to the ripple wrapper
*/
*/
event
=
event
.
originalEvent
;
event
=
event
.
originalEvent
;
if
(
event
.
touches
.
length
===
1
)
{
if
(
event
.
touches
.
length
===
1
)
{
return
event
.
touches
[
0
].
pageY
-
wrapperOffset
.
top
;
return
event
.
touches
[
0
].
pageY
-
wrapperOffset
.
top
;
}
}
return
false
;
return
false
;
}
};
};
/**
/**
* Get the ripple color
* Get the ripple color
*/
*/
Ripples
.
prototype
.
getRipplesColor
=
function
(
$element
)
{
Ripples
.
prototype
.
getRipplesColor
=
function
(
$element
)
{
const
color
=
$element
.
data
(
'ripple-color'
)
var
color
=
$element
.
data
(
"ripple-color"
)
?
$element
.
data
(
"ripple-color"
)
:
window
.
getComputedStyle
(
$element
[
0
]).
color
;
?
$element
.
data
(
'ripple-color'
)
:
window
.
getComputedStyle
(
$element
[
0
]).
color
;
return
color
;
return
color
;
};
};
/**
/**
* Verify if the client browser has transistion support
* Verify if the client browser has transistion support
*/
*/
Ripples
.
prototype
.
hasTransitionSupport
=
function
()
{
Ripples
.
prototype
.
hasTransitionSupport
=
function
()
{
var
thisBody
=
document
.
body
||
document
.
documentElement
;
const
thisBody
=
document
.
body
||
document
.
documentElement
;
var
thisStyle
=
thisBody
.
style
;
const
thisStyle
=
thisBody
.
style
;
var
support
=
(
const
support
=
thisStyle
.
transition
!==
undefined
||
thisStyle
.
transition
!==
undefined
||
thisStyle
.
WebkitTransition
!==
undefined
||
thisStyle
.
WebkitTransition
!==
undefined
||
thisStyle
.
MozTransition
!==
undefined
||
thisStyle
.
MozTransition
!==
undefined
||
thisStyle
.
MsTransition
!==
undefined
||
thisStyle
.
MsTransition
!==
undefined
||
thisStyle
.
OTransition
!==
undefined
thisStyle
.
OTransition
!==
undefined
;
);
return
support
;
return
support
;
};
};
/**
/**
* Verify if the client is using a mobile device
* Verify if the client is using a mobile device
*/
*/
...
@@ -246,79 +218,78 @@
...
@@ -246,79 +218,78 @@
return
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
.
test
(
navigator
.
userAgent
);
return
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
.
test
(
navigator
.
userAgent
);
};
};
/**
/**
* End the animation of the ripple
* End the animation of the ripple
*/
*/
Ripples
.
prototype
.
rippleEnd
=
function
(
$ripple
)
{
Ripples
.
prototype
.
rippleEnd
=
function
(
$ripple
)
{
$ripple
.
data
(
"animating"
,
"off"
);
$ripple
.
data
(
'animating'
,
'off'
);
if
(
$ripple
.
data
(
"mousedown"
)
===
"off"
)
{
if
(
$ripple
.
data
(
'mousedown'
)
===
'off'
)
{
self
.
rippleOut
(
$ripple
);
self
.
rippleOut
(
$ripple
);
}
}
};
};
/**
/**
* Turn off the ripple effect
* Turn off the ripple effect
*/
*/
Ripples
.
prototype
.
rippleOut
=
function
(
$ripple
)
{
Ripples
.
prototype
.
rippleOut
=
function
(
$ripple
)
{
$ripple
.
off
();
$ripple
.
off
();
if
(
self
.
hasTransitionSupport
())
{
if
(
self
.
hasTransitionSupport
())
{
$ripple
.
addClass
(
"ripple-out"
);
$ripple
.
addClass
(
'ripple-out'
);
}
else
{
}
else
{
$ripple
.
animate
({
"opacity"
:
0
},
100
,
function
()
{
$ripple
.
animate
({
opacity
:
0
},
100
,
function
()
{
$ripple
.
trigger
(
"transitionend"
);
$ripple
.
trigger
(
'transitionend'
);
});
});
}
}
$ripple
.
on
(
"transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd"
,
function
()
{
$ripple
.
on
(
'transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'
,
function
()
{
$ripple
.
remove
();
$ripple
.
remove
();
});
});
};
};
/**
/**
* Turn on the ripple effect
* Turn on the ripple effect
*/
*/
Ripples
.
prototype
.
rippleOn
=
function
(
$element
,
$ripple
)
{
Ripples
.
prototype
.
rippleOn
=
function
(
$element
,
$ripple
)
{
var
size
=
self
.
getNewSize
(
$element
,
$ripple
);
const
size
=
self
.
getNewSize
(
$element
,
$ripple
);
if
(
self
.
hasTransitionSupport
())
{
if
(
self
.
hasTransitionSupport
())
{
$ripple
$ripple
.
css
({
.
css
({
"-ms-transform"
:
"scale("
+
size
+
")"
,
'-ms-transform'
:
`scale(
${
size
}
)`
,
"-moz-transform"
:
"scale("
+
size
+
")"
,
'-moz-transform'
:
`scale(
${
size
}
)`
,
"-webkit-transform"
:
"scale("
+
size
+
")"
,
'-webkit-transform'
:
`scale(
${
size
}
)`
,
"transform"
:
"scale("
+
size
+
")"
transform
:
`scale(
${
size
}
)`
,
})
})
.
addClass
(
"ripple-on"
)
.
addClass
(
'ripple-on'
)
.
data
(
"animating"
,
"on"
)
.
data
(
'animating'
,
'on'
)
.
data
(
"mousedown"
,
"on"
);
.
data
(
'mousedown'
,
'on'
);
}
else
{
}
else
{
$ripple
.
animate
({
$ripple
.
animate
(
"width"
:
Math
.
max
(
$element
.
outerWidth
(),
$element
.
outerHeight
())
*
2
,
{
"height"
:
Math
.
max
(
$element
.
outerWidth
(),
$element
.
outerHeight
())
*
2
,
width
:
Math
.
max
(
$element
.
outerWidth
(),
$element
.
outerHeight
())
*
2
,
"margin-left"
:
Math
.
max
(
$element
.
outerWidth
(),
$element
.
outerHeight
())
*
(
-
1
),
height
:
Math
.
max
(
$element
.
outerWidth
(),
$element
.
outerHeight
())
*
2
,
"margin-top"
:
Math
.
max
(
$element
.
outerWidth
(),
$element
.
outerHeight
())
*
(
-
1
),
'margin-left'
:
Math
.
max
(
$element
.
outerWidth
(),
$element
.
outerHeight
())
*
-
1
,
"opacity"
:
0.2
'margin-top'
:
Math
.
max
(
$element
.
outerWidth
(),
$element
.
outerHeight
())
*
-
1
,
},
500
,
function
()
{
opacity
:
0.2
,
$ripple
.
trigger
(
"transitionend"
);
},
});
500
,
function
()
{
$ripple
.
trigger
(
'transitionend'
);
},
);
}
}
};
};
/**
/**
* Create the jquery plugin function
* Create the jquery plugin function
*/
*/
$
.
fn
.
ripples
=
function
(
options
)
{
$
.
fn
.
ripples
=
function
(
options
)
{
return
this
.
each
(
function
()
{
return
this
.
each
(
function
()
{
if
(
!
$
.
data
(
this
,
"plugin_"
+
ripples
))
{
if
(
!
$
.
data
(
this
,
`plugin_
${
ripples
}
`
))
{
$
.
data
(
this
,
"plugin_"
+
ripples
,
new
Ripples
(
this
,
options
));
$
.
data
(
this
,
`plugin_
${
ripples
}
`
,
new
Ripples
(
this
,
options
));
}
}
});
});
};
};
})(
jQuery
,
window
,
document
);
})(
jQuery
,
window
,
document
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment