Free Download

Site Search

 

Top Download

Saturday, October 27, 2007

Autocomplete select dropdown


YUI Autocomplete AJAX Select Drowdown with ID
Posted in Pylons, Mako, JavaScript by thejimmyg on the October 19th, 2007
The YUI toolkit comes with a very flexible autocomplete control but a common requirement is for an autocomplete control that submits the ID associated with a text value rather than the text value itself, much like a select field submits the option value, not the contents the user selects from a drop down list.

Luckily this is fairly easy to achieve using a forceSelection option, a hidden field, and a custom itemSelectEvent handler.

First setup the imports as described on the YUI AutoComplete page:

























Now let’s set up the data structure in a Pylons controller action which the YUI component will access to populate the find as you type select dropdown. You could write similar code for Rails or PHP, it doesn’t have to be Pylons. Notice that the @jsonify decorator converts the Python data structure we return to valid JSON:

@jsonify
def get_data(self):
return {
"ResultSet": {
"totalResultsAvailable":"100",
"totalResultsReturned":2,
"firstResultPosition":1,
"Result": [
{
"ID": "897",
"Title":"foo",
"Summary":"... When foo' is used in connection with bar' it has generally traced...",
"Url":"http:\/\/www.catb.org\/~esr\/jargon\/html\/F\/foo.html",
"ModificationDate":1072684800,
"MimeType":"text\/html"
},
{
"ID": "492",
"Title":"Foo Fighters",
"Summary":"Official site with news, tour dates, discography, store, community, and more.",
"Url":"http:\/\/www.foofighters.com\/",
"ModificationDate":1138521600,
"MimeType":"text\/html"
}
]
}
}
Now we need to write the code to generate the autocomplete control. YUI uses an existing text field as the autocomplete field and this will contain whatever text is looked up. Our application requires the corresponding ID so we need a hidden field to hold that value. The hidden field should have the name you want the ID to be submitted as, the text field can have any name because it doesn’t contain the data the application needs. YUI also needs a container

which it populates with the results. Ours is called myContainer.

Here’s some HTML to achive this:

















Now let’s add some JavaScript. This can go after the HTML above:




The first line sets up a schema, the first item of which specifies where the actual results are in the data structrue returned (in this case they are in the Result list of the ResultSet dictionary), the subsequent entries specify values within each result which might be displayed in the control.

Test this example by entering foo into the field. It works as expected returning two options and allowing you to select one but the hidden myInput_id field doesn’t get populated.


To populate the hidden field we need to create a callback function and subscribe it to the autocomplete control’s itemSelectEvent. Add the following code at the end of the JavaScript above, just before the script tag:

function fnCallback(e, args) {
YAHOO.util.Dom.get("myInput_id").value = args[2][1];
}
myAutoComp.itemSelectEvent.subscribe(fnCallback);
Now, when an item is selected from the autocomplete control, fnCallback gets called with two arguments. The first is an event object e and the second is a list of arguments described here. These are:

