-
Notifications
You must be signed in to change notification settings - Fork 10
/
avro-phonetic.php
184 lines (143 loc) · 5.54 KB
/
avro-phonetic.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* @package Avro Phonetic WP Plugin
* @version 1.1
*/
/*
Plugin Name: Avro Phonetic WP Plugin
Plugin URI: http://www.masnun.me/2011/11/11/avro-phonetic-wp-plugin.html
Description: Adds Avro Phonetic to all your text inputs
Author: Masnun
Version: 1.1
Author URI: http://masnun.com
*/
//Admin Section
add_action('admin_head', 'avro_phonetic_styles_admin');
add_action('admin_head', 'avro_phonetic');
add_action('admin_footer', 'avro_phonetic_notif');
// Blog View
add_action("widgets_init", "avro_phonetic_register_widget");
add_action('wp_head', 'avro_phonetic_styles');
add_action('wp_head', 'avro_phonetic');
add_action('wp_footer', 'avro_phonetic_notif');
function avro_phonetic_disclaimer()
{
echo 'Bangla input is proudly powered by <a href="http://www.masnun.me/2011/11/11/avro-phonetic-wp-plugin.html" target="_blank">Avro Phonetic WP Plugin</a> ';
}
function avro_phonetic_register_widget()
{
register_widget("AvroPhoneticWidget");
}
function avro_phonetic_styles_admin()
{
?>
<style type="text/css">
#avro-phonetic-notif {
border: 0;
position: fixed;
top: 200px;
right: 0;
}
</style>
<?php
}
function avro_phonetic_styles()
{
?>
<style type="text/css">
#avro-phonetic-notif {
border: 0;
position: fixed;
top: 200px;
right: 0;
}
</style>
<?php
}
function avro_phonetic_notif()
{
echo '<div id="avro-phonetic-notif"><img src="https://github.com/masnun/Avro-Phonetic-WP-Plugin/raw/master/avro-english.png" width="50px" height="50px" alt="E" /></div>';
}
function avro_phonetic()
{
?>
<script type="text/javascript">
var root = (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]);
var ns = document.createElementNS && document.documentElement.namespaceURI;
if (typeof jQuery === 'undefined') {
var script = ns ? document.createElementNS(ns, 'script') : document.createElement('script');
script.type = 'text/javascript';
script.onreadystatechange = function () {
if (this.readyState == 'complete') enable_avro();
}
script.onload = enable_avro;
script.src = 'https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js';
root.appendChild(script);
}
else {
enable_avro();
}
function enable_avro() {
jQuery.noConflict();
var script = ns ? document.createElementNS(ns, 'script') : document.createElement('script');
script.type = 'text/javascript';
script.onreadystatechange = function () {
if (this.readyState == 'complete') avro_js_loader();
}
script.onload = avro_js_loader;
script.src = 'https://raw.github.com/torifat/jsAvroPhonetic/master/dist/avro-latest.js';
root.appendChild(script);
preload_avro_images();
}
function avro_js_loader() {
jQuery(function() {
jQuery('textarea, input[type=text]').avro({'bn':false}, function(isBangla){
if (isBangla) {
jQuery("#avro-phonetic-notif").html('<img src="https://github.com/masnun/Avro-Phonetic-WP-Plugin/raw/master/avro-bangla.png" width="50px" height="50px" alt="অ" />')
}
else {
jQuery("#avro-phonetic-notif").html('<img src="https://github.com/masnun/Avro-Phonetic-WP-Plugin/raw/master/avro-english.png" width="50px" height="50px" alt="E" />')
}
});
jQuery("#avro-phonetic-notif").hide();
jQuery('textarea, input[type=text]').focus(function() {
jQuery("#avro-phonetic-notif").show();
});
jQuery('textarea, input[type=text]').blur(function() {
jQuery("#avro-phonetic-notif").hide();
});
});
}
function preload_avro_images() {
var avro_preload = ['https://github.com/masnun/Avro-Phonetic-WP-Plugin/raw/master/avro-bangla.png', 'https://github.com/masnun/Avro-Phonetic-WP-Plugin/raw/master/avro-english.png'];
var avro_images = [];
for (var i = 0; i < avro_preload.length; i++) {
avro_images[i] = new Image();
avro_images[i].src = avro_preload[i];
}
}
</script>
<?php
}
// WordPress Widget
class AvroPhoneticWidget extends WP_Widget {
function AvroPhoneticWidget()
{
$widget_ops = array(
"classname" => "AvroPhoneticWidget",
"description" => "Adds Avro Phonetic Layout"
);
$this->WP_Widget('AvroPhoneticWidget', 'Avro Phonetic', $widget_ops);
}
function widget($args, $instance)
{
extract($args);
echo $before_widget;
echo $before_title;
echo '<img src="https://github.com/masnun/Avro-Phonetic-WP-Plugin/raw/master/avro-bangla.png" width="50px" height="50px" alt="অ" />';
echo $after_title;
echo "The blog supports Avro Phonetic. Press <strong>Ctrl + M</strong> to switch keyboard.<br/>";
avro_phonetic_disclaimer();
echo $after_widget;
}
}