Archive for the ‘jquery’ Category

jQuery Object Accessors

jQuery Object Accessors

สำหรับ jQuery ในส่วน Object Accessor หรือเรียกว่าเป็นเรื่องของ function ของคำสั่งที่ jQuery เตรียมไว้ให้กับเราซึ่งมีอยู่ ด้วยกันดังนี้

Core / each

ส่วนนี้คือการทำงานในลักษณะ loop ซึ่งทำให้เราสามารถที่จะทำงาน วนข้อมูลง่ายๆ จนกว่าจะครบตามจำนวน Length ของ selector ที่เลือก ซึ่งจะขออธิบายในตัวอย่างนี้นะครับ

จากตัวอย่างนี้ จะเป็นการวน loop ตามจำนวน ที่ selector คือ $(“div”) ทั้งหมด จะสังเกตุเห็นว่า จะมี alert บอกว่ากำลังทำงานกับ tag div ตัวไหนอยู่ และ parameter i ก็จะเป็นตัวบอก รอบที่อยู่ใน loop เริ่มจาก 0

<script language=”javascript”>

$(document).ready(function(){

$( document.body ).click( function () {

$(”div”).each( function(i) {

alert( (i+1) + “. Working in Tag =” + this.innerHTML);

if (this.style.color !=”blue”) {

this.style.color=”blue”;

}else{

this.style.color=””;

}

} );

} );

});

</script>

<style type=”text/css”>

div { color:red; text-align:center; cursor:pointer;

font-weight:bolder; width:300px; }

</style>

มี Tag div อยู่ 3 ตัวซึ่งเราจะมองว่า Tag div แต่ละตัวคือ element แต่ละ element

<div>Click here</div>

<div>to iterate through</div>

<div>these divs.</div>

Core/Length

การใช้ method length เพื่อนับจำนวน array ของ Selector (method length เป็นของ javascript อยู่แล้ว) ซึ่งเราสามารถนำมาประยุกต์ใช้กับงานได้ ยกตัวอย่างเช่น ตัวอย่างการเพิ่มแถวของ Table และ ลบแถวของ Table อย่างง่ายๆ ซึ่งเราจะใช้ manipulation append เพื่อ create element แถวลงไปใน table โดยต่อท้ายแถวสุดท้ายลงไป

<script language=”javascript”>

$(document).ready(function(){

// ปุ่ม Insert

$(”#btnIn”).click(function () {

var txtnum=$(”.trcolor”).length+1;

$(”#tblData”).append($(”<tr class=\”trcolor\”> ” +

“           <td>”+txtnum+”</td>” +

“           <td><input type=\”text\”></td>”+

“           <td><input type=\”text\”></td>”+

“           <td><input type=\”text\”></td>”+

” </tr>”));

getMsg();

});

// ปุ่ม Delete

$(”#btnDel”).click(function (){

$(”.trcolor:last”).remove();

getMsg();

});

// function บอกจำนวนแถว โดยใช้ method length

function getMsg(){

var n=$(”.trcolor”).length;

$(”#lblMsg”).text(”There are ” + n + ” Rows.”);

}

});

</script>

<style type=”text/css”>

