Browse Source
new "favorite" form with bookmarklet
new "favorite" form with bookmarklet
* disable facebook liking for now since it was getting complicated * new page for creating a favorite, can pass in a URL parameter too * bookmarklet code added to the "favorite" pagepull/5/head
Aaron Parecki
10 years ago
13 changed files with 277 additions and 47 deletions
-
97controllers/controllers.php
-
2lib/helpers.php
-
2public/css/favorite.css
-
33views/favorite-js.php
-
50views/favorite-popup.php
-
4views/layout.php
-
22views/liked-js.php
-
4views/new-bookmark.php
-
74views/new-favorite.php
-
4views/new-post.php
-
2views/partials/bookmark-bookmarklet.php
-
10views/partials/favorite-bookmarklet.php
-
8views/settings.php
@ -0,0 +1,33 @@ |
|||
|
|||
console.log("Favoriting URL: <?= $this->url ?>"); |
|||
|
|||
var css = document.createElement('link'); |
|||
css.rel="stylesheet"; |
|||
css.type="text/css"; |
|||
css.href="<?= Config::$base_url ?>css/favorite.css"; |
|||
document.body.appendChild(css); |
|||
|
|||
function show_star() { |
|||
var star = document.createElement('img'); |
|||
star.id="quill-star"; |
|||
star.src="<?= Config::$base_url ?>images/<?= $this->like_url ? 'star' : 'red-x' ?>.svg"; |
|||
star.onload=function() { |
|||
setTimeout(function(){ |
|||
|
|||
document.getElementById('quill-star').classList.add('hidden'); |
|||
var el = document.getElementById('quill-star'); |
|||
el.parentNode.removeChild(el); |
|||
if(typeof favorite_finished == "function") { |
|||
favorite_finished(); |
|||
} else { |
|||
// For now, redirect the user to the URL of their favorite so they can see it posted.
|
|||
// Might want to change this later.
|
|||
window.location = "<?= $this->like_url ?>"; |
|||
} |
|||
|
|||
}, 1200); |
|||
} |
|||
document.body.appendChild(star); |
|||
} |
|||
|
|||
show_star(); |
@ -0,0 +1,50 @@ |
|||
<!doctype html> |
|||
<html lang="en"> |
|||
<head> |
|||
<title>Favoriting</title> |
|||
</head> |
|||
<body> |
|||
<script> |
|||
function favorite_finished() { |
|||
self.close(); |
|||
} |
|||
</script> |
|||
<script src="/favorite.js?url=<?= urlencode($this->url) ?>&token=<?= $this->token ?>"></script> |
|||
|
|||
<?php /* |
|||
<script> |
|||
window.quillFbInit = function() { |
|||
FB.getLoginStatus(function(response) { |
|||
|
|||
if (response.status === 'connected') { |
|||
// the user is logged in and has authenticated your
|
|||
// app, and response.authResponse supplies
|
|||
// the user's ID, a valid access token, a signed
|
|||
// request, and the time the access token
|
|||
// and signed request each expire
|
|||
var uid = response.authResponse.userID; |
|||
var accessToken = response.authResponse.accessToken; |
|||
console.log(accessToken); |
|||
|
|||
FB.api("/<?= $this->facebook_id ?>/likes", "post", function(response){ |
|||
console.log(response); |
|||
show_star(); |
|||
}); |
|||
|
|||
} else if (response.status === 'not_authorized') { |
|||
// the user is logged in to Facebook,
|
|||
// but has not authenticated your app
|
|||
console.log("Logged in but not authorized"); |
|||
} else { |
|||
// the user isn't logged in to Facebook.
|
|||
console.log("User isn't logged in"); |
|||
} |
|||
}); |
|||
}; |
|||
</script> |
|||
<?= partial('partials/fb-script') ?>
|
|||
*/ ?>
|
|||
|
|||
|
|||
</body> |
|||
</html> |
@ -1,22 +0,0 @@ |
|||
<?= $this->facebook_id ? partial('partials/fb-script') : '' ?>
|
|||
|
|||
console.log("Favoriting URL: <?= $this->url ?>"); |
|||
|
|||
var star = document.createElement('img'); |
|||
star.id="quill-star"; |
|||
star.src="http://quill.dev/images/<?= $this->like_url ? 'star' : 'red-x' ?>.svg"; |
|||
document.body.appendChild(star); |
|||
|
|||
var css = document.createElement('link'); |
|||
css.rel="stylesheet"; |
|||
css.type="text/css"; |
|||
css.href="http://quill.dev/css/favorite.css"; |
|||
document.body.appendChild(css); |
|||
|
|||
setTimeout(function(){ |
|||
|
|||
document.getElementById('quill-star').classList.add('hidden'); |
|||
var el = document.getElementById('quill-star'); |
|||
el.parentNode.removeChild(el); |
|||
|
|||
}, 1200); |
@ -0,0 +1,74 @@ |
|||
<div class="narrow"> |
|||
<?= partial('partials/header') ?>
|
|||
|
|||
<div style="clear: both;"> |
|||
<div class="alert alert-success hidden" id="test_success"><strong>Success! We found a Location header in the response!</strong><br>Your post should be on your website now!<br><a href="" id="post_href">View your post</a></div> |
|||
<div class="alert alert-danger hidden" id="test_error"><strong>Your endpoint did not return a Location header.</strong><br>See <a href="/creating-a-micropub-endpoint">Creating a Micropub Endpoint</a> for more information.</div> |
|||
</div> |
|||
|
|||
<form role="form" style="margin-top: 20px;" id="note_form"> |
|||
|
|||
<div class="form-group"> |
|||
<label for="note_url">URL to Favorite (<code>like-of</code>)</label> |
|||
<input type="text" id="note_url" value="<?= $this->url ?>" class="form-control"> |
|||
</div> |
|||
|
|||
<div style="float: right; margin-top: 6px;"> |
|||
<button class="btn btn-success" id="btn_post">Post</button> |
|||
</div> |
|||
|
|||
</form> |
|||
|
|||
<div style="clear: both;"></div> |
|||
|
|||
<hr> |
|||
<div style="text-align: right;"> |
|||
Bookmarklet: <a href="javascript:<?= js_bookmarklet('partials/favorite-bookmarklet', $this) ?>" class="btn btn-default btn-xs">favorite</a> |
|||
</div> |
|||
|
|||
</div> |
|||
|
|||
<script> |
|||
$(function(){ |
|||
|
|||
// ctrl-s to save
|
|||
$(window).on('keydown', function(e){ |
|||
if(e.keyCode == 83 && e.ctrlKey){ |
|||
$("#btn_post").click(); |
|||
} |
|||
}); |
|||
|
|||
$("#btn_post").click(function(){ |
|||
|
|||
var syndications = []; |
|||
$("#syndication-container button.btn-info").each(function(i,btn){ |
|||
syndications.push($(btn).data('syndication')); |
|||
}); |
|||
|
|||
$.post("/favorite", { |
|||
url: $("#note_url").val() |
|||
}, function(data){ |
|||
var response = JSON.parse(data); |
|||
|
|||
if(response.location != false) { |
|||
|
|||
$("#test_success").removeClass('hidden'); |
|||
$("#test_error").addClass('hidden'); |
|||
$("#post_href").attr("href", response.location); |
|||
|
|||
window.location = response.location; |
|||
} else { |
|||
$("#test_success").addClass('hidden'); |
|||
$("#test_error").removeClass('hidden'); |
|||
} |
|||
|
|||
}); |
|||
return false; |
|||
}); |
|||
|
|||
bind_syndication_buttons(); |
|||
}); |
|||
|
|||
<?= partial('partials/syndication-js') ?>
|
|||
|
|||
</script> |
@ -1,4 +1,4 @@ |
|||
javascript:(function(){ |
|||
(function(){ |
|||
var t;try{t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));}catch(e){t="";}; |
|||
window.location="<?= Config::$base_url ?>bookmark?url="+encodeURIComponent(window.location.href)+"&content="+encodeURIComponent((t == '' ? '' : '"'+t+'"'))+"&name="+encodeURIComponent(document.title)+"&token=<?= $this->token ?>"; |
|||
})(); |
|||
|
@ -0,0 +1,10 @@ |
|||
var quill_popup=function(){ |
|||
window.open(document.getElementById('quill-script').src.replace('favorite.js?','favorite-popup?'),'quill-like', 'status=no,directories=no,location=no,resizable=no,menubar=no,width=300,height=200,toolbar=no'); |
|||
}; |
|||
(function(){ |
|||
var quill=document.createElement('script'); |
|||
quill.src='<?= Config::$base_url ?>favorite.js?url='+encodeURIComponent(window.location)+'&token=<?= $this->token ?>'; |
|||
quill.setAttribute('id','quill-script'); |
|||
quill.setAttribute('onerror', 'quill_popup()'); |
|||
document.body.appendChild(quill); |
|||
})(); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue