Ejemplo n.º 1
0
javascript.do_after_body('''
var i;
var show_transcript_button   = document.getElementById('show_transcript_button'  );
var hide_transcript_button   = document.getElementById('hide_transcript_button'  );
var hide_transcript_button_2 = document.getElementById('hide_transcript_button_2');
if (show_transcript_button  ) { add_event_listener(show_transcript_button  ,'click',window.elidupree.show_transcript); }
if (hide_transcript_button  ) { add_event_listener(hide_transcript_button  ,'click',window.elidupree.hide_transcript); }
if (hide_transcript_button_2) { add_event_listener(hide_transcript_button_2,'click',window.elidupree.hide_transcript); }

var view_the_comic_p = document.getElementById('view_the_comic_p');
if (view_the_comic_p) {
  var dismiss_content_warning_a = document.createElement('a');
  dismiss_content_warning_a.className = 'dismiss_content_warning meta_controls_coloring';
  dismiss_content_warning_a.setAttribute('href','javascript:;');
  dismiss_content_warning_a.appendChild(document.createTextNode('View the comic'));
  view_the_comic_p.replaceChild(dismiss_content_warning_a, view_the_comic_p.firstChild);
  add_event_listener(dismiss_content_warning_a,'click',function() { document.documentElement.className += ' content_warning_dismissed'; });
  
  var disable_content_warnings_p = document.getElementById('disable_content_warnings_p');
  if (window.cookies_enabled) {
    var disable_content_warnings_a = document.createElement('a');
    disable_content_warnings_a.className = 'comic_disable_content_warnings meta_controls_coloring';
    disable_content_warnings_a.setAttribute('href','javascript:;');
    disable_content_warnings_a.appendChild(document.createTextNode('Disable content warnings'));
    disable_content_warnings_p.replaceChild(disable_content_warnings_a, disable_content_warnings_p.firstChild);
    add_event_listener(disable_content_warnings_a,'click',window.elidupree.disable_content_warnings);
  }
  else {
    disable_content_warnings_p.firstChild.nodeValue = 'You could disable content warnings if you had cookies enabled.';
  }
}

var enable_content_warnings_buttons = document.getElementsByClassName("enable_content_warnings_button");
for (i = 0; i < enable_content_warnings_buttons.length; ++i) {
  add_event_listener(enable_content_warnings_buttons[i],'click',window.elidupree.enable_content_warnings);
}
var disable_content_warnings_buttons = document.getElementsByClassName("disable_content_warnings_button");
for (i = 0; i < disable_content_warnings_buttons.length; ++i) {
  add_event_listener(disable_content_warnings_buttons[i],'click',window.elidupree.disable_content_warnings);
}
''')
Ejemplo n.º 2
0
javascript.do_after_body(r'''
var comments = document.getElementsByClassName("user_comment");
var all_comments_divs = document.getElementsByClassName("all_comments");
var random_post_link = document.getElementById("random_post");
var index_entries = document.getElementsByClassName("index_entry_link");
var random_entry;
var i;

function handle_transcript (stuff) {
  if (document.getElementById('show_transcript_button_'+ stuff [0])) {
    add_event_listener (document.getElementById('show_transcript_button_'+ stuff [0]), 'click', stuff [1]);
    add_event_listener (document.getElementById('hide_transcript_button_'+ stuff [0]), 'click', stuff [2]);
  }
}
for (i = 0; i < window.elidupree.transcripts.length; ++i) {
  handle_transcript (window.elidupree.transcripts [i]);
}


var do_secret_comment_identifiers = window.cookies_enabled && JSON && window.crypto;
var replace_secret_comment_identifier = function () {
  var array = new Uint32Array(4);
  window.crypto.getRandomValues(array);
  set_cookie ("secret_comment_identifier", JSON.stringify (array), 30);
};
if (do_secret_comment_identifiers &&!read_cookie ("secret_comment_identifier")) {replace_secret_comment_identifier ();}

function expand_reply_box(elem, id) {
  elem.innerHTML = ''+
    '<p class="reply_input_info">'+
      'You may use &lt;em&gt;<em>emphasized text</em>&lt;/em&gt;, &lt;strong&gt;<strong>strongly emphasized text</strong>&lt;/strong&gt;, <br/>&lt;q&gt;<q>Quoted text</q>&lt;/q&gt;, and &lt;blockquote&gt;longer, indented quotes&lt;/blockquote&gt;.'+
    '</p>'+
    'Your name: <input id="reply_username_'+id+'" type="text">'+
    '<textarea id="reply_contents_'+id+'" class="make_reply_input" cols="60" rows="7"></textarea><br/>'+
    '<div id="preview_space_'+id+'" class="preview_space"></div>'+
'';
  var preview_space = document.getElementById('preview_space_'+id);
  var username_input = document.getElementById('reply_username_'+id);
  var contents_input = document.getElementById('reply_contents_'+id);
  username_input.value = read_cookie('username');
  var preview_button = document.createElement("button");
  preview_button.innerHTML = 'Preview your reply';
  var submit_button = document.createElement("button");
  submit_button.innerHTML = 'Submit your reply';
  var previewed = false;
  var action = function(request_type) {
    return function() {
      preview_button.setAttribute('disabled', 'disabled');
      submit_button.setAttribute('disabled', 'disabled');
      set_cookie('username', username_input.value, 30);
      preview_space.innerHTML = "Processing...";
      var secret_string = "unavailable";
      var last_secret_string = "also unavailable";
      if (do_secret_comment_identifiers && request_type === 'submit') {
        last_secret_string = read_cookie ("secret_comment_identifier");
        replace_secret_comment_identifier (); 
        secret_string = read_cookie ("secret_comment_identifier");
      }
      $.post({
        'url': '/_services/comments',
        'timeout':10000,
        'headers': {
          'X-Not-A-Simple-Crossdomain-Request': 'yes',
        },
        'data': {
          'request_type': request_type,
          'parent': id,
          'username': username_input.value,
          'contents': contents_input.value,
          'secret_comment_identifier': secret_string,
          'last_secret_comment_identifier': last_secret_string,
        },
        'error': function (request, status, error) {
          if (status === 'timeout') {
            preview_space.innerHTML ='<p>Oops! The server didn\'t reply in time. Maybe trying again will help.</p>';
          } else {
            preview_space.innerHTML =' <p>Oops! The request returned "'+ status +'", "' + error + '". I regret that I have not prepared a good explanation for this error message.</p>';
          }
          preview_button.removeAttribute('disabled');
          submit_button.removeAttribute('disabled');
        },
        'success': function(text) {
          if (request_type === 'preview') {
            preview_space.innerHTML = ' <p>This is a preview. Your comment is not yet visible to other users.</p>' + text;
            if (!previewed) {
              previewed = true;
              elem.appendChild(submit_button);
            }
            preview_button.removeAttribute('disabled');
            submit_button.removeAttribute('disabled');
          }
          else {
            preview_space.innerHTML = ' <p>You\'ve submitted your comment! It\'s not visible to other users yet, but it probably will be soon, after I notice it and confirm that it\'s not obvious spam or harassment or something.</p>' + text;
          }
        }
      });
    };
  };
  add_event_listener(preview_button, 'click', action('preview'));
  add_event_listener(submit_button, 'click', action('submit'));
  elem.appendChild(preview_button);
}

function setup_reply_box(id) {
  var make_reply_box = document.getElementById("make_reply_box_"+id);
  var make_reply_button = document.getElementById("make_reply_button_"+id);
  var expanded = false;
  add_event_listener(make_reply_button,'click',function() {
    if (!expanded) {
      expanded = true;
      expand_reply_box(make_reply_box, id);
    }
  });
}
for (i = 0; i < comments.length; ++i) {
  setup_reply_box(comments[i].id);
}
for (i = 0; i < all_comments_divs.length; ++i) {
  setup_reply_box(all_comments_divs[i].id);
}
if (random_post_link) {
  random_entry = index_entries[Math.floor(Math.random()*index_entries.length)];
  random_post_link.setAttribute("href", random_entry.getAttribute("href"));
  random_post_link.innerHTML = random_post_link.dataset.itemname+random_entry.innerHTML;
  random_post_link.className = random_post_link.className+" enabled";
}

''')
Ejemplo n.º 3
0
.fake_warning_link {font-size: 71%; margin:0.4em 0; position: relative; z-index: 0;}
.fake_reveal_warning_button {color: blue; text-decoration: underline;}
html.javascript_enabled .fake_warning_link {display: inline-block;}
html.javascript_enabled .fake_reveal_warning_button {display: block;}
html.javascript_enabled .comic_warnings_list {display: none;}

.debug {display: none;}
html.debug_mode .debug {display: block; display: initial;}
html.debug_mode .not_debug {display: none;}
''')

javascript.do_after_body (r'''
$(".fake_warning_link").click (function () {
  $(this).css ("display", "block");
  $(this).children (".fake_reveal_warning_button").hide ();
  $(this).children (".comic_warnings_list").show ();
  return false;
});
''')

import html_pages
import bars

def exhibit (href, classes, thumbnail, blurb, enter_text):
  class_string ='''exhibit '''+ classes + (" no_image" if thumbnail is None else "")
  return (
    (('''<a href="'''+href +'''" class="'''+ class_string +'''">''') if  href else '<div class="'+ class_string + '">') +
      ('<img class="exhibit ' + classes + '" alt="" src="' + thumbnail + '" />' if thumbnail else '') +
      '<div class="exhibit_blurb">' + blurb + '</div>' +
      ('<div class=" exhibit_start_reading">' + enter_text + '</div>' if enter_text else '') + 
    ('</a>' if  href else '</div>') )