oSelf
The AutoComplete instance.
elItem
The selected
  • element item.
    oData

  • Reference: http://jimmyg.org/2007/10/19/yui-autocomplete-ajax-select-drowdown-with-id/

    Record Mouse Movement


    I just found some piece of code i created one or two years ago. The “movelogger” records the mouse movement a users does on a web site. Just before the user leaves the current page, the recorded data get posted back to the server using AJAX.
    The cool thing is that you can “replay” these movements afterwards. The movelogger records clicks on links and other elements. In replay mode this events are fired in the exact same order as they have been recorded.
    That way it would be possible to record a websesion (the click-flow) in a heavy AJAX based application. It would even be possible to record keyboard strokes and other type of events.

    Check out the little demo of the movelogger here.

    This technique may be usefull or not. But some use cases could be:

    Instead of eye tracking, use mouse tracking.
    Analyze the usage of ajax enabled websites.
    Spionage and other Bad Things™ (not recommended).
    The whole thing is coded in javascript using Prototype and script.aculo.us with some php code on the server side.

    The data recorded on the demo website is stored only in the php session on the server and gets deleted automatically, soon after you close your browser. But theoreticaly it would be possible to store that data in some kind of database for further analysis.

    Please let me know what you think about this. Do you have any ideas for other uses of this technique ?


    ASP.NET Wrapper for ExtJs

    The ExtJs Extender controls are a pack of asp.net server controls that wrap the extjs javascript framework.The controls avaiable are:

    YuiGrid- A replacement for the GridView control that is Ajax by default , is better looking and has lots of cool features.
    TreePanel- A cross-browser TreePanel with drag and drop and inline node editing.
    TabPanel- A TabPanel control , very similar to the one in the Asp.net Ajax control toolkit but better looking.
    CalendarExtender- A control that transforms a textbox into a DatePicker.
    ResizableExtender- A control that makes any control resizable with the possibility of keeping the aspect ratio of the control being resized.
    BorderLayout - A control to implement BorderLayout functionality.
    And many more.. just look in the menu on the left
    Requirements
    Asp.net 2.0
    Asp.net Ajax 1.0
    Asp.net Ajax control toolkit

    Demo

    Javascript Image Magnification 2.4 (PopBox)


    V2.4 - Still Easy. Still Simple. Just Better.

    PopBox is an image magnification javascript solution for dynamically moving and resizing images on your web page. Javascript? Yes - I know it's nothing new and that you've been able to move and resize things in Javascript for years, but only now is there a prepackaged solution that makes it as easy as 3 lines of HTML without knowing a lick about positioning!

    If your web site has a thumbnail image gallery then you need PopBox!

    Main Features

    Ridiculously simple to use.
    Does not navigate away from the page or create separate windows.
    Does not require any special browser plug-ins. 100% script and CSS solution.
    Includes a multi-line caption capability that dynamically sizes to fit.
    Allows for a different image to be used for the thumbnail and Popped images - on page load or on image click.
    Can display a user-defined text message across the top of the image on page load on the thumbnail image.
    Can display a user-defined text message across the top of the image after it has been popped.
    Please see the Documentation Page for full instructions.

    What can PopBox do?

    It was originally created to magnify your images so you could display small ones on your web page that expanded to show the detail when the user clicked on it (thumbnails).

    Wednesday, October 10, 2007

    What is jsProgressBarHandler ?

    jsProgressBarHandler is a rewrite of the (unfortunately wrongly named) AJAX Progress / Percentage Bar by Webappers. Improvements made were the change from a set of functions to a true Prototype.js Class, reduction in the number of functions, and making it unobtrusive (if javascript is disabled you'll still see the percentage), amongst some minor tweaks.
    jsProgressBarHandler has been tested and verified working in IE6, IE7, FireFox 2 and Safari 3.0.3. Other browsers should work fine too (untested though).

    SWFUpload

    What is SWFUpload
    A small javascript/flash library to get the best of both worlds - The great upload capabilitys of flash and the accessibility and ease of html/css
    Upload multiple files at once by ctrl/shift-selecting in dialog
    Javascript callbacks on all events
    Get file information before upload starts
    Style upload elements with XHTML and css
    Display information while files are uploading using HTML
    No page reloads necessary
    Works on all platforms/browsers that has Flash support.
    Degrades gracefully to normal HTML upload form if Flash or javascript is unavailable
    Control filesize before upload starts
    Only display chosen filetypes in dialog
    Queue uploads, remove/add files before starting upload

    Download

    Friday, October 5, 2007

    Whizzywig - web based rich text editor for free






    web based rich text editor for free
    Whizzywig is easy. It lets people create rich, formatted text through a web form. It actually creates HTML (or xhtml, if you prefer) but you need no HTML knowledge to use it. If you can use a word processor or email, then you can use this.
    Whizzywig is cross-browser: it is written in Javascript, which will run in nearly all web browsers.
    Whizzywig is FREE. Free to copy, free to use and free to change. Free for personal use, free for commercial use. See
    the licence for the details. Basically, it says it is FREE.


    See it work
    Try
    this demo click!!!
    See this
    demo using text buttons.
    See this
    demo with mutiple edit areas.
    see this
    demo in Spanish OR Italian OR German OR French or dutch.
    See this
    demo generating XHTML.
    See this
    demo configured with file browsers for images and links. After clicking the image button, click [Browse] on the insert image form.
    If you want to edit pages and see the changes, try the
    whizzywig playground.
    demo download


    Fleegix.js: Simple. Useful. JavaScript.



    Fleegix.js provides an extremely lightweight, cross-browser set of JavaScript tools for building dynamic Web-app UIs.
    Fleegix.js includes the basics of what you need to build an Ajaxy Web app:
    A concise but powerful
    events system
    An industrial-strength
    XHR library
    JSON and Web form serialization
    CSS manipulation
    Visual effects
    To keep the toolkit small, more specialized features are broken off into
    optional plugins, including:
    JavaScript Dates with Olson timezone support
    a simple, no-muss-no-fuss
    XML parser
    a sortable
    Hash
    useful date utilities such as strftime, add, and diff
    Some
    color conversion utilities
    Most of the plugins can be used standalone with your JS toolkit of choice.
    Fleegix.js does not attempt to coerce JavaScript into behaving like Python, Ruby, Java, or any other language -- the code is plain, ordinary, idiomatic JavaScript. Simple, but potent stuff.
    It is well tested in the major-market-share browsers -- Firefox 1+, Internet Explorer 6+, and Safari 2.
    Fleegix.js is licensed under the
    Apache License, Version 2.

    ModalPopup with Multiple Cancel Buttons



    I recently stumbled across the following post. In the entry, the author describes a simple modal popup he has created for his hotel reservation ASP.NET AJAX web application. While developing the popup control, he ran into a problem when trying to include both a 'Close' button at the bottom of the dialog as well as a close 'X' button in the top right corner:
    I ran into a bit of a stumbling block because I wanted to have multiple buttons close the popup. I had the OK button and the cancel button centered and vertically aligned at the bottom of the window, but I also wanted a cancel button in the top right (ie "Cancel [X]") - with the familiar [X] that we know and love for closing something. The problem is, I couldn't figure out how to assign more than one control to the CancelControlID.
    Live Demo Download
    [Update 10/3/2007]: As Koen points out, the sample modal dialog doesn't look as nice in IE6 (it looks fine in FF and IE7)
    Thankfully Dave found a solution that he found to be workable. He wrapped the
    MoalPopupExtender in an UpdatePanel and explicitly called the Hide method from the server side button event handler. It sounds like this approach has worked him, but I thought I would provide a quick example of how you can dismiss the dialog without roundtripping to the web server.
    To close the popup without having to leave the client, all you have to do is call the hide function of the
    ModalPopup's client-side JavaScript behavior. Here is a quick example of the easiest way to accomplish this. Below is the markup for a modal popup that contains a message, an OK button and 6 Cancel buttons. Notice the two area's outlined in red. In the first outlined area I assigned the BehaviorID attribute of the ModalPopupExtender to a unique id ('mdlPopup' in this example). Then, in the OnClientClick of each of my Cancel buttons I pass this BehaviorID to the ASP.NET AJAX $find JavaScript shortcut function. The $find function will fetch the JavaScript behavior for the modal popup. Once I have a reference to the popup's behavior I invoke the hide function - which will hide my dialog.

    jQuery Treetable



    Take a plain html table, wrap the rows you want collapsing/expanding in a tbody with an id of treetable, map each row to it's parent row, set some options, and let jQTreeTable take it from there.
    By wrapping it in a tbody, it means you can have other rows within the same table not part of the tree, and it also means that if javascript is disabled, users still get the plain table.
    You can set which column takes the treeview effect, and you can also set which parents are collapsed initially. To do this, it must be done with an array, even if there is only one node you want collapsed.
    A highlight option can be set so that rows change colour as they are hovered over. There is dynamic striping of the rows, and there is also a custom onselect event which fires on the table cells, that can be handled with a callback function (watch the status bar when you click on a cell). Links within the cells still work as expected.
    I took the graphics files from J๖rn Zaefferer's site, and adapted them for my purposes. I hope he doesn't mind.
    Sorry I've nowhere to put comments as yet, but I will be keeping a close eye on the jquery-en list, so any feedback/bug finds would be appreciated.
    By the way, if you use the script off this page, make sure to remove the part of the script written for this page (just one line). Alternatively, you can download the zipped file here. It includes this php page with it's random treetable generator.

    var options = {openImg: "tv-collapsable.gif", shutImg: "tv-expandable.gif", leafImg: "tv-item.gif", lastOpenImg: "tv-collapsable-last.gif", lastShutImg: "tv-expandable-last.gif", lastLeafImg: "tv-item-last.gif", vertLineImg: "vertline.gif", blankImg: "blank.gif", collapse: false, column: 1, striped: true, highlight: true, onselect: function(target){window.status = "You clicked "+target.html();}};
    Map Array for the table below is :
    [0, 0, 0, 0, 0, 5, 0, 0, 8, 9, 8, 8, 0, 0, 14, 14, 14, 0, 18, 0, 0, 21, 22, 22, 22, 0, 0, 27, 27, 27, 30, 31, 31, 0, 0, 0, 0, 37, 37, 0, 0, 41, 41, 41, 44, 41, 46, 41, 41, 41]


    Sample : http://www.hanpau.com/jquery/unobtrusivetreetable.php

    Wednesday, September 26, 2007

    highlight: JavaScript text higlighting jQuery plugin




    jQuery Plugin: Text Highlight

    Text higlighting is part of
    DynaCloud – where tags/keywords are automatically highlighted once they’re clicked – so I took that code and made it a stand-alone JavaScript text highlighting jQuery plugin.
    Demo
    Each of the links will highlight the corresponding word.
    highlight
    javascript
    Remove highlights.
    Usage
    Add highlight
    Download
    jquery.highlight-1.js (2 KB) and add it to your page along with a jQuery version.
    Style the highlight class
    Create an entry in your style sheet for the highlight class..highlight { background-color: yellow }
    Highlight terms
    Call the $.highlight function with the start node and the text to highlight. Note that at this time the text must be upper-cased. To highlight all occurrances of “BLA” (case insensitive) in all li elements, use the following code:$('li').each(function() { $.highlight(this, 'BLA'); }));
    Remove highlighting
    The highlight can be removed from any element with the removeHighlight function. In this example, all highlights under the element with the ID highlight-plugin are removed.$('#highlight-plugin').removeHighlight();

    Saturday, September 22, 2007

    Spice up ASP.NET validation with AJAX Control Toolkit



    Introduction of AJAX Control Toolkit has opened many interesting possibilities for developing rich UI in ASP.NET. Add an awesome IDE like Visual Studio to it, and you can get astounding results without doing much. In this article we will see how to enhance client side validators using AJAX Control Toolkit. Given below are screen shots of what we are trying to achieve. The whole purpose is to improve user experience with very little effort.
    Download the source
    Download AJAX Control Toolkit (if you dont have it)
    Run it by following the instructions in 'readme.txt' file of downloaded archive.




    Friday, September 21, 2007

    What's JQuery UI?




    jQuery UI is a set of themable widgets and interactions, built on top of the jQuery JavaScript Library, that you can use to build highly interactive web applications.
    The core of the library revolves around different mouse interactions, namely drag and dropping, sorting, selecting, and resizing.
    On top of the core interactions are built a number of reusable widgets, including accordions, date pickers, dialogs, sliders, table sorters, and tabs.
    Finally, the library is finished off with a few effects that you can use to liven up your site, specifically magnifier and shadow.

    » More Information

    Wednesday, September 19, 2007

    HTTP Upload with Progress Monitoring Events



    The Chilkat Upload component is freeware. This example demonstrates how to HTTP upload one or more files and monitor the progress with event callbacks. Formal support for the Chilkat Upload component is included with a "Chilkat Bundle" purchase.


    download Download Chilkat .NET for 2.0 Framework


    download Download Chilkat .NET for 1.0 / 1.1 Framework



    //  

    // Progress monitor callback -- called each time the percentage completion
    // updates to a larger value.

    public void OnPercentDone(object source, Chilkat.PercentDoneEventArgs args)
    {
    // args.PercentDone is an integer value between 1 and 100.
    progressBar1.Value = args.PercentDone;

    }

    // The Chilkat.Upload.HeartbeatMs property determines the interval at which
    // AbortCheck events are called. If HeartbeatMs is set to 0 (the default),
    // then no AbortCheck events are called. This example sets the HeartbeatMs = 100
    // milliseconds.

    public void OnAbortCheck(object source, Chilkat.AbortCheckEventArgs args)
    {
    // Update progressBar2 so we can visually see the heartbeat.
    if (progressBar2.Value > 90)
    {
    progressBar2.Value = 0;
    }
    else
    {
    progressBar2.Value += 10;
    }

    // Handle UI events to keep the user-interface responsive.

    System.Windows.Forms.Application.DoEvents();

    // To abort the upload while in progress, set the
    // args.Abort property = true, like this:
    // args.Abort = true;

    }

    // Demonstrates a BlockingUpload with progress monitoring events.
    private void button1_Click(object sender, EventArgs e)
    {
    Chilkat.Upload upload = new Chilkat.Upload();

    // Make sure the EnableEvents property is set to true, otherwise we
    // won't receive event callbacks.

    upload.EnableEvents = true;

    // Call AbortCheck every 100 milliseconds.
    upload.HeartbeatMs = 100;

    // Setup our event callback handlers.

    upload.OnPercentDone += new Chilkat.Upload.PercentDoneEventHandler(OnPercentDone);
    upload.OnAbortCheck += new Chilkat.Upload.AbortCheckEventHandler(OnAbortCheck);

    // To upload more than one file, call AddFileReference multiple times --
    // once for each file to be uploaded.

    // The formElementName is arbitrary, and can be anything.

    string formElementName = "file1";
    // The localFilename is a file that exists on your local filesystem.
    string localFilename = "hamlet.xml";
    upload.AddFileReference(formElementName, localFilename);

    // The Hostname and Path properties specify the server-side
    // page/program/script/CGI that will recieve and process the upload.

    upload.Hostname = "www.freeaspupload.net";
    upload.Path = "/freeaspupload/testUpload.asp";

    // The BlockingUpload call does not return until all the files have been
    // uploaded (or an error occurs or the upload is aborted by the application).

    bool success = upload.BlockingUpload();
    if (success == false)
    {
    textBox1.Text = upload.LastErrorText;
    }
    else
    {
    // When BlockingUpload returns true, it indicates that the files/data have
    // been uploaded and an HTTP response status indicating success was
    // received. If the success/failure of an uploaded is indicated by
    // a message in the HTTP response body, you may access it via
    // the ResponseBody property (which is a byte array).


    textBox1.Text = System.Text.UTF8Encoding.UTF8.GetString(upload.ResponseBody);

    MessageBox.Show("Success!");
    }
    }

    Create an Atom Feed

    This sample C# program demonstrates how to create an Atom feed using the Tortuga Atom .NET API.

    // Create an Atom Feed in C#

    Tortuga.Atom feed = new Tortuga.Atom();



    // Initialize the feed.

    feed.NewFeed();

    feed.SetTopAttr("version","0.3");

    feed.SetTopAttr("xml:lang","en");



    feed.AddElement("generator","TortugaAtom/1.0");

    feed.AddElement("title","My Cool Atom Feed");

    feed.AddLink("alternate","http://www.myCoolAtomFeed.com/news","","text/html");

    feed.AddElement("tagline","Top Stories");

    feed.AddPerson("author","Tortuga Group LLC","","news-feedback@worldwideweb-x.com");

    feed.AddElement("copyright","Copyright 2005 Tortuga Group LLC");

    feed.AddElementDate("modified",DateTime.Now);



    // Build an entry.

    Tortuga.Atom entry = new Tortuga.Atom();



    // Inialize the object...

    entry.NewEntry();



    // Build the atom entry

    entry.AddElement("title","Tortuga Atom API Released");

    entry.AddLink("alternate","http://www.myCoolAtomFeed.com/news/story1.html","","text/html");

    entry.AddElement("id","763489562980");

    entry.AddElementDate("issued",DateTime.Now);

    entry.AddElementDate("modified",DateTime.Now);

    entry.AddElementHtml("content","<br><b>This is the HTML content for this story</b><br>");

    entry.SetElementAttr("content",0,"type","text/html");

    entry.SetElementAttr("content",0,"mode","escaped");



    // Add the entry to the feed.

    feed.AddEntry(entry.ToXmlString());



    // Build another atom entry

    entry.NewEntry();

    entry.AddElement("title","Tortuga Blogger API Released");

    entry.AddLink("alternate","http://www.myCoolAtomFeed.com/news/story2.html","","text/html");

    entry.AddElement("id","763489562981");

    entry.AddElementDate("issued",DateTime.Now);

    entry.AddElementDate("modified",DateTime.Now);

    entry.AddElementHtml("content","<br><b>This is the HTML content for the 2nd story</b><br>");

    entry.SetElementAttr("content",0,"type","text/html");

    entry.SetElementAttr("content",0,"mode","escaped");



    // Add the entry to the feed.

    feed.AddEntry(entry.ToXmlString());



    MessageBox.Show(feed.ToXmlString());




    Monday, September 17, 2007

    Javascript image rollover



    JavaScript image rollovers
    JavaScript image rollovers have been one of the most used features for bringing interactivity to web pages. They refer to the change in the image when the mouse cursor is moved over and subsequently off the image.


    Rollovers employ two JavaScript event handlers. onmouseover, that captures the action when the mouse cursor is brought over an image and onmouseout, that detects the action when the mouse cursor is moved off an image. These two even handlers are placed inside the anchor tag that surrounds the IMG tag.

    We also use the src property of the JavaScript image object. This property refers to the file name of the image being displayed (image source). Finally, we employ the NAME attribute of the HTML IMG tag to explicitly refer to the image in question.
    The logic is extremely simple. It's a matter of changing the image when the mouse cursor is placed over it and then changing it back to the original when the mouse cursor moves off the image.
    Let's construct our image tag:



    <img height="39" alt="Move your mouse over me" src="http://www.blogger.com/moveup.gif" width="143" border="0" name="sub_but" />

    Note: We use the NAME attribute of the HTML IMG tag to give the name sub_but to our image. JavaScript event handlers will refer to the image with this name.You'll notice that the image source (file name) is moveup.gif, which is the image to be displayed when the mouse cursor is off the image.
    Now, we place anchor tags around this image:


    <a href="http://www.blogger.com/somewhere.html">
    <img height="39" alt="Move your mouse over me" src="http://www.blogger.com/moveup.gif" width="143" border="0" name="sub_but" />
    </a>


    Lastly, we include the two JavaScript event handlers inside this anchor tag.

    <a onmouseover="document.sub_but.src='movedown.gif'" onmouseout="document.sub_but.src='moveup.gif'" href="http://www.blogger.com/somewhere.html">
    <img height="39" alt="Move your mouse over me" src="http://www.blogger.com/moveup.gif" width="143" border="0" name="sub_but" />
    </a>

    Friday, September 14, 2007

    What's Cake PHP

    Cake is a rapid development framework for PHP which uses commonly known design patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility.

    Download




    Cutting Edge Content Management


    Joomla! is one of the most powerful Open Source Content Management Systems on the planet. It is used all over the world for everything from simple websites to complex corporate applications. Joomla! is easy to install, simple to manage, and reliable.
    Demo Download Details


    PHP Tips & Tricks - A Picture Upload, Part 1

    By Vince Barnes




    First, I'd like to give credit to my co-author, Mundi King. I've mentioned him before -- he's the PHP guru who can wite code with both hands tied behind his back (well, almost!!) Thanks, Mundi, for great work on this! And now to it......



    There are entire shelves of books dedicated to tackling the question "how should one write a program?". It is a difficult question and you will invariably get a different answer depending on the programmer you ask.



    One of the harder tasks to writing a PHP application (or any program) is to know how to break down the processes into smaller, more manageable pieces.



    Many PHP files start out as simple little scripts, but after time (and many feature requests) they tend to grow into very long, complicated programs. It may even become difficult to determine exactly what the program is doing at any given point. It is at this point where breaking it down will add a bit of clarity to the program flow.



    Fortunately, PHP provides a few simple, yet elegant methods for breaking out code into separate pieces. The first one we will concentrate on is PHP's very powerful include() statement.



    Let us start with an often requested web application that will allow an end user to upload an image file to the web server and then give them a list of the images they have uploaded in the past.



    Starting with first things first, we know that we will need a web form that has a file upload field and a submit button. And we know we will need some php code to actually handle the upload. Here is an example.



    <?

    //print_r($_POST);



    if($_POST["action"] == "Upload Image")

    {

    unset($imagename);



    if(!isset($_FILES) && isset($HTTP_POST_FILES))

    $_FILES = $HTTP_POST_FILES;



    if(!isset($_FILES['image_file']))

    $error["image_file"] = "An image was not found.";





    $imagename = basename($_FILES['image_file']['name']);

    //echo $imagename;



    if(empty($imagename))

    $error["imagename"] = "The name of the image was not found.";



    if(empty($error))

    {

    $newimage = "images/" . $imagename;

    //echo $newimage;

    $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);

    if(empty($result))

    $error["result"] = "There was an error moving the uploaded file.";

    }



    }



    ?>





    <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>">

    <p><input type="file" name="image_file" size="20"></p>

    <p><input type="submit" value="Upload Image" name="action"></p>

    </form>



    <?

    if(is_array($error))

    {

    while(list($key, $val) = each($error))

    {

    echo $val;

    echo "<br>\n";

    }

    }

    ?>





    Without going into great detail, here is the basic low-down of the up-load.



    The bulk of the php code only get activated if $_POST["submit"] is "Upload Image" and this only occurs if someone has pressed the submit button. The form actually submits back to itself by using the <?$_SERVER["PHP_SELF"];?>. Inside the HTML of the form, we will print out any error messages that may have occurred. This script also assumes that there exists a directory named "images" that is writable by the web server. You can usually accomplish this by ftping into your website and making a folder named "images" and changing the permissions of the folder to 777 or xxx or execute execute execute.



    You may want to take a look at this tutorial about uploading files.

    http://www.htmlgoodies.com/beyond/php/article.php/3472551





    Now that we have our uploading script, it is time to take a step back and see if there is a way that we can make it more modular. Imagine a scenario where you are working with a team, and a designer who only knows HTML wants to modify the form. This could lead to a dangerous situation where he inadvertently changes some php code when he just wants to change some HTML.



    Here is where php's include() comes in handy. include() lets you grab other files and php will automatically insert everything from that file at the exact place you invoke the include() statement. To accomplish this, one only has to type the file name in-between the parentheses of the statement. For example, include("myfile.txt");



    If we separate out our one giant php script so that the html part is in another file and leave most of the php in the original script, the HTML designer can go into that file and not have to worry about changing code.



    After putting in our include, the main file would appear like this...



    <?

    //print_r($_POST);



    if($_POST["action"] == "Upload Image")

    {

    unset($imagename);



    if(!isset($_FILES) && isset($HTTP_POST_FILES))

    $_FILES = $HTTP_POST_FILES;



    if(!isset($_FILES['image_file']))

    $error["image_file"] = "An image was not found.";





    $imagename = basename($_FILES['image_file']['name']);

    //echo $imagename;



    if(empty($imagename))

    $error["imagename"] = "The name of the image was not found.";



    if(empty($error))

    {

    $newimage = "images/" . $imagename;

    //echo $newimage;

    $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);

    if(empty($result))

    $error["result"] = "There was an error moving the uploaded file.";

    }



    }



    include("upload_form.php");



    if(is_array($error))

    {

    while(list($key, $val) = each($error))

    {

    echo $val;

    echo "<br>\n";

    }

    }



    ?>





    and our mostly HTML file would be this...





    <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>">

    <p><input type="file" name="image_file" size="20"></p>

    <p><input type="submit" value="Upload Image" name="action"></p>

    </form>





    The next step is to have something that actually shows what images are in the directory. We can write a quick script that will iteratively go through images directory and echo out what is there like this...



    <?

    $handle = @opendir("images");



    if(!empty($handle))

    {

    while(false !== ($file = readdir($handle)))

    {

    if(is_file("images/" . $file))

    echo '<img src="images/' . $file . '"><br><br>';

    }

    }



    closedir($handle);

    ?>





    Again, here is where the power of include comes in handy. We can provide a direct link to our list_images.php, but we can also just include it in our original upload.php This saves us from having to write it twice!



    So at the bottom of our upload.php we can just include the include like this...



    <?

    //print_r($_POST);



    if($_POST["action"] == "Upload Image")

    {

    unset($imagename);



    if(!isset($_FILES) && isset($HTTP_POST_FILES))

    $_FILES = $HTTP_POST_FILES;



    if(!isset($_FILES['image_file']))

    $error["image_file"] = "An image was not found.";





    $imagename = basename($_FILES['image_file']['name']);

    //echo $imagename;



    if(empty($imagename))

    $error["imagename"] = "The name of the image was not found.";



    if(empty($error))

    {

    $newimage = "images/" . $imagename;

    //echo $newimage;

    $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);

    if(empty($result))

    $error["result"] = "There was an error moving the uploaded file.";

    }



    }



    include("upload_form.php");



    if(is_array($error))

    {

    while(list($key, $val) = each($error))

    {

    echo $val;

    echo "<br>\n";

    }

    }



    include("list_images.php");



    ?>







    So far, our little application has been kept basic to emphasize the program flow and not get bogged down in the details. But our next step is to enhance the functionality of our gallery.

    Thursday, September 13, 2007

    ExtJS JavaScript Framework

    April 30, 2007 at 10:29 pm · Filed under JavaScript, Ajax Resources
    Ext JS, the JavaScript framework with Ajax and UI Components
    Ext JS is a JavaScript Library/Framework which works in conjunction with Prototype, YahooUI and jQuery. It’s probably the most exciting toolkit available for building web 2.0 websites right now. It’s jam packed with features, and is designed to make life much easier for building great UI in JavaScript.
    I’ll not dig to deep right now, I suggest you check out the
    example and demos first to see what you think.
    Below is a the script used to grab XML data via Ajax and populate a grid (sortable table like object):


    view plaincopy to clipboardprint?


    ajax


    Take a look at the JavaScript generated grid here.
    Hopefully this short intro will wet your appetite, more to come soon.
    Great work Jack (and the rest of the Ext JS team) for this superb library, can’t wait to see more!!

    Wednesday, September 12, 2007

    Fancy Sliding Tab Menu V2

    Fancy Sliding Tab Menu V2

    The Fancy Sliding Tab Menu is back and better than ever in Version 2 and this time I’ve included an idle state listener to bring all the tabs back to their normal state after a desired amount of time without mouse movement on the window.
    The menu is developed in script.aculo.us and as I have mentioned above has some extra features as requested in comments after the last version of the
    Fancy Sliding Tab Menu. I have some more ideas for the menu and once I have implemented those I will post on here again with full documentation. I have really put it up here for now to hear peoples comments.



    demo
    Have a look for yourself at the new
    Fancy Sliding Tab Menu demo
    .
    code
    Feel free to download the Fancy Sliding Menu Code.



    Tuesday, September 11, 2007

    Aptana RadRails (Beta with RadRails and Ruby )

    Aptana RadRails Beta with RadRails and Ruby Development Tools (RDT)

    Aptana RadRails is an integrated development environment for the Ruby on Rails framework.
    Web Features
    Free and open source; cross-platform, stand-alone IDE or Eclipse plug-in
    File- and project-based workflow with integrated FTP/SFTP
    Real-time, Wiki-based online help; IDE translated into multiple languages
    Scriptable using JavaScript (“Aptana Monkey”)
    Backed by full-time developers; nearing a million combined downloads
    Deep support (including cross-browser tips) for JavaScript, HTML, CSS
    Syntax highlighting, auto completion, code assist, error reporting, etc.
    Full support for JavaScript and CSS embedded within HTML; unified outlining
    Works with any JavaScript, incl. all Ajax libraries
    JavaScript debugger with live Firebug integration
    Rails Features
    Unified, deep support for Ruby, Rails, RHTML…and JS, HTML, CSS!
    Syntax highlighting, auto completion, code assist, error reporting, outlining, etc.
    Ruby code generation: constructors, overrides, templates, accessors
    Refactoring: local to instance variables, extract methods, inlining, renaming…
    Fast, integrated debugger
    Support for Rails generators, Rake, plugins, and server management
    View unit tests and test results
    Integrated code analysis
    Embedded database navigator and query console
    Snippets and wizards
    Integrated help, including “Go to definition”, RDoc/RI, and code explorer

    Reference http://www.radrails.org/download_rails_rdt.php





    Open Source YouTube

    Everyone knows what YouTube or Google Video is. Most of them might use to waste a period of time in this kind of service. I'm one of them. I also wonder how it works. Technically, upload video service like YouTube and Google Video is very similar in underlying technology. In particular, all uploaded videos are automatically converted to Flash Video or FLV. The FLVs are stored in the file server. However, the FLVs is nevered shown directly on your browser. Instead, the FLVs are played inside Flash Video Player written in Flash itself. As a result, you can view a video immediately after getting only some part of the full-length video. In other words, Flash Video Player and FLV are the best couple for on-demand video streaming.
    If you think it is too complex and too difficult to implement XXXTube by yourself, I will summarize everything you need to know and to have.
    You need a Flash Video Player,
    Uploading system,
    Video conversion system,
    Big storage and
    Bandwidth
    Let's see how to implement XXXTube as fast as possible. For the first requirement, you don't need to write Flash Video Player by yourself. There is an open source project namely
    Flash Video Player, latest verion is 2.4. The developer claimed that it has been used by YouTube and Blip. Next one, uploading system is very simple and easy. You can write uploading system in PHP in just an hour so you don't need to take care about this piece. The most difficult part of XXXTube is here in the third step, video conversion system. Why?
    It should support video formats and codecs as many as possible or at least DivX, MPEG1, MPEG4, MOV, WMV, and 3GPP.
    It might be as fast as possible. Otherwise, the uploaded videos may be waiting in the conversion queue. Nobody want this delay happened.
    It should be robust and fully automatic. No interactive with other piece of tools.
    Don't panic. Open source community is showing its useful, powerful, and awesome results. At least we have
    FFmpeg, MPlayer, MEncoder, and Transcode. These are more than enough to produce flash video from various video formats and codecs.
    The simplest example is shown in official documentation of MPlayer site.

    mencoder input.avi \
    -o output.flv \
    -of lavf \
    -oac mp3lame -lameopts abr:br=56 \
    -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 \
    -srate 22050

    Below is my flavorite.

    mencoder input.avi \
    -of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames \
    -ovc lavc
    -lavcopts vcodec=flv:vbitrate=150 -ofps 15 \
    -oac mp3lame -lameopts abr:br=32 -srate 22050 \
    -vf scale=320:-3 \
    -o output.flv

    One last problem is how to handle mass clients to produce flv just in time.

    Reference (sugree's blog)

    Free Gallery Code

    Slightbox Extension for SmoothGallery (Demo)

    Slightbox is a lightbox extension for SmoothGallery. It allows you to show images from SmoothGallery in a lightbox. It features a cooler, darker theme designed by Jonathan Schemoul.

    Download Source code

    Easy SlideShow

    You can make the slideshow easily by using Highslide.

    What is Highslide JS? (Click Here for example)
    Highslide JS is a piece of JavaScript that streamlines the use of thumbnail images on web pages. The library offers these features and advantages:
    No plugins like Flash or Java required.
    Popup blockers are no problem. The images expand within the active browser window.
    Single click. After expanding the image, the user can scroll further down or leave the page without restoring the image.
    The approach uses two separate images. No heavy full-size image packed into thumbnail display size! The full-size image is loaded in the background either on page load or when the user clicks the thumb. You specify this option in the script's settings.
    Compatibility and safe fallback. If the user has disabled JavaScript or the JavaScript fails in any way, the browser redirects directly to the image itself. This fallback is able to cope with most exceptions and incompatibilities.


    Download Source code