Ian Lewis
Ian Lewis is a web developer living in Tokyo Japan. His current interests are in Django, python, alternative databases and rapid web application development. About Me...
  • Connecting Sortables in jQuery UI

    jQuery has a UI framework called jQueryUI which provides a number of UI controls and widgets that you can use to create cool user interfaces. I've been using jQueryUI a fair bit for work recently and wanted to share a pretty cool feature that jQueryUI has.

    jQueryUI has a widget called a sortable which is just a list of sortable dom elements. It allows you to drag the items around and resort them in a list. Options are passed in an object that you give to the sortable constructor/initializer. You can initialize a sortable like so:

    $('#my-list').sortable({
      axis: 'x'
    });

    In this case the options object and contained "axis" option are optional but it gives you a good idea what a widget initializer looks like.

    jQueryUI also has a draggable widget which allows you to easily create draggable items. This draggable can also be connected to a sortable object so you can drag an object onto a sortable widget.

    $('#my-item').draggable({
      connectToSortable: '#my-list'
    });

    jQueryUI also allows you to connect sortables to each other which creates the potential for some interesting user interfaces.

    $('#my-list').sortable({
      connectWith: '#my-other-list'
    });

    You can even connect the sortables together so you can drag items back and forth between the sortables:

    $('#my-list').sortable({
      connectWith: '#my-other-list'
    });

    $('#my-other-list').sortable({
      connectWith: '#my-list'
    });

    DEMO >>

    Send feedback このエントリーを含むはてなブックマーク はてなブックマーク - Connecting Sortables in jQuery UI
  • jQuery Multi-Pageslide

    Earlier this week I came across the jQuery Pageslide plugin via Ajaxian and was impressed with the design. I set about using it to display help messages to the user for a site I am working on.

    It worked well and all but I found that you can only have one pageslide per page. Say you want to have multiple links one one page that each invoke a page slide but with different settings. So I made some changes to the plugin to allow multiple pageslides per page. The demo includes a version of page slide that allows multiple pageslide links per page and allows them all to have their own individual settings. These all point to the same secondary page but could just as well point to different pages. Currently they all share the same css styles.

    I made it so that only one pageslide can be open at a time. Clicking on a pageslide link while a pageslide is already open will do nothing. I also included a way to close the currently open pageslide from javascript.

    View the source:
    demo.html
    jquery.pageslide-0.2.js

    Demo: demo.html

    Send feedback このエントリーを含むはてなブックマーク はてなブックマーク - jQuery Multi-Pageslide
  • Ok/Cancel buttons with jqModal

    I recently quit using gwt and started using jQuery for a personal project of mine and I wanted to be able to show some modal dialog boxes using jQuery. As it turns out there is an easy to use plugin that does exactly this called jqModal. jqModal makes it simple to create modal dialogs by simply setting a css class on the tag you want to open the dialog and on the tag in the dialog that you want to close it.

    <a href="#" class="jqModal">view</a>
    ...
    <div class="jqmWindow" id="dialog">
    <p>This is my dialog.</p>
    <a href="#" class="jqmClose">Close</a>
    </div>
    <pre><code>
    $().ready(function() {
      $('#dialog').jqm();
    });
    </code></pre>

    That's easy but gives you a pretty minimalistic popup dialog. Any tag with the jqmClose class will simply close the dialog. What if you want to do something with OK and Cancel options? What if you want to do some fancy fade in/fade out no matter what happens? This tripped me up for a but much luckily only took about a few minutes to straiten out and test.

    <a href="#" class="jqModal">Update</a>
    ...
    <div class="jqmWindow" id="dialog">
    <p>I'm going to update. Is that ok?</p>
    <a href="#" class="dialogok">OK</a> <a href="#" class="jqmClose">Cancel</a>
    </div>
    $("#dialog #dialogok").bind("click",
      function() {
        /* Do your update logic here. */
        $('#dialog').jqmHide();
      }
    );
     
    var newFieldHide = function(hash) {
      hash.w.fadeOut('2000',function() { hash.o.remove(); });
    };
    var newFieldShow = function(hash) {
      hash.w.fadeIn("2000");
    };
    $("#dialog").jqm({onHide:newFieldHide, onShow:newFieldShow});

    So I'm basically closing the dialog manually in the OK case and closing it automatically using the jqmClose class in the Cancel case. In both cases the onHide trigger is called and fades out the dialog.

    Send feedback このエントリーを含むはてなブックマーク はてなブックマーク - Ok/Cancel buttons with jqModal
  • Twitter Page Code

    Twitter

    I took a look at Twitter's code as an example of a site that gets lots of traffic and noticed a couple things.

    1. They use Amazon S3 to store images
    2. They split the javascript, favicons, and css up across 3 or 4 subdomains (assets0.twitter.com, assets2.twitter.com, etc.)
    3. They include prototype and a version of jQuery as well as a version of script.aculo.us.
      <script src="http://assets3.twitter.com/javascripts/prototype.js?1213829093" type="text/javascript"></script>
      <script src="http://assets1.twitter.com/javascripts/effects.js?1213829093" type="text/javascript"></script>

      <script src="http://assets0.twitter.com/javascripts/application.js?1213829093" type="text/javascript"></script>
      <script src="http://assets0.twitter.com/javascripts/jquery-1.2.3.min.js?1213829093" type="text/javascript"></script>

    It kind of surprised me that they include a version of prototype AND jQuery AND script.aculo.us since they aren't really light javascript files. Prototype comes in at 123kb, jQuery is 53kb, and script.aculo.us is 38kb. Seems to me that even with caching and all they could significantly reduce download traffic by sticking to one javascript library. I'm sure there is some wierd reason they do it though.

    Send feedback このエントリーを含むはてなブックマーク はてなブックマーク - Twitter Page Code