.trcolor { background:#F2F2F2; }

</style>

<button id=”btnIn”>RUN</button> | <button id=”btnDel”>Del</button>

<div id=”lblMsg”></div>

<table id=”tblData” width=”600″ border=”0″ cellpadding=”1″ cellspacing=”1″ bgcolor=”#CCCCCC”>

<tr>

<td width=”12%”><strong>Number</strong></td>

<td width=”24%”><strong> Name</strong></td>

<td width=”22%”><strong>Surname</strong></td>

<td width=”42%”><strong>Tel</strong></td>

</tr>

</table>

Core/eq(position)

Argument position คือการใส่ Number Index ลงไป

การใช้ eq สำหรับระบุ ไปยัง Index ของ element แบบเฉพาะเจาะจงลงไปในตัวใดตัวหนึ่ง จะอธิบายด้วยตัวอย่างนี้นะครับ

<script language=”javascript”>

$(document).ready(function(){

/* initial function */

$(”#btnRun”).click(function (){

$(”div”).eq(2).css(”background”,”#CCFFFF”);

});

});

</script>

จากตัวอย่างนี้จะเป็นการ เลือก selector ที่ element Div และกำหนด eq ที่ 2 คือตำแหน่ง index ที่ 2 จากข้อมูลชุดด้านล่างนี้ เพื่อทำการ ใส่สี่ background

<button id=”btnRun”>RUN</button>

<div><a href=”#”>Data 01</a> < — index 0 , first element </div>

<div><a href=”#”>Data 02</a> < — index 1</div>

<div><a href=”#”>Data 03</a> < — index 2</div>

<div><a href=”#”>Data 04</a> < — index 3          , last element</div>

Core/get

การใช้ get เป็นการรับ element จาก selector ซึ่งค่าที่ได้จะเป็นลักษณะ array

<script language=”javascript”>

$(document).ready(function(){

$(”#btnRun”).click(function (){

var objDiv= $(”div”).get(); // ใช้ get ใส่ตัวแปร objDiv

var txt=[];            // ประกาศตัวแปร Array

for (var i =0;i<objDiv.length;i++){

txt.push(objDiv[i].innerHTML);

// push คือ method ของ Javascript เพื่อ ใส่ข้อมูลใน ตัวแปร Array

}

$(”span”).text(txt.join(” , “));

// join คือ method ของ Javascript เพื่อ เชื่อมสมาชิกแต่ละตัว ใน Array ซึ่ง Argument ของ join คือตัวคั่นระหว่าง สมาชิกแต่ละตัว

});

});

</script>

<button id=”btnRun”>RUN</button><br>

Data Divs Join : <span style=”color:#FF0000″></span>

<hr>

<div>One</div>

<div>Two</div>

<div>Three</div>

<div>Four</div>

Core/get (index)

เป็นการรับ element จาก selector แต่ระบุ index เข้าไปเพื่อชี้เฉพาะเจาะจง ลงไป ว่าจะเลือกตัวไหน ยกตัวอย่าง จาก ตัวอย่างด้านบน

$(”div”).get(2).innerHTML หากกำหนด get(2) จะได้ค่า กลับมาเป็น Three เนื่องจากจะไปจับ elements Index ที่ 2 นับจาก 0 ซึ่งก็คือ แทก <div> ที่ข้อความว่า Three

Core/index (subject)

Subject คือ element ที่จะระบุใน Index

เรื่อง index จะเป็นเรื่องการหาค่า index ใน element ว่าอยู่ตำแหน่งที่เท่าไหร่ ซึ่ง subject จะเป็นตัวระบุ current ของ index ที่ถูกกระทำ หาก ยังไม่ได้ถูกกระทำ จะ คืนค่า -1 กลับมา

จากตัวอย่างนี้ เมื่อ click ไปที่ Tag div แต่ละตัว จะแสดง alert current Index ของตัวนั้นออกมา

<script language=”javascript”>

$(document).ready(function(){

$(”div”).click(function (){

var txt=”Index is : ” + $(”div”).index(this);

alert(txt);

});         });

</script>

<div>One</div>

<div>Two</div>

<div>Three</div>

<div>Four</div>

  • Comments Off

jquery flash Upload error 500

This is what i got from the server log:

mod_security: Access denied with code 500. Error processing request body: Multipart: final boundary missing [severity "EMERGENCY"]

This error message from ModSecurity means that the request body was not
properly constructed or something was wrong with the file upload (most
likely that the client timed out and did not fully complete the upload).

Other possible reasons for this -

1) If the end of the final boundary is missing a CRLF
2) If the size specified in the Content-Length header is too small. In
this case, Apache would cut off the end of the file.

