seoscribe / jsearch

jsearch: a drop-in library for client-side search if you don't have a back-end.
BSD 3-Clause Clear License
2 stars 1 forks source link

We need to use unique IDs for injected markup #3

Closed wnda closed 7 years ago

wnda commented 7 years ago

The thought occurs that IDs like 'search', 'searchbutton' etc are apt to cause conflicts with existing websites elements.

While any user of the library will presumably not have any search elements to conflict with, it makes testing on seoscribe.net a little bit messy.

loisatwood commented 7 years ago

generate ID on the fly or just use something unlikely to be used?

wnda commented 7 years ago

On the fly would probably be best. It'll complicate the HTML injection but not by much. Only needs to be done once.

loisatwood commented 7 years ago

k. i'll get working on it.

wnda commented 7 years ago

Great. Let me know how you get on.

wnda commented 7 years ago

I'm thinking something like this:

var j = 0;
var _UI = {
  'search': '',
  'button': '',
  'close': ''
};

for (; Object.keys(_UI).length > j; ++j) {
  _UI[Object.keys(_UI)[j]] = generateID(j);
}

function generateID(idx) {
  return ('jsrch_' + idx + '_') + (new Date().getTime());
}
// see results: console.log(_UI);
// use like so: [...] '<button id="' + _UI.search + '">'; [...]
loisatwood commented 7 years ago

oops, sorry i hadn't even started yet!

wnda commented 7 years ago

No worries, I just knew how it could be done so I went ahead and did it myself.