jquery.anchoring
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:jQuery plugin that allows for easy AJAX permalinks with anchored links.
jQuery.anchoring

------------------------------------------------------------------------------------------------------

A jQuery plugin to allow AJAX permalinking with anchoring tags.

Released by Greg Leuch , originally for Magma .

------------------------------------------------------------------------------------------------------

Easy to use:

  1. Add jquery.anchoring.js to the page.
  2. Add rel="anchor fn_name" to links, where "fn_name" is the name of the callback function.
  3. Add the initalizer and callback function(s):
      $(document).ready(

        // Add callback function 'fn_name'
        $.anchoring.addFunc('fn_name', function(href, data) {
          $.anchoring.retrieve({url: href, success : function() {
            -- return success callback --
            }
          });
        });
        
        // Initializer
        $('a[rel=^anchor]').anchoring({--additional settings--});
      });

  4. Start clicking away.

------------------------------------------------------------------------------------------------------

Examples:

Doing a custom AJAX request with fallback function.

  JavaScript:

  $(document).ready(function() {
    // Adding special function
    $.anchoring.addFunc('search', function(item) {
      var url = (item && item.href && item.href != '' ? item.href : item);

      if (item) $.anchoring.set(url);

      if (url) {
        $.anchoring.retrieve({
          dataType:'HTML',
          url : url,
          success : function(response) {
            $('#example').html(response);
          }
        }
      });
    });

    // Initializing with fallback function (which evals our function previously added above.
    $('a[rel^=anchor').anchoring({
      fallback : function(item) {
        $.anchoring.funcs.search(item ? item : $.anchoring.settings.location);
      }
    });
  });


  And some HTML:

  

Search for 'rails'

Search for 'jQuery'

Search results will be replaced in this area.
Or do custom functions based on HTML elements. These anchors will be defined by /#tagName.id JavaScript: $(document).ready(function() { // Adding special function for tabbing $.anchoring.addFunc('tab', function(item, data) { // Use the setElement function instead of the set function $.anchoring.setElement(item); // Tab effects $('#tabs .tab').removeClass('current'); $('#tabs #tab_'+data).addClass('current'); // Tab Area affects $('#areas .area').hide(); $('#areas #area_'+data).show(); }); // Initialize and set fallback action. $('a[rel^=anchor tab]').anchoring({ fallback : function() { // Always enable the first tab. $('#tab .tab:eq(0)').click(); } }); }); And some HTML using the expansion of the rel attribute for more data:

This would be more info about 'rails'.

This would be more info about 'rails'.

------------------------------------------------------------------------------------------------------ Tested and works in the following browsers: - Firefox 2.*, 3.* (and 3.5b) - Safari 3.* & 4 beta - Internet Explorer 8 Works with known issues in the following browsers: - Internet Explorer 6 & 7 ****************************************************************************************************** NOTE: IE 6 & 7 only allows forward & back button to navigate between actual pages, not anchors. jQuery.anchoring does detect and load based on anchor tabs, but if a user clicks their back or forward button in their browser, it will take to to the previous page they were on. ****************************************************************************************************** Upcoming Features - Using JSOND as the default callback method (instead of initial function with an AJAX success function() as the callback). - Optimization and testing in older browsers. - Demo code and demo page. ------------------------------------------------------------------------------------------------------ Changelog - Allowing shortened urls if requested URL base is same as current page URL base. - i.e. converts /videos/#/videos/?page=2 into /videos/#?page=2 - Renaming 'default' to 'fallback' due to reserve word in WebKit/Safari. - Moving certain vars into settings object and added default function. - Removing cache:false from jQuery AJAX and forcing cache only if anchored url is the called url (primarily first request).

本源码包内暂不包含可直接显示的源代码文件,请下载源码包。