Commits

Yang Zhang committed 1a30294

add random word feature

  • Participants
  • Parent commits d1e57bc

Comments (0)

Files changed (4)

File static/main.css

     //border-top: 3px solid #00aba9;
     border-left: 3px solid #00aba9;
     padding: 0px 5px 15px 15px;
-    margin: 25px 0;
+    margin: 35px 0;
 }
 
 .widget:first-child{

File static/main.js

 
 
 
-
-
 });
 
 
     
 }
 
+
+
+function getRandomWord(){
+     $.getJSON('/jsonrandomword', function (data) {
+         //console.log(data.content);
+         var word = data.content.spell;
+         var linkword = tolinkWord(word);
+         if (linkword == "") {
+             return;
+         }
+         if ($("#word_meaning #" + linkword).length == 0) {
+             constructTabContent(word, null);
+         }
+         if ($('[data-toggle=' + linkword + ']').length == 0) {
+             constructTab(word);
+         } else {
+             $('[data-toggle=' + linkword + ']').tab('show');
+             return;
+         }
+         if (data.content == null) {
+             $('#' + tolinkWord(word)).html($('#nofound').html());
+             return;
+         }
+         render_template('meaning_template', data.content, tolinkWord(word));
+         
+         var newTab = $('#word_chooser_tab a:last');
+         newTab.click(function (e) {
+             e.preventDefault();
+             $(this).tab('show');
+         });
+         /*
+         newTab.on('shown',function(e){
+         alert('1');
+         });
+          */
+         newTab.tab('show');
+     })
+     .error(function () {
+         alert("error");
+     });
+}
+
+
 function render_template(templateid, data, targetid) {
     var template = $('#'+templateid).html();
     var html = Mustache.to_html(template, data);

File templates/base.html

         
         <div class="nav-collapse span12">
           <div class='span8'>
-              <a id='zendict'class=" span2 brand" style='padding-left:0;'>ZENDICT2</a>
+              <a id='zendict'href='/' title='zendict2'class=" span2 brand" style='padding-left:0;'>ZENDICT2</a>
               <form class="navbar-search span10" action="javascript:void(0);" novalidate="novalidate">
                 <div class='input-append'>
                 <input type="text" id='word_search' class="search-query input-xxlarge"  data-provide="typeahead" data-source='["Test","test1","Teds"]' placeholder="Search" spellcheck="false" greditor="true" style='padding-top: 2px;'/>
             <li><a href='javascript:void(0)' onclick='addSoon();'>简</a></li>
             <li><a href='javascript:void(0)' onclick='addSoon();'>繁</a></li>
           #}
-            <li><a title='show random word' href='javascript:void(0)' onclick='addSoon();'>Random</a></li>
-            <li id='user'class="span2">
+            <li><a title='show random word' href='javascript:void(0)' onclick='getRandomWord();'>Random</a></li>
+            <li id='user'class="span2 pull-right">
               <div class="btn-group" style="margin-top:7px;">
                   <a class="btn btn-small btn-info green" href="#"><i class="icon-user icon-white" style='margin-top: 2px;'></i> guest</a>
                   <a class="btn btn-small btn-info green dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret green"></span></a>

File templates/widgets/opensource.html

 I use some opensources in this project, 
 so I list them as a token of gratitude:
 <ul>
-    <li><a href='http://talkslab.github.com/metro-bootstrap/index.html'>metro-bootstrap</a></li>
+    <li><a href='http://talkslab.github.com/metro-bootstrap/index.html'>Metro-Bootstrap</a></li>
+    <li><a href='http://mustache.github.com/'>Mustache</a></li>
     <li><a href='http://fortawesome.github.com/Font-Awesome/'>Font Awesome</a> (awesome! )</li>
-    <li><a href='http://flask.pocoo.org/'>flask</a></li>
+    <li><a href='http://flask.pocoo.org/'>Flask</a></li>
 </ul>
 Of course, this project is opensource, too.
 You can find code <a href='https://bitbucket.org/zhy0216/zendict2'>here</a>