Skip to content

Commit

Permalink
generate global message by tags
Browse files Browse the repository at this point in the history
  • Loading branch information
davidxuan committed Mar 22, 2019
1 parent d25dc1c commit a21a3d9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
14 changes: 14 additions & 0 deletions assets/js/message.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
var msg_contents = {
"message": [{
"text": "Did you know that you can contribute to OpenGenus IQ as well and become a writer 💪.",
"link": "https://discourse.opengenus.org/t/become-a-writer-at-opengenus-iq/843/",
}, {
"text": "Join our community today and ask us anything 💪.",
"link": "https://discourse.opengenus.org/"
}],
"algorithm": [{
"text": "Want to contribute to Algorithms? See this task list and make your first contribution today 💪.",
"link": "https://discourse.opengenus.org/t/task-list-algorithms/2052/",
}, {
"text": "Want to contribute to Data Structure? See this task list and make your first contribution today 💪.",
"link": "https://discourse.opengenus.org/t/task-list-data-structures/1898/"
}],
"data-structure": [{
"text": "See how Van Emde Boas tree performs operations in O(log log N) time complexity 💪.",
"link": "https://discourse.opengenus.org/t/van-emde-boas-tree/2216",
}, {
"text": "Learn about Y fast trie, the bitwise version of trie 💪.",
"link": "https://discourse.opengenus.org/t/y-fast-trie-data-structure/2152"
}]
}
43 changes: 27 additions & 16 deletions post.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,27 @@ into the {body} of the default.hbs template --}}
{{> "site-nav"}}
</div>
</header>


<script type="text/javascript" src="{{asset "js/message.js"}}"></script>
<script type="text/javascript">
function generateMSG(tag) {
if (tag in msg_contents) {
msg = msg_contents[tag];
} else {
msg = msg_contents['message'];
}
num = Math.floor(Math.random() * msg.length);
msg = msg[num];
var text = msg['text'];
var link = msg['link'];
var msg_box = document.getElementById('global_message');
var a = document.getElementById('global_message_link');
a.href = link;
a.innerHTML = text;
msg_box.onclick = function () {
window.open(link, "_self");
};
}
</script>
{{!-- Everything inside the #post tags pulls data from the post --}}
{{#post}}

Expand All @@ -22,6 +41,12 @@ into the {body} of the default.hbs template --}}
<h1 class="post-full-title" style="color:#292929; font-size:30px ; ">{{title}}</h1>
<div id="global_message" style="background: rgb(181, 222, 250);padding-top:20px;padding-bottom:20px;">
<a id='global_message_link' style="font-color: #a0a1a1; "></a>
{{#if tags}}
<p id="hidden" hidden>{{primary_tag.name}}</p>
<script>generateMSG(document.getElementById('hidden').innerText);</script>
{{else}}
<script>generateMSG('message');</script>
{{/if}}
</div>
<br>
<p style="display: inline-block; font-size: 75%">Share this:</p>
Expand Down Expand Up @@ -293,7 +318,6 @@ into the {body} of the default.hbs template --}}

{{!-- The #contentFor helper here will send everything inside it up to the matching #block helper found in default.hbs --}}
{{#contentFor "scripts"}}
<script type="text/javascript" src="{{asset "js/message.js"}}"></script>
<script type="text/javascript" src="{{asset "js/lightbox/lightbox.js"}}"></script>
<script>
Expand Down Expand Up @@ -372,8 +396,6 @@ into the {body} of the default.hbs template --}}
})();
</script>



{{!-show/hide tags if they excceed one line--}}
<script DOCTYPE="text/javascript">
Expand All @@ -390,17 +412,6 @@ into the {body} of the default.hbs template --}}
});
$(document).ready(function () {
num = Math.floor(Math.random() * msg_contents['algorithm'].length); // later change algorithm to tag names
msg = msg_contents['algorithm'][num];
var text = msg['text'];
var link = msg['link'];
var msg_box = document.getElementById('global_message');
var a = document.getElementById('global_message_link');
a.href = link;
a.innerHTML = text;
msg_box.onclick = function () {
window.open(link, "_self");
};
var taglist_height = $('#taglist').height();
var tag_height = $('#tag_element').height();
Expand Down

0 comments on commit a21a3d9

Please sign in to comment.