## The contents of this file are subject to the Common Public Attribution
## License Version 1.0. (the "License"); you may not use this file except in
## compliance with the License. You may obtain a copy of the License at
## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
## License Version 1.1, but Sections 14 and 15 have been added to cover use of
## software over a computer network and provide for limited attribution for the
## Original Developer. In addition, Exhibit A has been modified to be
## consistent with Exhibit B.
##
## Software distributed under the License is distributed on an "AS IS" basis,
## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
## the specific language governing rights and limitations under the License.
##
## The Original Code is reddit.
##
## The Original Developer is the Initial Developer.  The Initial Developer of
## the Original Code is reddit Inc.
##
## All portions of the code written by reddit are Copyright (c) 2006-2012
## reddit Inc. All Rights Reserved.
###############################################################################

<%! 
   from r2.lib.template_helpers import static, get_domain, add_sr, panel_size
   from r2.lib.strings import Score
%>

<%inherit file="reddit.html"/>
<%namespace file="utils.html" import="plain_link, logout"/>
<%namespace file="printablebuttons.html" import="state_button, comment_button"/>
<%namespace file="printable.html" import="thing_css_class, score" />

<%def name="javascript_run()">
  ${parent.javascript_run()}
  reddit.external_frame = true;
  toolbar = new toolbar_p("${panel_size('expanded')}", "${panel_size('collapsed')}");
</%def>

<%def name="bodyHTML()">
<body class="toolbar">
  <div class="preload">
    ## everything in here will get rendered off screen for pre-fetching purposes.
    <div class="arrow up"></div>
    <div class="arrow upmod"></div>
    <div class="arrow down"></div>
    <div class="arrow downmod"></div>
    <img src="${static('link.png')}" />
    <img src="${static('link-active.png')}" />
    <img src="${static('tb-loginarrow-right.png')}" />
  </div>

  <div class="left-side">
    <a class="logo" target="_top" href="http://${get_domain(cname = thing.cname)}/">
      <img src="${static('logo-toolbar.png')}" alt="${thing.site_description or thing.site_name}"
           title="${thing.site_description or thing.site_name}"/>
    </a>

    %if thing._fullname:
      ${withlink()}
    %endif
  </div>

  <div class="right-side">
    <a href="${thing.url}" onclick="return toolbar.toggle_linktitle(this);">
      <img class="linkicon" src="${static('link.png')}"
           height="13" width="16"
           title="${_('show url')}" alt="${_('show url')}"/>
      <img class="linkicon" src="${static('link-active.png')}"
           style="display: none" height="13" width="16"
           title="${_('hide url')}" alt="${_('hide url')}"/>
    </a>

    <a class="serendipity popped-button"
       title="${_('load a random link')}"
       onmousedown="toolbar.push_button(this)"
       onmouseup="toolbar.pop_button(this)"
       onclick="toolbar.serendipity()"
       href="${add_sr('/random')}"
       target="_top">
      %if thing.default_sr:
        ${_("serendipity")}
      %else:
        ${"%(subreddit)s serendipity" % dict (subreddit=thing.site_name)}
      %endif
    </a>

    %if thing.user_is_loggedin:
      <a href="http://${get_domain(cname = thing.cname)}/user/${thing.user_name}"
         title="${_('visit your userpage')}"
         class="clickable" target="_top">${thing.user_name}</a>
    %elif thing._fullname:
      <a href="${thing.loginurl}" target="_top" class="clickable">
        ${_("login / register")}
      </a>
    %endif

    %if thing.have_messages:
      <a target="_top" href="/message/inbox/">
        <img src="${static('mail.png')}"
             width="15" height="10"
             alt="${_('new mail')}" title="${_('new mail')}" />
      </a>
    %endif

    <a target="_top" href="/help/toolbar">
      <img src="${static('help.png')}"
           width="11" height="11"
           alt="${_('help')}" title="${_('help')}" />
    </a>

    <a href="${thing.url}" target="_top">
      <img src="${static('kill.png')}"
           width="11" height="11"
           alt="${_('visit this link without the toolbar')}"
           title="${_('visit this link without the toolbar')}" />
    </a>
  </div>

  <div class="middle-side clickable">
    %if thing._fullname:
    <a
       title="${_('click to visit the main page for this submission')}"
       class="title clickable"
       target="_top"
       href="${thing.permalink}"
    >
         ${thing.title}

         %if thing.domain:
           <span class="domain">&#32;(${thing.domain})</span>
         %endif
    </a>
    %else:
      ${plain_link(_('click to submit this link to reddit'), thing.submit_url,
                      target="_top", _class="submit")}
    %endif
    <div class="url" style="display: none;">
      <form onsubmit="return toolbar.gourl(this, '${add_sr('/s/')}')">
        <input type="text" value="${thing.url}" />
      </form>
    </div>
  </div>

  <div class="toolbar-status-bar" style="display: none;">
    <div class="login-arrow" style="display: none;">
      <img src="${static('tb-loginarrow-right.png')}" class="login-arrow-right"/>
      <div class="login-arrow-left">
        <p class="login-message">
          ${_("you'll need to login or register to do that")}
        </p>
      </div>
    </div>
  </div>
</body>
</%def>


<%def name="withlink()">
<span class="${thing_css_class(thing)}">
  ## add us to the click cookie
  <script type="text/javascript">
    $(function() {
      add_thing_id_to_cookie("${thing._fullname}", "recentclicks2");
    });
  </script>
  <span class="entry ${'likes' if thing.likes else 'dislikes' if thing.likes is False else 'unvoted'}">
    ${score(thing, thing.likes, tag='b')}
  </span>
  <span class="arrows">
    <%def name="arrow(direction, style, message)">
      <a class="arrow ${direction + style}"
         title="${_('vote %(direction)s') % dict(direction=direction)}"
       %if thing.user_is_loggedin:
         href="javascript:void(0);"
         onclick="$(this).vote('${thing.votehash}', null, event)"
       %else:
         href="${thing.loginurl}"
         target="_top"
         onclick="return toolbar.login_msg()"
       %endif
      >
        ${message}
      </a>
    </%def>

    %if getattr(thing, "votable", True):
      ${arrow("up",   thing.upstyle,   _("like"))}
      ${arrow("down", thing.downstyle, _("dislike"))}
    %endif
  </span>


  %if thing.user_is_loggedin:
    <span>
    %if thing.saved:
      ${state_button("unsave", _("unsave"),
        "return change_state(this, 'unsave');", "<b>%s</b>" % _("unsaved"),
        a_class="clickable")}
    %else:
       ${state_button("save", _("save"),
         "return change_state(this, 'save');", "<b>%s</b>" % _("saved"),
         a_class="clickable")}
    %endif
    </span><span>
    %if thing.hidden:
      ${state_button("unhide", _("unhide"),
        "return change_state(this, 'unhide');", "<b>%s</b>" % _("unhidden"),
        a_class="clickable")}
    %else:
       ${state_button("hide", _("hide"),
         "return change_state(this, 'hide');", "<b>%s</b>" % _("hide"),
         a_class="clickable")}
    %endif
    </span>
  %endif

  <a href="/toolbar/comments/${thing._id36}" target="reddit_panel"
     title="${_('toggle the comments panel')}"
     onclick="toolbar.comments_pushed(this); return toolbar.panel_loadurl(this.href);"
     class="comments comments-button">${thing.comment_label}</a>
</span>

%if thing._fullname and thing.expanded:
  <script type="text/javascript">
    $(function() {
      toolbar.comments_pushed($('.comments-button'));
    });
  </script>
%endif
</%def>
