Created
January 20, 2014 22:07
-
-
Save ArcTanSusan/8530182 to your computer and use it in GitHub Desktop.
A simple Brython widget: button and pagination. I am debugging the show_additional_comment event handler. I get the error "Uncaught Error: local variable 'count' referenced before assignment". Feel free to leave comments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="Brython1.4/src/brython.js"></script> | |
<link rel="stylesheet" type="text/css" href='css/pagination.css'> | |
</head> | |
<body onload="brython(2)"> | |
<div class ="preloaded_comment" id="comment1">some sample comment #1 here</div> | |
<div class ="preloaded_comment" id="comment2">some sample comment #2 here</div> | |
<div class ="preloaded_comment" id="comment3">some sample comment #3 here</div> | |
<div class ="one_comment" id="comment4">some sample comment #4 here</div> | |
<div class ="one_comment" id="comment5">some sample comment #5 here</div> | |
<div class ="one_comment" id="comment6">some sample comment #6 here</div> | |
<div class ="one_comment" id="comment7">some sample comment #7 here</div> | |
<div class ="one_comment" id="comment8">some sample comment #8 here</div> | |
<div class ="one_comment" id="comment9">some sample comment #9 here</div> | |
<div class ="one_comment" id="comment10">some sample comment #10 here</div> | |
<div class ="one_comment" id="comment11">some sample comment #11 here</div> | |
<div class ="one_comment" id="comment12">some sample comment #12 here</div> | |
<div class ="one_comment" id="comment13">some sample comment #13 here</div> | |
<div class ="one_comment" id="comment14">some sample comment #14 here</div> | |
<div class ="one_comment" id="comment15">some sample comment #15 here</div> | |
<div class ="one_comment" id="comment16">some sample comment #16 here</div> | |
<div class ="one_comment" id="comment17">some sample comment #17 here</div> | |
<div class ="one_comment" id="comment18">some sample comment #18 here</div> | |
<div class ="one_comment" id="comment19">some sample comment #19 here</div> | |
<div class ="one_comment" id="comment20">some sample comment #20 here</div> | |
<button class="show_more">Show More</button> | |
</body> | |
<script type="text/python"> | |
from browser import doc, html | |
from browser.local_storage import storage | |
# Hide ALL comments, except pre-loaded comments, on page load. | |
all_comments = doc.get(selector='.one_comment') # an array object | |
for comment in all_comments: | |
comment.classList.add("hidden") | |
# Create a global variable count to keep track of the comment number | |
count = 4 | |
button = doc.get(selector='.show_more') | |
def show_additional_comment(ev): | |
next_comment_num = '#comment'+count | |
next_comment = doc.get(selector=next_comment_num) | |
for comment in next_comment: | |
comment.classList.remove("hidden") | |
comment.classList.add("visible") | |
count += 1 | |
button[0].bind('click', show_additional_comment) | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment