-
Notifications
You must be signed in to change notification settings - Fork 0
/
configr-ribbon.js
53 lines (48 loc) · 1.78 KB
/
configr-ribbon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*!
* jQuery Configr Ribbons Plugin 1.0
* https://github.com/configr/configr-ribbons
*
* Copyright 2013 Arthur Furlan <[email protected]>
* Copyright 2013 Amilton Paglia <[email protected]>
*/
(function($) {
"use strict";
// extract querystring data
var _parse_querystring = function(querystring) {
var params = {}, pieces, temp, i, l;
pieces = querystring.split('&');
for (i=0,l=pieces.length;i<l;i++) {
temp = pieces[i].split('=');
params[temp[0]] = temp[1];
}
return params;
}
// extract querystring param from configr script
var _configr_param = function(param, value) {
$('script').each(function() {
var http_pieces = this.src.split('?');
var path_pieces = http_pieces[0].split('/');
var path_script = path_pieces[path_pieces.length-1];
if (path_script.match(/^configr-ribbon(\.min)?\.js$/) && http_pieces.length > 1) {
var querystring = _parse_querystring(http_pieces[1]);
value = querystring[param] || value;
}
});
return value;
}
// default settings
var template = _configr_param('t', 'purple');
var referral = _configr_param('r', '');
// build assets url
var ribbon = 'http://media.configr.com/ribbon/' + template + '.png';
var target = 'http://configr.com/?r=' + referral
// include html content
$('body').prepend(
'<div id="configr-ribbon" style="position:absolute;top:0;right:0;'
+ 'background:transparent;width:119px;height:119px;text-indent:-9999px;'
+ 'cursor:hand;cursor:pointer;outline:0;border:none;"><a href="' + target
+ '" title="Managed via Configr"><img src="' + ribbon + '" '
+ 'style="position:absolute;top:-1px;right:0px;width:119px;height:119px;'
+ 'text-indent:-9999px;z-index:2;outline:0;border:none;"/></a></div>'
);
})(jQuery);