Known bugs
If you are using Apache with mod_security this will not work, you need to put the following in your .htaccess file to disable mod_security:

SecFilterEngine Off
SecFilterScanPOST Off

Disabling mod_security isn’t allowed on some shared hosts, and only do this if you know what you are doing.

So editing the .htacces is what i will do next

  • Comments Off

See demo
drag and drop the left table row and see result in right table

Why have another plugin?

Dragging and dropping rows within a table can?t be handled by general purpose drag and drop utilities for a number of reasons, not least because you need to move the whole row, not just the cell that receives the mouse events. Re-parenting the row also requires specific code. Sadly also, effects like fadeIn and fadeOut don?t work well with table rows on all browsers, so we have to go for simpler effects.
What does it do?

This TableDnD plugin allows the user to reorder rows within a table, for example if they represent an ordered list (tasks by priority for example). Individual rows can be marked as non-draggable and/or non-droppable (so other rows can?t be dropped onto them). Rows can have as many cells as necessary and the cells can contain form elements.

How to use


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>mcDropdown jQuery Plug-in</title>
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript" src="jquery.tablednd.js"></script>
<link type="text/css" href="style.css" rel="stylesheet" media="all" />
<script type="text/javascript">
$(document).ready(function() {
$('#table-3').tableDnD({
        onDrop: function(table, row) {
            //alert($.tableDnD.serialize());
			$('#AjaxResult').load("ajax.php?" + $.tableDnD.serialize());
        }
    });
 });
</script>
</head>

