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 3296 2011-06-22 17:15:17Z 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).die('click').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 // url: 'ajax request URL' 52 }; 53 54 $.fn.yiiListView.settings = {}; 55 56 /** 57 * Returns the key value for the specified row 58 * @param id string the ID of the list view container 59 * @param index integer the zero-based index of the data item 60 * @return string the key value 61 */ 62 $.fn.yiiListView.getKey = function(id, index) { 63 return $('#'+id+' > div.keys > span:eq('+index+')').text(); 64 }; 65 66 /** 67 * Returns the URL that generates the list view content. 68 * @param id string the ID of the list view container 69 * @return string the URL that generates the list view content. 70 */ 71 $.fn.yiiListView.getUrl = function(id) { 72 var settings = $.fn.yiiListView.settings[id]; 73 return settings.url || $('#'+id+' > div.keys').attr('title'); 74 }; 75 76 /** 77 * Performs an AJAX-based update of the list view contents. 78 * @param id string the ID of the list view container 79 * @param options map the AJAX request options (see jQuery.ajax API manual). By default, 80 * the URL to be requested is the one that generates the current content of the list view. 81 */ 82 $.fn.yiiListView.update = function(id, options) { 83 var settings = $.fn.yiiListView.settings[id]; 84 $('#'+id).addClass(settings.loadingClass); 85 options = $.extend({ 86 type: 'GET', 87 url: $.fn.yiiListView.getUrl(id), 88 success: function(data,status) { 89 $.each(settings.ajaxUpdate, function(i,v) { 90 var id='#'+v; 91 $(id).replaceWith($(id,'<div>'+data+'</div>')); 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.