Added support for text selection: selected text will be wrapped in hyperlink to source URL and used as default value for text input
This commit is contained in:
parent
0a9be160dd
commit
b1cc83945c
2 changed files with 22 additions and 24 deletions
|
@ -224,7 +224,7 @@ referrers.push(new Antville.Referrer("<% param.referrer %>",
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class='small'><% gettext 'Bookmarklet' %>:</td>
|
<td class='small'><% gettext 'Bookmarklet' %>:</td>
|
||||||
<td><a href="javascript: var site = '<% site.href %>'; window.open('<% site.static %>../www/formica.html#' + encodeURIComponent(site) + '&' + encodeURIComponent(location.href) + '&400&400', 'formica', 'width=630, height=350'); void(0);" title="<% gettext 'Drag to Bookmarks Bar' %>"><% gettext "Post to {0}" <% site.title %> %></a></td>
|
<td><a href="javascript: var siteUrl = '<% site.href %>'; var selection = (window.getSelection) ? window.getSelection() : document.selection.createRange(); selection = selection.text || selection; selection = selection + ''; var url='<% site.static %>../www/formica.html?s=' + encodeURIComponent(siteUrl) + '&l=' + encodeURIComponent(location.href) + '&w=400&h=400&c=' + encodeURIComponent(selection); window.open(url, 'formica', 'width=630, height=350'); void(0);" title="<% gettext 'Drag to Bookmarks Bar' %>"><% gettext "Post to {0}" <% site.title %> %></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2"><div class="listSeparator"> </div>
|
<td colspan="2"><div class="listSeparator"> </div>
|
||||||
|
|
|
@ -136,13 +136,20 @@ google.load('jquery', '1');
|
||||||
|
|
||||||
<script type='text/javascript'>
|
<script type='text/javascript'>
|
||||||
$(function() {
|
$(function() {
|
||||||
//var proxyUri = 'http://p3k-001.appspot.com/roxy';
|
var proxyUri = 'http://p3k-001.appspot.com/roxy';
|
||||||
var proxyUri = 'http://macke:8081/roxy';
|
//proxyUri = 'http://localhost:8081/roxy';
|
||||||
var args, siteUri, sourceUri, images, currentIndex;
|
var args, siteUri, sourceUri, images, currentIndex;
|
||||||
|
|
||||||
new function() {
|
new function() {
|
||||||
var parts = String(location.hash).split('#');
|
var search = String(location.search).substr(1);
|
||||||
args = parts.length > 1 ? parts[1].split('&') : [];
|
if (search.length > 0) {
|
||||||
|
args = {};
|
||||||
|
var parts = search.split('&');
|
||||||
|
$.each(parts, function(index, item) {
|
||||||
|
parts = item.split('=');
|
||||||
|
args[parts[0]] = decodeURIComponent(parts[1]);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.controls a').click(function(event) {
|
$('.controls a').click(function(event) {
|
||||||
|
@ -163,12 +170,14 @@ $(function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
if (args.length < 2 || !args[0] || !args[1]) {
|
if (!args.s || !args.l) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
siteUri = decodeURIComponent(args[0]);
|
siteUri = decodeURIComponent(args.s);
|
||||||
sourceUri = decodeURIComponent(args[1]);
|
sourceUri = decodeURIComponent(args.l);
|
||||||
if (siteUri && sourceUri) {
|
if (siteUri && sourceUri) {
|
||||||
|
var text = $.trim(decodeURIComponent(args.c));
|
||||||
|
text && $('#text').val('<a href="' + sourceUri + '">' + text + '</a>');
|
||||||
images = [];
|
images = [];
|
||||||
currentIndex = 0;
|
currentIndex = 0;
|
||||||
if (sourceUri.match(new RegExp('(?:bmp|gif|jpg|jpeg|png)$', 'i'))) {
|
if (sourceUri.match(new RegExp('(?:bmp|gif|jpg|jpeg|png)$', 'i'))) {
|
||||||
|
@ -176,6 +185,9 @@ $(function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$.getJSON(proxyUri + '?callback=?&url=' + sourceUri, function(data) {
|
$.getJSON(proxyUri + '?callback=?&url=' + sourceUri, function(data) {
|
||||||
|
if (!data.content) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var baseHref = getBaseHref(data.content);
|
var baseHref = getBaseHref(data.content);
|
||||||
var match, re = /(?:\(|=|"|')([^\s\(\)'">]+\.(?:gif|jpg|jpeg|png))/gi;
|
var match, re = /(?:\(|=|"|')([^\s\(\)'">]+\.(?:gif|jpg|jpeg|png))/gi;
|
||||||
while (match = re.exec(data.content)) {
|
while (match = re.exec(data.content)) {
|
||||||
|
@ -185,19 +197,6 @@ $(function() {
|
||||||
toggleImage();
|
toggleImage();
|
||||||
$('#image').attr({disabled: true, checked: false});
|
$('#image').attr({disabled: true, checked: false});
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
$(data.content).find('*[style*=background-image]').each(function(index, item) {
|
|
||||||
var re = new RegExp('^url\\((.+)\\)$');
|
|
||||||
var url = baseHref + $(this).css('background-image').replace(re, '$1');
|
|
||||||
if (url !== 'none') {
|
|
||||||
appendImage(url);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$(data.content).find('img').each(function(index, img) {
|
|
||||||
var url = baseHref + $(img).attr('src');
|
|
||||||
appendImage(url);
|
|
||||||
});*/
|
|
||||||
//$('body').append('OK');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,7 +245,6 @@ $(function() {
|
||||||
}
|
}
|
||||||
addImage.counter -= 1;
|
addImage.counter -= 1;
|
||||||
}
|
}
|
||||||
//addImage.images = images;
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var item = $('<img>');
|
var item = $('<img>');
|
||||||
|
@ -368,8 +366,8 @@ $(function() {
|
||||||
file_origin: imageUrl,
|
file_origin: imageUrl,
|
||||||
name: name,
|
name: name,
|
||||||
description: 'Source: ' + url.replace(new RegExp('^.+:///?([^/]+).*$'), '$1'),
|
description: 'Source: ' + url.replace(new RegExp('^.+:///?([^/]+).*$'), '$1'),
|
||||||
maxWidth: args[2] || '',
|
maxWidth: args.w || '',
|
||||||
maxHeight: args[3] || ''
|
maxHeight: args.h || ''
|
||||||
}, function(data, status, xhr) {
|
}, function(data, status, xhr) {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
console.log(this, arguments);
|
console.log(this, arguments);
|
||||||
|
|
Loading…
Add table
Reference in a new issue