-
Notifications
You must be signed in to change notification settings - Fork 0
/
elevator.php
69 lines (54 loc) · 2.35 KB
/
elevator.php
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
<?php
/**
* Plugin Name: Elevator
* Plugin URI: https://fatpony.me/plugins/elevator/
* Description: Smoothly escort your visitors back to the top of the page with music accompaniment and a 'Ting!' on arrival.
* Version: 1.0.5.4
* Author: Erica Franz
* Author URI: https://fatpony.me/
* Text Domain: elevator
* License: MIT
*/
defined( 'ABSPATH' ) or die( 'Please enjoy the music during your wait.' );
// Register Scripts
function elevator_enqueue_scripts() {
$path = plugin_dir_url( __FILE__ );
// Scripts
wp_register_script( 'elevator', $path . 'assets/js/elevator.min.js', false, '1.0.5.4', true );
wp_enqueue_script( 'elevator' );
}
// Hook into the 'wp_enqueue_scripts' action
add_action( 'wp_enqueue_scripts', 'elevator_enqueue_scripts' );
// Add an elevator button
function elevator_button() {
// Begin Elevator Container
$button = '<div id="elevator" class="elevator-container">';
// Basic Inline Style
$button .= '<style type="text/css" scoped="scoped">#elevator{text-align:center;}.elevator-button{padding:20px;width:auto;margin:auto;display:inline-block;}.elevator-button:hover{cursor:pointer;}</style>';
// Begin Elevator Button Container
$button .= '<div class="elevator-button">';
// Button Text
$button .= __( 'Back to Top', 'elevator' ) . '</div>';
// End Elevator Button Container
$button .= '</div>';
// End Elevator Container
$button .= '</div>';
echo $button;
}
add_action( 'wp_footer', 'elevator_button', 10 );
// And, elevate!
function elevator_script() {
$path = plugin_dir_url( __FILE__ );
$script = '<script type="text/javascript">';
$script .= 'window.onload = function() {';
$script .= 'var elementButton = document.querySelector(\'.elevator-button\');';
$script .= 'var elevator = new Elevator({';
$script .= 'element: elementButton,';
$script .= 'mainAudio: \'' . $path . 'assets/music/elevator-music.ogg\','; // Music from http://www.bensound.com/
$script .= 'endAudio: \'' . $path . 'assets/music/ding.ogg\''; // Music from http://www.bensound.com/
$script .= '});';
$script .= '}';
$script .= '</script>';
echo $script;
}
add_action( 'wp_footer', 'elevator_script', 20 );