1/** 2 * jQuery Yii ListView plugin file. 3 * 4 * @author Qiang Xue <[email protected]> 5 * @link http://www.yiiframework.com/ 6 * @copyright Copyright © 2008-2010 Yii Software LLC 7 * @license http://www.yiiframework.com/license/ 8 * @version $Id: jquery.yiilistview.js 164 2010-04-29 21:03:33Z qiang.xue $ 9 */ 10 11;(function($) { 12 /** 13 * yiiListView set function. 14 * @param options map settings for the list view. Availablel options are as follows: 15 * - ajaxUpdate: array, IDs of the containers whose content may be updated by ajax response 16 * - ajaxVar: string, the name of the GET variable indicating the ID of the element triggering the AJAX request 17 * - pagerClass: string, the CSS class for the pager container 18 * - sorterClass: string, the CSS class for the sorter container 19 * - updateSelector: string, the selector for choosing which elements can trigger ajax requests 20 * - beforeAjaxUpdate: function, the function to be called before ajax request is sent 21 * - afterAjaxUpdate: function, the function to be called after ajax response is received 22 */ 23 $.fn.yiiListView = function(options) { 24 return this.each(function(){ 25 var settings = $.extend({}, $.fn.yiiListView.defaults, options || {}); 26 var $this = $(this); 27 var id = $this.attr('id'); 28 if(settings.updateSelector == undefined) { 29 settings.updateSelector = '#'+id+' .'+settings.pagerClass.replace(/\s+/g,'.')+' a, #'+id+' .'+settings.sorterClass.replace(/\s+/g,'.')+' a'; 30 } 31 $.fn.yiiListView.settings[id] = settings; 32 33 if(settings.ajaxUpdate.length > 0) { 34 $(settings.updateSelector).live('click',function(){ 35 $.fn.yiiListView.update(id, {url: $(this).attr('href')}); 36 return false; 37 }); 38 } 39 }); 40 }; 41 42 $.fn.yiiListView.defaults = { 43 ajaxUpdate: [], 44 ajaxVar: 'ajax', 45 pagerClass: 'pager', 46 loadingClass: 'loading', 47 sorterClass: 'sorter' 48 // updateSelector: '#id .pager a, '#id .sort a', 49 // beforeAjaxUpdate: function(id) {}, 50 // afterAjaxUpdate: function(id, data) {}, 51 }; 52 53 $.fn.yiiListView.settings = {}; 54 55 /** 56 * Returns the key value for the specified row 57 * @param id string the ID of the list view container 58 * @param index integer the zero-based index of the data item 59 * @return string the key value 60 */ 61 $.fn.yiiListView.getKey = function(id, index) { 62 return $('#'+id+' > div.keys > span:eq('+index+')').text(); 63 }; 64 65 /** 66 * Returns the URL that generates the list view content. 67 * @param id string the ID of the list view container 68 * @return string the URL that generates the list view content. 69 */ 70 $.fn.yiiListView.getUrl = function(id) { 71 return $('#'+id+' > div.keys').attr('title'); 72 }; 73 74 /** 75 * Performs an AJAX-based update of the list view contents. 76 * @param id string the ID of the list view container 77 * @param options map the AJAX request options (see jQuery.ajax API manual). By default, 78 * the URL to be requested is the one that generates the current content of the list view. 79 */ 80 $.fn.yiiListView.update = function(id, options) { 81 var settings = $.fn.yiiListView.settings[id]; 82 $('#'+id).addClass(settings.loadingClass); 83 options = $.extend({ 84 type: 'GET', 85 url: $.fn.yiiListView.getUrl(id), 86 success: function(data,status) { 87 $.each(settings.ajaxUpdate, function(i,v) { 88 var id='#'+v, 89 $d=$(data), 90 $filtered=$d.filter(id); 91 $(id).replaceWith( $filtered.size() ? $filtered : $d.find(id)); 92 }); 93 if(settings.afterAjaxUpdate != undefined) 94 settings.afterAjaxUpdate(id, data); 95 $('#'+id).removeClass(settings.loadingClass); 96 }, 97 error: function(XMLHttpRequest, textStatus, errorThrown) { 98 $('#'+id).removeClass(settings.loadingClass); 99 alert(XMLHttpRequest.responseText); 100 } 101 }, options || {}); 102 103 if(options.data!=undefined && options.type=='GET') { 104 options.url = $.param.querystring(options.url, options.data); 105 options.data = {}; 106 } 107 options.url = $.param.querystring(options.url, settings.ajaxVar+'='+id) 108 109 if(settings.beforeAjaxUpdate != undefined) 110 settings.beforeAjaxUpdate(id); 111 $.ajax(options); 112 }; 113 114})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.