Skip to content

Commit

Permalink
Merge pull request #27 from davidxuan/master
Browse files Browse the repository at this point in the history
update message.js, implemente announcements
  • Loading branch information
AdiChat authored Mar 22, 2019
2 parents d8d3ecb + 4b591bd commit da244ab
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 18 deletions.
23 changes: 23 additions & 0 deletions assets/js/message.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
var msg_contents = {
"display": "1",
"announce": "0",
"global": [{
"text": "Learn how Freivalds’ algorithm verifies matrix multiplication faster than doing matrix multiplication 💪.",
"link": "https://discourse.opengenus.org/t/freivalds-algorithm-for-verifying-matrix-multiplication/963",
}],
"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": "Learn how comb sort improves bubble sort 💪.",
"link": "https://discourse.opengenus.org/t/comb-sort-algorithm/2274"
}],
"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": "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/"
}, {
"text": "Learn about Y fast trie, the bitwise version of trie 💪.",
"link": "https://discourse.opengenus.org/t/y-fast-trie-data-structure/2152"
}]
}
57 changes: 39 additions & 18 deletions post.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,36 @@ 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 (msg_contents['display'] == 0) {
var elem = document.querySelector('#global_message');
elem.style.display = 'none';
return;
}
if (msg_contents['announce'] == 0) {
if (tag in msg_contents) {
msg = msg_contents[tag];
} else {
msg = msg_contents['message'];
}
} else {
msg = msg_contents['global'];
}
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, "_blank");
};
}
</script>
{{!-- Everything inside the #post tags pulls data from the post --}}
{{#post}}

Expand All @@ -20,8 +48,15 @@ into the {body} of the default.hbs template --}}

<header class="post-full-header">
<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>
<div id="global_message"
style="cursor:pointer; background:rgb(181, 222, 250); padding-top:20px; padding-bottom:20px;">
<a id='global_message_link' target="_blank" 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 +328,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 +406,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 +422,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 da244ab

Please sign in to comment.