Skip to content

Instantly share code, notes, and snippets.

@joshstrange
Created March 15, 2012 19:50
Show Gist options
  • Save joshstrange/2046413 to your computer and use it in GitHub Desktop.
Save joshstrange/2046413 to your computer and use it in GitHub Desktop.
Add Translation icon to edit page
var elems = document.getElementsByTagName('a'),
i;
for (i in elems) {
if ((" " + elems[i].parentNode.className + " ").indexOf(" views-field-edit-node ") > -1) {
var url = elems[i].href;
var re1 = '.*?';
var re2 = '(node)';
var re3 = '(\\/)';
var re4 = '(\\d+)';
var re5 = '(\\/)';
var re6 = '(edit)';
var p = new RegExp(re1 + re2 + re3 + re4 + re5 + re6, ["i"]);
var m = p.exec(url);
var id = m[3];
var a = document.createElement('a');
var img = document.createElement('img');
img.src = 'http://alltechmulti.dev.ableengine.com/sites/all/modules/languageicons/flags/es.png';
a.appendChild(img);
a.href = 'http://es.alltechmulti.dev.ableengine.com/node/add/location?translation=' + id + '&target=es';
a.target = "_blank";
a.setAttribute('style', "float:right;");
elems[i].insertBefore(a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment