Day: January 19, 2018

How can I load jQuery if it is not loaded?

If you need to check that a specific jQuery load or not load if not loaded then load it or not load . You can do this using jquery . This is simple code.

<script type="text/javascript">
 var baseurl="shafiqul.wordpress.com";
 var doc=document.getElementsByTagName("head").item(0);
 var jQueryScriptOutputted = false;
 var jQueryScriptOutputtedplaceholder = false;
 window.onload=function()
 {
 initJQuery();
 }
 function initJQuery() {
 if (typeof(jQuery) == "undefined") {
 if (! jQueryScriptOutputted) {
 jQueryScriptOutputted = true;
 includeJs("/js/jquery-1.4.4.min.js", true);
| }
 }
 if (! jQueryScriptOutputtedplaceholder) {
 jQueryScriptOutputtedplaceholder = true;
 includeJs("/scripts/html5_placeholder.js", true);
 }
 setTimeout("initJQuery()", 100);
 }
 function includeJs(fileName, jQ, head){
 var js=document.createElement("script");
 js.setAttribute("language", "javascript");
 js.setAttribute("type", "text/javascript");
 js.setAttribute("src", baseurl+fileName);
 if(jQ===true){
 doc.insertBefore(js, doc.firstChild);
 return false;
 }
 if(head===true){
 doc.appendChild(js);
 return false;
 }
 document.getElementsByTagName("body").item(0).appendChild(js);
 return false;
 }
 </script>

This code first check jquery already or not, if not loaded then load it. If you face any problem then please inform me.

Comment

Image crop and upload using PHP & Jquery.

If you want to crop image and also upload this crop image then you can do this using jquery and php. This is simple hmtl code

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<style>
    select,textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{display:inline-block;height:20px;padding:4px;margin-bottom:9px;font-size:13px;line-height:18px;color:#555555;}
    textarea{height:auto;}
    select,textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{background-color:#ffffff;border:1px solid #cccccc;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;-webkit-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.075);-moz-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.075);box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.075);-webkit-transition:border linear 0.2s,box-shadow linear 0.2s;-moz-transition:border linear 0.2s,box-shadow linear 0.2s;-ms-transition:border linear 0.2s,box-shadow linear 0.2s;-o-transition:border linear 0.2s,box-shadow linear 0.2s;transition:border linear 0.2s,box-shadow linear 0.2s;}textarea:focus,input[type="text"]:focus,input[type="password"]:focus,input[type="datetime"]:focus,input[type="datetime-local"]:focus,input[type="date"]:focus,input[type="month"]:focus,input[type="time"]:focus,input[type="week"]:focus,input[type="number"]:focus,input[type="email"]:focus,input[type="url"]:focus,input[type="search"]:focus,input[type="tel"]:focus,input[type="color"]:focus,.uneditable-input:focus{border-color:rgba(82, 168, 236, 0.8);outline:0;outline:thin dotted \9;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6);box-shadow:inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6);height: 20px;}
    select,input[type="radio"],input[type="checkbox"]{margin:3px 0;*margin-top:0;line-height:normal;cursor:pointer;}
    select,input[type="submit"],input[type="reset"],input[type="button"],input[type="radio"],input[type="checkbox"]{width:auto;}
    .uneditable-textarea{width:auto;height:auto;}
    #country{height: 30px;}
	.highlight
	{
		border: 1px solid red !important;
	}
</style>
<script>
function test()
{
 var isFormValid = true;

    $(".bs-example input").each(function(){
        if ($.trim($(this).val()).length == 0){
		    $(this).addClass("highlight");
            isFormValid = false;
			$(this).focus();
        }
        else{
            $(this).removeClass("highlight");
        }
    });

    if (!isFormValid) { 
		alert("Please fill in all the required fields (indicated by *)");
	}

    return isFormValid;
}	
</script>
</head>
<body>
<div class="bs-example">
    <form onsubmit="return test()">
        <div class="form-group">
            <label for="inputEmail">Email</label>
            <input type="text" class="form-control" id="inputEmail" placeholder="Email">
        </div>
        <div class="form-group">
            <label for="inputPassword">Password</label>
            <input type="password" class="form-control" id="inputPassword" placeholder="Password">
        </div>
        <button type="submit" class="btn btn-primary">Login</button>
    </form>
</div>
</body>
</html>       

then create php file. This is php code

<?php
 
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$targ_w =$_POST['w'];
$targ_h =$_POST['h'];
 
$jpeg_quality = 90;
 
if(!isset($_POST['x']) || !is_numeric($_POST['x'])) {
die('Please select a crop area.');
}
 
$src = $_POST['image_name'];
$system = explode(".", $src);
 
if (preg_match("/jpg|jpeg/", $system[1]))
{
$src_img=imagecreatefromjpeg($src);
}
if (preg_match("/png/", $system[1]))
{
$src_img = imagecreatefrompng($src);
}
if (preg_match("/gif/", $system[1]))
{
$src_img = imagecreatefromgif($src);
}
 
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
 
imagecopyresampled($dst_r,$src_img,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
 
if (preg_match("/png/", $system[1]))
{
imagepng($dst_r, $_POST['image_name']);
}
else if (preg_match("/gif/", $system[1]))
{
imagegif($dst_r, $_POST['image_name']);
}
else
{
imagejpeg($dst_r, $_POST['image_name']);
}
 
imagedestroy($dst_r);
imagedestroy($src_img);
 
exit;
}
 
?>

then run html code then php code crop image and upload it. If you face any problem then please inform me.

Comment