Skip to content

Instantly share code, notes, and snippets.

@atxryan
Created August 23, 2011 20:36
Show Gist options
  • Save atxryan/1166447 to your computer and use it in GitHub Desktop.
Save atxryan/1166447 to your computer and use it in GitHub Desktop.
Trac ticket form parametizer bookmarklet
javascript:(function(a,b,c,d,e,f,g,h){if(!(e=a.jQuery)||c>e.fn.jquery||d(e)){f=b.createElement(%22script%22);f.type=%22text/javascript%22;f.src=%22http://ajax.googleapis.com/ajax/libs/jquery/%22+c+%22/jquery.min.js%22;f.onload=f.onreadystatechange=function(){if(!g&&(!(h=this.readyState)||h==%22loaded%22||h==%22complete%22)){d((e=a.jQuery).noConflict(1),g=1);e(f).remove()}};b.documentElement.childNodes[0].appendChild(f)}})(window,document,%221.6%22,function(a,b){var%20c=window.location;var%20d=[];var%20e,f;a(%22fieldset#properties%20input:visible,%20fieldset#properties%20select%22).each(function(){if(a(this).val()!=%22%22){e=a(this).attr(%22name%22);f=a(this).val();d.push({name:e.replace(%22field_%22,%22%22),value:f})}});window.location=c.protocol+%22//%22+c.host+c.pathname+%22?%22+a.param(d)})
/*****
== Trac ticket form parametizer bookmarklet ==
I use this to quickly create a lot of Trac tickets with the same properties.
javascript:(function(a,b,c,d,e,f,g,h){if(!(e=a.jQuery)||c>e.fn.jquery||d(e)){f=b.createElement(%22script%22);f.type=%22text/javascript%22;f.src=%22http://ajax.googleapis.com/ajax/libs/jquery/%22+c+%22/jquery.min.js%22;f.onload=f.onreadystatechange=function(){if(!g&&(!(h=this.readyState)||h==%22loaded%22||h==%22complete%22)){d((e=a.jQuery).noConflict(1),g=1);e(f).remove()}};b.documentElement.childNodes[0].appendChild(f)}})(window,document,%221.6%22,function(a,b){var%20c=window.location;var%20d=[];var%20e,f;a(%22fieldset#properties%20input:visible,%20fieldset#properties%20select%22).each(function(){if(a(this).val()!=%22%22){e=a(this).attr(%22name%22);f=a(this).val();d.push({name:e.replace(%22field_%22,%22%22),value:f})}});window.location=c.protocol+%22//%22+c.host+c.pathname+%22?%22+a.param(d)})
Instructions:
1. Create a new bookmarklet and replace it's location with the javascript line above.
2. Fill in a Trac form with the shared properties (type, priority, keywords, et cetera)
3. Choose this bookmarklet from your bookmarks. The page will reload with a query string corresponding to the ticket form.
4. Fill in the specific details about this issue. Click "Create ticket". Once you're done, click back in the browser and the form is filled out with the shared properties.
*****/
// Load jQuery v1.6 if not already loaded on the page;
javascript: (function(e, a, g, h, f, c, b, d) {
if (! (f = e.jQuery) || g > f.fn.jquery || h(f)) {
c = a.createElement("script");
c.type = "text/javascript";
c.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + g + "/jquery.min.js";
c.onload = c.onreadystatechange = function() {
if (!b && (!(d = this.readyState) || d == "loaded" || d == "complete")) {
h((f = e.jQuery).noConflict(1), b = 1);
f(c).remove()
}
};
a.documentElement.childNodes[0].appendChild(c);
}
})(window, document, "1.6",
function($, L) {
var winloc = window.location
var queries = [];
var key, value;
// Iterate over field elements in Properties fieldset and construct queries key/value array
$("fieldset#properties input:visible, fieldset#properties select").each(function() {
if($(this).val() != '') {
key = $(this).attr("name");
value = $(this).val();
queries.push(
// Trac query string format does not need the 'field_' namespace
{"name" : key.replace("field_", ""), "value" : value}
);
}
});
// Reconstruct the URL path and append the parameterized key/value list
window.location = winloc.protocol + "//" + winloc.host + winloc.pathname + '?' + $.param(queries);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment