Skip to content

Commit

Permalink
Image Preloader
Browse files Browse the repository at this point in the history
  • Loading branch information
masnun committed Nov 11, 2011
1 parent 9616827 commit ad47f59
Showing 1 changed file with 127 additions and 116 deletions.
243 changes: 127 additions & 116 deletions avro-phonetic.php
Original file line number Diff line number Diff line change
@@ -1,106 +1,104 @@
<?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');
add_action('admin_footer', 'avro_phonetic_hidden_div');

// 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');
add_action('wp_footer', 'avro_phonetic_hidden_div');

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()
{
?>
/**
* @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');
add_action('admin_footer', 'avro_phonetic_hidden_div');

// 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');
add_action('wp_footer', 'avro_phonetic_hidden_div');

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 {
#avro-phonetic-notif {
border: 0;
position: fixed;
top: 200px;
right:0;

top: 200px;
right: 0;

}
</style>
<?php

}
}

function avro_phonetic_styles()
{
?>
function avro_phonetic_styles()
{
?>

<style type="text/css">
#avro-phonetic-notif {
#avro-phonetic-notif {
border: 0;
position: fixed;
top: 200px;
right:0;

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_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_hidden_div()
{
echo '<div id="avro-phonetic-hidden-div" style="visibility: hidden;"><img src="https://github.com/masnun/Avro-Phonetic-WP-Plugin/raw/master/avro-english.png" width="50px" height="50px" alt="E" /><img src="https://github.com/masnun/Avro-Phonetic-WP-Plugin/raw/master/avro-bangla.png" width="50px" height="50px" alt="B" /></div>';
}
function avro_phonetic_hidden_div()
{
echo '<div id="avro-phonetic-hidden-div" style="visibility: hidden;"><img src="https://github.com/masnun/Avro-Phonetic-WP-Plugin/raw/master/avro-english.png" width="50px" height="50px" alt="E" /><img src="https://github.com/masnun/Avro-Phonetic-WP-Plugin/raw/master/avro-bangla.png" width="50px" height="50px" alt="B" /></div>';
}

function avro_phonetic()
{
?>
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') {
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';
script.onload = enable_avro;
script.src = 'https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js';
root.appendChild(script);
}
else {
Expand All @@ -114,67 +112,80 @@ function enable_avro() {
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';
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}, stateHandler);

jQuery("#avro-phonetic-notif").hide();

jQuery('textarea, input[type=text]').focus(function() {
stateHandler(jQuery(this).data('isBangla'));
jQuery("#avro-phonetic-notif").show();
});

jQuery('textarea, input[type=text]').blur(function() {
jQuery("#avro-phonetic-notif").hide();
});

function stateHandler(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(function() {
jQuery('textarea, input[type=text]').avro({'bn':false}, stateHandler);

jQuery("#avro-phonetic-notif").hide();

jQuery('textarea, input[type=text]').focus(function() {
stateHandler(jQuery(this).data('isBangla'));
jQuery("#avro-phonetic-notif").show();
});

jQuery('textarea, input[type=text]').blur(function() {
jQuery("#avro-phonetic-notif").hide();
});

function stateHandler(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" />')
}
}

;
});
}


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 = [];
function preload_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
// WordPress Widget

class AvroPhoneticWidget extends WP_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 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;
}
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;
}

}
}

0 comments on commit ad47f59

Please sign in to comment.