﻿/* 
 * jQuery jID plugin 0.1 - get Unique Identifiers stored in css class of http element in form of name-ID
 * Copyright (c) 2009 Anton Simov
 * Distributed under the GPL licenses.
*/

// Define the jID plugin
(function($) { 
    $.fn.jID = function(name){    
        var returnID = null;
        //Get all classes from element
        var getElementClass = String($(this).attr("class"));
        //Regex to get all id containing classes formed like parameterID-123
        var regex = /([^\s].+?)-(\d+)/g;        
        //If name was passed modify regex to include name
        if (name != null){
         regex = eval("/([^\\s]" + name + ")-(\\d+)/g");
        }               
        if(getElementClass.match(regex)){            
        var matches = [];
	    getElementClass.replace(regex, function () {
		    matches.push(arguments[2]);
	    });           
           returnID = matches[0]; //Return the first ID found     
        }                             
        return returnID;
   };
 })(jQuery);
 
