JavaScript Repeater Control (dataRepeater) – from jQuery.Presenter.1.0.8 – UIControls Library

20 באוגוסט 2008

10 תגובות

In this post, I want to present a new JavaScript Repeater Control from my latest UIControls Library jQuery.Presenter 1.0.8. This control like (ASP.NET Repeater Control) created using jQuery Library 1.2.3 and support for later versions.
It's a free open source script…

Enjoy…

/*
* jQuery.Presenter 1.0.8
* Author: (basil.goldman@gmail.com)
* Description: developed and tested on jQuery 1.2.1,
* support and fixes for jQuery 1.2.6
*/

jQuery.fn.presenter = function() {

if (arguments.length == 0) return [];
var args = arguments[0] || {};

// Global arguments
var controlType = args.controlType;
var dataSource = args.dataSource;
var headerTemplate = args.headerTemplate;
var itemTemplate = args.itemTemplate;
var separatorTemplate = args.separatorTemplate;
var footerTemplate = args.footerTemplate;

// Global library control types
var properties = {
// Control types
controlTypes:[['dataRepeater']]
};

if(!jQuery.isNull(controlType) &&
(controlType.toLowerCase() ==
String(properties.controlTypes[0]).toLowerCase())) {

var o = $(this[0]), i = 0;
if( jQuery.isArray( dataSource ) ) {
var q = dataSource.length;
// Append headerTemplate
if( !jQuery.isNull( headerTemplate ))
$(o).append($(headerTemplate));

for( ; i < q; i++ ) {
if( !jQuery.isNull( itemTemplate ) ) {

// Replace {x} - using prototype
// function String.format
$(o).append(
$(String.format(itemTemplate, dataSource[i])));

// Append separatorTemplate
if( !jQuery.isNull( separatorTemplate ) &&
i != (dataSource.length - 1) ) {
$(o).append($(separatorTemplate));
}
}
}
// Append footerTemplate
if( !jQuery.isNull( footerTemplate ))
$(o).append($(footerTemplate));
}
}
};

String.format = function() {
var s = arguments[0] || {}, i = 0;
for( ; i < arguments[1].length; i++ ) {
var reg = new RegExp("\\{"+i+"\\}","gm");
s = s.replace(reg, arguments[1][i]);
}
return s;
}

jQuery.extend({
// Utilities
isArray: function(v){
return typeof(v) == 'object' &&
v != null &&
typeof(v.length) == 'number';
},
isNull: function(o) {
if(o == null && o == undefined) {
return true;
}
return false
}
});

HTML example for declarartion dataRepeater control

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>
<script type="text/javascript"
src="../App_Scripts/jQuery/jQuery-1.2.3.js"></script>
<script type="text/javascript"
src="../App_Scripts/Data/Presenter.1.0.8.js"></script>
<script type="text/javascript">

var itemTemplate = "<a href='{1}' title='{0}'>{0}</a>";
var separatorTemplate = "<span style='color: #fff'> | </span>";

var dataObject = [['Blogs', 'http://blogs.microsoft.com'],
['About', 'http://about.aspx'],
['Blogs', 'http://blogs.microsoft.com'],
['About', 'http://about.aspx']];

$(document).ready(function(){

$('#side-menu').presenter({controlType: 'dataRepeater',
dataSource: dataObject,
headerTemplate: null,
itemTemplate: itemTemplate,
separatorTemplate: separatorTemplate,
footerTemplate: null});
});
</script>
</head>
<body>

<div id="side-menu"></div>

</body>
</html>
הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

10 תגובות

  1. lior goldemberg11 במרץ 2009 ב 0:11

    basil u r the man

    הגב
  2. rallymaisha4 בינואר 2012 ב 11:15

    check ugg store london ugg store for more detail for more

    הגב
  3. vahspush12 באפריל 2012 ב 11:05

    to buy chanel 2010 bags for less

    הגב
  4. Wholesale Jerseys29 במאי 2012 ב 11:02

    Thank you for your work , I am very interested in your story , you are very concerned about our readers , and articles written by very close to our lives

    הגב
  5. Cheap Jerseys9 ביוני 2012 ב 8:46

    Interesting Article. Hoping that you will continue posting an article having a useful information.

    הגב
  6. Cheap Jerseys4 באוגוסט 2012 ב 8:59

    Like this site , like the inside of the article . Overall, very good · · · of as soon as possible in the write such a good article , good looking forward to it ! I will introduce to my police friends to enjoy such a good article . I wish I could be your friend again thank you for allowing me to see such a beautiful article · · ·

    הגב
  7. missguo790@gmail.com1 ביולי 2013 ב 7:38

    Tannenbaum said head coach Rex Ryan and Jets owner Woody Johnson visited Revis over the weekend in South Florida to hammer out a deal to bring back the talented cornerback.

    הגב