added bookmarklet that doesn't work yet
This commit is contained in:
parent
4d5a9e446f
commit
09d2e9f831
37
cookbook/static/js/bookmarklet.js
Normal file
37
cookbook/static/js/bookmarklet.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
(function(){
|
||||||
|
|
||||||
|
var v = "1.3.2";
|
||||||
|
|
||||||
|
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
|
||||||
|
var done = false;
|
||||||
|
var script = document.createElement("script");
|
||||||
|
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
|
||||||
|
script.onload = script.onreadystatechange = function(){
|
||||||
|
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
|
||||||
|
done = true;
|
||||||
|
initBookmarklet();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.getElementsByTagName("head")[0].appendChild(script);
|
||||||
|
} else {
|
||||||
|
initBookmarklet();
|
||||||
|
}
|
||||||
|
function initBookmarklet() {
|
||||||
|
(window.bookmarkletTandoor = function() {
|
||||||
|
r = confirm('Click OK to import recipe automatically, click Cancel to import the recipe manually.');
|
||||||
|
if (r) {
|
||||||
|
auto=true
|
||||||
|
} else {
|
||||||
|
auto=false
|
||||||
|
}
|
||||||
|
|
||||||
|
var newIframe = document.createElement('iframe');
|
||||||
|
newIframe.width = '200';newIframe.height = '200';
|
||||||
|
newIframe.src = localStorage.getItem('importURL');
|
||||||
|
document.body.appendChild(newIframe);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
)();
|
||||||
|
}
|
||||||
|
})();
|
@ -1,6 +1,7 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
{% load custom_tags %}
|
||||||
|
|
||||||
{% block title %}{% trans 'URL Import' %}{% endblock %}
|
{% block title %}{% trans 'URL Import' %}{% endblock %}
|
||||||
|
|
||||||
@ -20,9 +21,15 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<h2> {% trans 'Import' %} </h2>
|
<div class="row px-3" style="justify-content:space-between;">
|
||||||
|
<h2> {% trans 'Import' %} </h2> <!--{{ request.get_host }}{% url 'data_import_url' %} -->
|
||||||
|
<a class="btn btn-outline-info btn-sm"
|
||||||
|
style="height:50%"
|
||||||
|
href="{% bookmarklet request.get_host request.is_secure %}"
|
||||||
|
title="{% trans 'Drag me to your bookmarks to import recipes from anywhere' %}">
|
||||||
|
<img src="{% static 'assets/favicon-16x16.png' %}">{% trans 'Bookmark Me!' %} </a>
|
||||||
|
</div>
|
||||||
<nav class="nav nav-pills flex-sm-row" style="margin-bottom:10px">
|
<nav class="nav nav-pills flex-sm-row" style="margin-bottom:10px">
|
||||||
<a class="nav-link active" href="#nav-url" data-toggle="tab" role="tab" aria-controls="nav-url" aria-selected="true">URL</a>
|
<a class="nav-link active" href="#nav-url" data-toggle="tab" role="tab" aria-controls="nav-url" aria-selected="true">URL</a>
|
||||||
<a class="nav-link" href="#nav-app" data-toggle="tab" role="tab" aria-controls="nav-app">App</a>
|
<a class="nav-link" href="#nav-app" data-toggle="tab" role="tab" aria-controls="nav-app">App</a>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import bleach
|
import bleach
|
||||||
|
import re
|
||||||
import markdown as md
|
import markdown as md
|
||||||
from bleach_allowlist import markdown_attrs, markdown_tags
|
from bleach_allowlist import markdown_attrs, markdown_tags
|
||||||
from cookbook.helper.mdx_attributes import MarkdownFormatExtension
|
from cookbook.helper.mdx_attributes import MarkdownFormatExtension
|
||||||
@ -6,6 +7,7 @@ from cookbook.helper.mdx_urlize import UrlizeExtension
|
|||||||
from cookbook.models import Space, get_model_name
|
from cookbook.models import Space, get_model_name
|
||||||
from django import template
|
from django import template
|
||||||
from django.db.models import Avg
|
from django.db.models import Avg
|
||||||
|
from django.templatetags.static import static
|
||||||
from django.urls import NoReverseMatch, reverse
|
from django.urls import NoReverseMatch, reverse
|
||||||
from recipes import settings
|
from recipes import settings
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
@ -106,3 +108,23 @@ def message_of_the_day():
|
|||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def is_debug():
|
def is_debug():
|
||||||
return settings.DEBUG
|
return settings.DEBUG
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def bookmarklet(host, secure):
|
||||||
|
if secure:
|
||||||
|
prefix = "https://"
|
||||||
|
else:
|
||||||
|
prefix = "http://"
|
||||||
|
|
||||||
|
bookmark = "javascript: \
|
||||||
|
(function(){ \
|
||||||
|
if(window.bookmarkletTandoor!==undefined){ \
|
||||||
|
bookmarkletTandoor(); \
|
||||||
|
} else { \
|
||||||
|
localStorage.setItem('importURL', '"+ prefix + host + reverse('api_bookmarklet') +"'); \
|
||||||
|
document.body.appendChild(document.createElement(\'script\')).src=\'" \
|
||||||
|
+ prefix + host + static('js/bookmarklet.js') + "? \
|
||||||
|
r=\'+Math.floor(Math.random()*999999999);}})();"
|
||||||
|
|
||||||
|
return re.sub(r"[\n\t]*", "", bookmark)
|
||||||
|
Loading…
Reference in New Issue
Block a user