Was this page helpful?

Automatic Page Subscriptions

  • You do not have permissions to view this page - please try logging in.
Table of Contents

Introduction

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.  

  • Notify them that they are not subscribed
  • Prompt them to Subscribe.
  • Auto Subscribe them to the page.

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.

History

Version Date Author Description
 1.0  11/24/2009  rberinger  Inital Release

Requirements

  • This template requires MindTouch version: 9.02 or greater.

How do I install it?

  1. Create a template, call it "Template:AutoSubscribe" (or rename as you desire).  You must have UNSAFECONTENT permission for this to work.
  2. Create a "DekiScript" block on the template page (use the "Style" menu in the editor")
  3. Copy the code from the end of this page and paste it into the DekiScript block.  To copy, click "expand source", then mouse over the top right corner of the source code, and click the "view source" button.  This will pop up a window with the source code.  Select all, then copy to clipboard.
  4. Make sure there isn't an extra blank paragraph after the DekiScript block! Do this every time you edit!!!  
  5. Save.

A quick note about the examples on this page

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. 

How do I use it?

 Simply call this template somewhere on your page.

Arguments

Name
Type
Default
Description
 action  str?  notice

 The action to take when someone is not subscribed to a page.  

Valid options are:
 auto: Automatically Subscribe current visitor to page.
 prompt:  Ask the visitor if they would like to be subscribed to the page.
 notice:  Present a simple reminder about the page subscriptions.

 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.

Examples

AutoSubscribe{action: 'notice', timeout: 10};
You are not subscribed to this page. Please subscribe to this page to recieve notification of a change.

Reference(s)

Please direct all questions/comments to this forum thread.

Credits/Special Thanks

Forum member: joolsr for pushing me to create and share this template.

Template/Extension Source Code

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> 

Disclaimers

None.

Was this page helpful?
Tag page

Files 1

FileVersionSizeModified 
Viewing 1 of 1 comments: view all
Awesome!
Posted 07:28, 21 Mar 2011
Viewing 1 of 1 comments: view all
You must login to post a comment.

Copyright © 2011 MindTouch, Inc. Powered by