<body>
<div class="tableDemo">
<div id="AjaxResult">
<img src="images/1.gif"> 1 One<br>
<img src="images/2.gif"> 2 Two<br>
<img src="images/3.gif"> 3 Three (Can&amp;amp;amp;amp;#8217;t drop on this row)<br>
<img src="images/4.gif"> 4 Four<br>
<img src="images/5.gif"> 5 Five (Can&amp;amp;amp;amp;#8217;t drag this row)<br>
<img src="images/6.gif"> 6 Six<br>
</div>
<table id="table-3" cellspacing="0" cellpadding="2" height="200">
<tr id="1">
<td bgcolor="#FFFF99">1</td>
<td bgcolor="#FFFF99">One</td>
</tr>
<tr id="2">
<td bgcolor="#FF99CC">2</td>
<td bgcolor="#FF99CC">Two</td>
</tr>
<tr id="3" class="nodrop">
<td bgcolor="#0066CC">3</td>
<td bgcolor="#0066CC">Three (Can&amp;amp;amp;amp;#8217;t drop on this row)</td>
</tr>
<tr id="4">
<td bgcolor="#33CC66">4</td>
<td bgcolor="#33CC66">Four</td>
</tr>
<tr id="5" class="nodrag">
<td bgcolor="#990099">5</td>
<td bgcolor="#990099">Five (Can&amp;amp;amp;amp;#8217;t drag this row)</td>
</tr>
<tr id="6">
<td bgcolor="#FF0000">6</td>
<td bgcolor="#FF0000">Six</td>
</tr>
</table>
</div>
</body>
</html>

php code ajax.php


<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$result = $_REQUEST["table-3"];
$val = array("","One","Two","Three (Can&amp;amp;amp;amp;#8217;t drop on this row)","Four","Five (Can&amp;amp;amp;amp;#8217;t drag this row)","Six");
$pval = array("","1.gif","2.gif","3.gif","4.gif","5.gif","6.gif");
foreach($result as $value) {
	echo "<img src=\"images/$pval[$value]\"> $value $val[$value]<br/>";
}
?>

More info
http://www.isocra.com/2008/02/table-drag-and-drop-jquery-plugin/

For our help desk, customer service and call center software applications, we needed to develop a unique UI control that would allow users to select from a complex hierarchical tree of options. We wanted this control to be intuitive and it had to allow for both quick mouse and keyboard entry. After many rounds of discussion internally and with customers, we came up with the following list of requirements:

* Menus must resize and position themselves to stay in the viewport. Options should not show up off screen where users would need to scroll to select them.
* Quick keyboard entry. Many users prefer keyboard entry for speed of data entry, so efficient keyboard entry is a must.
* Must be able to handle very large complex (deep) data trees, but work equally as well with very small sets of data.
* Easy implementation.

Demo

While the list of requirements was not long, we knew there would be substantial technical obstacles to overcome. The biggest obstacle to solve would be how to ensure that the menu and all of its submenus remain on the screen at all times.

To overcome this obstacle, we spent a lot of time developing code that would automatically split long lists into multiple columns and then position itself so that it always fits within the viewport. The overall effect is somewhat similar to the Microsoft? Windows? “Start > All Programs” menu. However, the algorithm we use should keep the menus laid out in a more compact layout?which we believe offers quicker selection of the menu items. The screenshot below shows what the menu looks like when used with a very large menu.

How to use


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>mcDropdown jQuery Plug-in</title>
<script type="text/javascript" src="./lib/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="./lib/jquery.mcdropdown.js"></script>
<script type="text/javascript" src="./lib/jquery.bgiframe.js"></script>
<link type="text/css" href="./css/jquery.mcdropdown.css" rel="stylesheet" media="all" />
<script type="text/javascript">
<!--//
// on DOM ready
$(document).ready(function (){
//$("#current_rev").html("v"+$.mcDropdown.version);
  $("#category").mcDropdown("#categorymenu");
});
//-->
</script>
</head>

<body>
<form name="f1" method="get" action="">
	Please select a category:<br />
	<input type="text" name="category" id="category" value="">
<INPUT TYPE="submit" value="ok">
    <ul id="categorymenu" class="mcdropdown_menu">
        <li rel="1">
            Arts &amp;amp;amp;amp;amp; Humanities
            <ul>
                <li rel="2">
                    Photography
                    <ul>
                        <li rel="3">
                            3D
                            </li>
                        <li rel="4">
                            Digital
                            </li>
                    </ul>
                </li>
                <li rel="5">
                    History
                    </li>
                <li rel="6">
                    Literature
                    </li>
            </ul>
        </li>
        <li rel="7">
            Business &amp;amp;amp;amp;amp; Economy
          </li>
        <li rel="8">
            Computers &amp;amp;amp;amp;amp; Internet
            </li>
        <li rel="9">
            Education
            </li>
        <li rel="11">
            Entertainment
            <ul>
                <li rel="12">
                    Movies
                    </li>
                <li rel="13">
                    TV Shows
                    </li>
                <li rel="14">
                    Music
                    </li>
                <li rel="15">
                    Humor
                    </li>
            </ul>
        </li>
        <li rel="10">
            Health
            </li>
    </ul>
    </form>
</body>
</html>

More info
http://www.givainc.com/labs/mcdropdown_jquery_plugin.htm

Masked Input Plugin

This is a masked input plugin for the jQuery javascript library. It allows a user to more easily enter fixed width input where you would like them to enter the data in a certain format (dates,phone numbers, etc). It has been tested on Internet Explorer 6/7, Firefox 1.5/2, Safari, and Opera.

A mask is defined by a format made up of mask and placeholder characters. Any character not in the placeholder character list below is considered a mask character. Mask characters will be automatically entered for the user as they type and will not be able to be removed by the user.

The following placeholder characters are predefined:

* a - Represents an alpha character (A-Z,a-z)
* 9 - Represents a numeric character (0-9)
* * - Represents an alphanumeric character (A-Z,a-z,0-9)

Demo
key data in textbox

How to use


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE>Jquery</TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">

<script type='text/javascript' src="jquery-1.2.6.js"></script>
<script type="text/javascript" src="jquery.maskedinput-1.1.3"></script>
 <script type="text/javascript">
 jQuery.noConflict();
(function($) {
   $(function() {
      $.mask.addPlaceholder("~","[+-]");
      $("#date").mask("99/99/9999");
      $("#phone").mask("(999) 999-9999");
      $("#tin").mask("99-9999999");
      $("#ssn").mask("999-99-9999");
      $("#product").mask("a*-999-a999",{placeholder:" ",completed:function(){alert("You typed the following: "+this.val());}});
      $("#eyescript").mask("~9.99 ~9.99 999");
   });
})(jQuery);
</script>
<style type="text/css">
.style {
	font-size: 10px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	color: #000000;
}
</style>
</HEAD>

 <BODY>
<div id="demo">
<table>
<tr>
<td>Date</td>
<td>
<input id="date" type="text" tabindex="1"/></td>
<td>99/99/9999</td>
</tr>
<tr>
<td>Phone</td>
<td>
<input id="phone" type="text" tabindex="2"/></td>
<td>(999) 999-9999</td>
</tr>
<tr>
<td>Tax ID</td>
<td>
<input id="tin" type="text" tabindex="3"/></td>
<td>99-9999999</td>
</tr>
<tr>
<td>SSN</td>
<td>
<input id="ssn" type="text" tabindex="4"/></td>
<td>999-99-9999</td>
</tr>
<tr>
<td>Product Key</td>
<td>
<input id="product" type="text" tabindex="5"/></td>
<td>a*-999-a999</td>
</tr>
<tr>
<td>Eye Script</td>
<td>
<input id="eyescript" type="text" tabindex="6"/></td>
<td>~9.99 ~9.99 999</td>
</tr>
</table>
</div>
 </BODY>
</HTML>

More info
http://digitalbush.com/projects/masked-input-plugin

How does in place editing work?

Normal flow is this. User clicks text on web page. Block of text becomes a form. User edits contents and presses submit button. New text is sent to webserver and saved. Form becomes normal text again.

Demo



How to use


<?php      

$folder = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$url    = sprintf('http://%s%s', $_SERVER['SERVER_NAME'], $folder);

?>
<html>
<head>
<title>jEditable - Textile callback and tooltips demo</title>
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<script src="lib/jquery.js" type="text/javascript"></script>
<script src="lib/jquery.jeditable.js" type="text/javascript"></script>
<style type="text/css">
<!–
.style1 {
	font-size: large;
	font-weight: bold;
}
–>
</style>
</head>
<html>
<div id="header">
<h1 class="editable_textarea style1">Test Edit in place5  Click Here to
edit</h1>
<br>
<h1 class="editable_textarea_over style1">Test Edit in place6
Click Here to edit</h1>
<br>
</div>

<script type="text/javascript">
// <![CDATA[
$(document).ready(function() {
    $(".editable_textarea").editable("<?php print $url ?>echo.php", {
        indicator : "<img src='img/indicator.gif'>",
        type      : "textarea",
        submit    : "OK",
		cancel    : "Cancel",
		onblur    : 'submit',
        tooltip   : "Click to edit..."
    });

	$(".editable_textarea_over").editable("<?php print $url ?>echo.php", {
        indicator : "<img src='img/indicator.gif'>",
        type      : "textarea",
        submit    : "OK",
		cancel    : "Cancel",
        tooltip   : "Click to edit..."
		event     : "mouseover"
    });

});
// ]]>
</script>

</html>

echo.php


<?php

print $_POST['value'];

?>

More info
http://www.appelsiini.net/projects/jeditable

Time

Mp3

Msn status

  • manon2029@hotmail.com is

Chat with Meeh

Donate

    If you find an article useful, then please make a donation.

หมวดหมู่

UserOnline

Counter

  • Visitors today: 89
  • Visitors yesterday: 86
  • Visitors per day: 412
  • Max. visitors per day: 255
  • Total page views: 167,482
  • Page views of this page: 412
  • Currently online: 1
  • Max. online: 36
  • Total visitors: 36,257
  • counterStatistics