Expand my Community achievements bar.

Update inList plugin to handle serialized events


Level 2




This works as expected:



s.events = 'event1,event2'; s.inList('event1',s.events,','); // returns true




But the plugin does not work for serialized events:



s.events = 'event1:12345,event2'; s.inList('event1',s.events,','); // returns false



I know that it can be argued that this plugin can be used for more than just events, and ideally it should be as generic as possible, but in practice, it is almost exclusively used with the s.events variable, so it makes sense that support for serialization be added to this plugin.  


I would suggest an optional 4th argument to specify a serialization delimiter, and have the plugin strip everything from specified delimiter to end of string in the "is this in the list?" condition.  Here is the s.inList() plugin with updated code to reflect this proposed addition:


s.inList=new Function("v","l","d","sd","" +"var s=this,ar=Array(),i=0,d=(d)?d:',',sd=(sd)?sd:'',nv=new RegExp('" +"\\\\'+sd+'.*$');if(typeof(l)=='string'){if(s.split)ar=s.split(l,d);" +"else if(l.split)ar=l.split(d);else return-1} else ar=l;while(i



This addition will now produce desired results:


s.events = 'event1:12345,event2'; s.inList('event1',s.events,',',':'); // returns true