jQuery Numeric Plugin Update

Long time since I’ve posted, but have updated my jQuery numeric plugin for allowing only numbers in input boxes, fixing a couple of bugs and adding functionality (removing from input and allowing integers only). See code updates via GitHub, or download the latest stable version zipped. In the future might set it so you can restrict how many characters you can put after the decimal point (so could be useful for currency input).

jQuery newsticker Demo Page

Some may have noticed, the demo page for the newsticker jQuery plugin has not been working in Internet Explorer 7. This is due to it being experimental code for allowing pausing, resuming and clearing of any active news ticker’s on the page. It should now work in IE7 (and hopefully IE6 as well).

There are a few additions to the plugin that should be of benefit. Set up the news ticker as usual:

var $news = $("#news").newsticker();

After doing so, you may pause, resume and clear it in your own functions. For example, clicking on elements with id’s pause, resume or clear will perform the relevant action:

$("#pause").click(
  function()
  {
    $.newsticker.pause($news);
    return false;
  }
);

$("#resume").click(
  function()
  {
    $.newsticker.resume($news);
    return false;
  }
);

$("#clear").click(
  function()
  {
    $.newsticker.clear($news);
    return false;
   }
);

The code available for download via jQuery SVN doesn’t have this functionality, but should work fine in IE7.

jQuery appendToArray plugin

With jQuery, I found no real way of grouping elements together (other than using a class, and using filter), so I thought about adding jQuery objects to an array (or multiple arrays), which can then be iterated over with jQuery.each. I tried appendTo (on the off chance that it would work with plain arrays), but no such luck. So I created a simple plugin:

jQuery.fn.appendToArray = function()
{
 var a = arguments;
 for(var i = 0; i < arguments.length; i++) a[i][a[i].length] = this;
 return this;
}

Through using arguments, it can be appending to multiple arrays at the same time:

var ar1 = [];
var ar2 = [];
var $field1 = $("[name='field1']").appendToArray(ar1, ar2);
var $field2 = $("[name='field2']").appendToArray(ar1);
var $field3 = $("[name='field3']").appendToArray(ar1, ar2);
var $field4 = $("[name='field4']").appendToArray(ar2);
var $field5 = $("[name='field5']").appendToArray(ar2);

You can then loop through the arrays, with specific functions applied:

$.each(ar1, function()
 {
  console.log(this.attr("name") + " is in ar1");
 }
);

$.each(ar2, function()
 {
  console.log(this.attr("name") + " is in ar2");
 }
);