Table of Contents |
This template will simply check to see if the current visitor is subscribed to the page. If not it can take any 1 of 3 actions.
It should be noted that you cannot currently subscribe someone else to a page and for this template to work the user MUST at least visit the page.
Please direct all questions/comments to this forum thread.
| Version | Date | Author | Description |
| 1.0 | 11/24/2009 | rberinger | Inital Release |
For all the examples on this page, the code is shown before the working example. The code is shown with the syntax extension, and looks like this:
AutoSubscribe()
This means that the actual code on the page should be enclosed in a DekiScript block. If you want to copy the code from this page, then use the same procedure as described in steps 2-4 above.
Simply call this template somewhere on your page.
| Name | Type | Default | Description |
| action | str? | notice | The action to take when someone is not subscribed to a page. Valid options are: |
| subscribe | num? | 1 | The type of subscription: 1 = Current page, 2 = Current and Subpages |
| text | str? | varies on action | The text to use for any visual prompting or notifications. |
| timeout | num? | 5 | The number of seconds to display a notificaiton. This value is ignored if action=prompt. |
AutoSubscribe{action: 'notice', timeout: 10};
Please direct all questions/comments to this forum thread.
Forum member: joolsr for pushing me to create and share this template.
var action = ($action ?? $0 ?? 'notice'); //'notify, prompt, auto'
var SubscribeType = ($subscribe ?? $1 ?? 1); // 1= This page only, 2 = This as Sub-Pages
var text = ($text ?? $2 ?? ''); // Text to display for the prompt or notice
var timeout = (($timeout ?? $3 ?? 5) * 1000);
if(text == '') {
if(action == 'notice') {
let text = 'You are not subscribed to this page. Please subscribe to this page to recieve notification of a change.';
} else if(action == 'prompt') {
let text = 'Would you like to subscribe to this page?';
} else {
let text = 'You have been automatically subscribed to receive notifications if this page changes.';
}
}
// We need the id of the current page.
var pageID = page.id;
<div class="promptme">(text)</div>
<html><head>
<script type="text/javascript">"
var action = "..json.emit(action)..";
var SubscribeType = "..json.emit(SubscribeType)..";
var text = "..json.emit(text)..";
var timeout = "..json.emit(timeout)..";
$(document).ready(function() {
if($('div#deki-page-alerts a span.status').text() == 'Off') {
if(action == 'prompt') {
if(Confirmit(text)){
SetSubscription();
}
} else if(action =='notice') {
$('.promptme').fadeIn().idle(timeout).fadeOut('slow');
} else if(action == 'auto') {
SetSubscription();
}
}
});
function Confirmit(TheText) {
return confirm(TheText);
}
function SetSubscription() {
var pid = "..json.emit(pageID)..";
var subType = "..json.emit(SubscribeType)..";
var siteURI = "..json.emit(site.uri)..";
Deki.$.ajax({
type: 'POST',
url: siteURI + '/deki/gui/pageactions.php',
dataType: 'application/json',
data: {'action':'setalerts', 'pageId': pid, 'status':subType},
complete: function(data, status){
if(status == 'success') {
$('.promptme').fadeIn().idle(timeout).fadeOut('slow');
}
}
});
}
jQuery.fn.RefreshMe = function() {
window.location = window.location;
};
/* create a timeOut function in jQuery */
jQuery.fn.idle = function(time){
return this.each(function(){
var i = $(this);
i.queue(function(){
setTimeout(function(){
i.dequeue();
}, time);
});
});
};
"</script>
<style type="text/css">"
.promptme {
border-color: #666666;
border: solid;
background-color: rgba(0,0,0,.8);
height: 100px;
width: 200px;
position: fixed;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -100px;
padding: 10px;
color: white;
display: none;
}
"</style>
</head></html>
None.
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |
Copyright © 2011 MindTouch, Inc. Powered by