Monthly Archives: October 2013

Include JQuery UI framework from Google libs

Code snippet to include JQuery UI framework from Google libs

[javascript]
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
</head>
[/javascript]

How to make round corners by css

How to create round corners by css

Create class in css file like follows
[javascript]

.curved-5px {
-moz-border-radius:5px;
-webkit-border-radius:5px;
-khtml-border-radius:5px;
border-radius:5px;
}

[/javascript]
Assign the class to any html element like here

[javascript]
<div class=’curved-5px’>
Blah! Blah! Blah!
</div>
[/javascript]

Bonus: Drop shadow

[javascript][/javascript][/javascript]
.gray-shadow {
-moz-box-shadow: 2px 2px 2px #cccccc;
-webkit-box-shadow: 2px 2px 2px #cccccc;
box-shadow: 2px 2px 2px #cccccc;
}
[/javasript]

Upload file and change permisions in right way

		if(! move_uploaded_file($file['tmp_name'], $this->full_name ) )
			throw new Exception("Error to save the file {$this->full_name}");
		
		$oldumask = umask(0);
		
		if( ! chmod( $this->full_name, 0755 ) ) 
			throw new Exception("Error to set permissions for the file {$this->full_name}");	
		
		umask($oldumask);

How to impose maxlength on textArea using JQuery

How to impose maxlength on textArea using JQuery


$(function() {

// Get all textareas that have a “maxlength” property.
$(‘textarea[maxlength]‘).each(function() {

    // Store the jQuery object to be more efficient...
    var $textarea = $(this);

    // Store the maxlength and value of the field.
    var maxlength = $textarea.attr('maxlength');
    var val = $textarea.val();

    // Trim the field if it has content over the maxlength.
    $textarea.val(val.slice(0, maxlength));

    // Bind the trimming behavior to the "keyup" event.
    $textarea.bind('keyup', function() {
        $textarea.val($textarea.val.slice(0, maxlength));
    });

});

});

Best solution

[javascript]
window.onload = function() {
var txts = document.getElementsByTagName(‘TEXTAREA’)

for(var i = 0, l = txts.length; i < l; i++) {
if(/^[0-9]+$/.test(txts[i].getAttribute("maxlength"))) {
var func = function() {
var len = parseInt(this.getAttribute("maxlength"), 10);

if(this.value.length > len) {
alert(‘Maximum length exceeded: ‘ + len);
this.value = this.value.substr(0, len);
return false;
}
}

txts[i].onkeyup = func;
txts[i].onblur = func;
}
}
}

[/javascript]

Recursive delete folders and subfolders

[html]
public function remove_dir($dir_name_based_on_script)
{
$dir_name_to_remove = dirname( $_SERVER['SCRIPT_FILENAME']) . ‘/’. $dir_name_based_on_script;

$this-&gt;recursiveDelete($dir_name_to_remove);
}
/**
* Delete a file or recursively delete a directory
*
* @param string $str Path to file or directory
*/
private function recursiveDelete($str){
if(is_file($str)){
return @unlink($str);
}
elseif(is_dir($str)){
$scan = glob(rtrim($str,’/').’/*’);
foreach($scan as $index=&gt;$path){
$this-&gt;recursiveDelete($path);
}
return @rmdir($str);
}
}
[/html]