Pass snapshot formats as requirejs config rather than globally
Pass snapshot formats as requirejs config rather than globally

  /*
  * GitPHP snapshot formats
  *
  * Passes snapshot formats from config to other modules
  *
  * @author Christopher Han <xiphux@gmail.com>
  * @copyright Copyright (c) 2012 Christopher Han
  * @package GitPHP
  * @subpackage Javascript
  */
 
  define(['module'],
  function (module) {
  return module.config().formats || null;
  }
  );
 
/* /*
* GitPHP Javascript snapshot tooltip * GitPHP Javascript snapshot tooltip
* *
* Displays choices of snapshot format in a tooltip * Displays choices of snapshot format in a tooltip
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2011 Christopher Han * @copyright Copyright (c) 2011 Christopher Han
* @package GitPHP * @package GitPHP
* @subpackage Javascript * @subpackage Javascript
*/ */
   
define(["jquery"], define(["jquery", 'modules/snapshotformats'],
function($) { function($, formats) {
function buildTipContent(href) { function buildTipContent(href) {
var content = '<div>' + GitPHP.Resources.Snapshot + ': '; var content = '<div>' + GitPHP.Resources.Snapshot + ': ';
var first = true; var first = true;
var formats = GitPHP.Snapshot.Formats  
var cleanurl = href.indexOf('/snapshot') != -1; var cleanurl = href.indexOf('/snapshot') != -1;
for (var type in formats) { for (var type in formats) {
if (formats.hasOwnProperty(type)) { if (formats.hasOwnProperty(type)) {
if (!first) { if (!first) {
content += ' | '; content += ' | ';
} }
if (cleanurl) { if (cleanurl) {
var newhref = href.replace("/snapshot", "/" + type); var newhref = href.replace("/snapshot", "/" + type);
content += '<a href="' + newhref + '">' + formats[type] + '</a>'; content += '<a href="' + newhref + '">' + formats[type] + '</a>';
} else { } else {
content += '<a href="' + href + '&fmt=' + type + '">' + formats[type] + '</a>'; content += '<a href="' + href + '&fmt=' + type + '">' + formats[type] + '</a>';
} }
first = false; first = false;
} }
} }
content += '</div>'; content += '</div>';
return content; return content;
} }
   
function buildTipConfig(content) { function buildTipConfig(content) {
return { return {
content: { content: {
text: content text: content
}, },
show: { show: {
event: 'click' event: 'click'
}, },
hide: { hide: {
fixed: true, fixed: true,
delay: 150 delay: 150
}, },
style: { style: {
classes: 'ui-tooltip-gitphp ui-tooltip-light ui-tooltip-shadow' classes: 'ui-tooltip-gitphp ui-tooltip-light ui-tooltip-shadow'
}, },
position: { position: {
viewport: $(window) viewport: $(window)
} }
} }
} }
   
return function(elements) { return function(elements) {
if (elements && (elements.size() > 0)) { if (elements && (elements.size() > 0)) {
require(['qtip'], function() { require(['qtip'], function() {
elements.each(function(){ elements.each(function(){
var jThis = $(this); var jThis = $(this);
var href = jThis.attr('href'); var href = jThis.attr('href');
var content = buildTipContent(href); var content = buildTipContent(href);
var config = buildTipConfig(content); var config = buildTipConfig(content);
jThis.qtip(config); jThis.qtip(config);
jThis.click(function() { return false; }); jThis.click(function() { return false; });
}); });
}); });
} }
} }
} }
); );
   
{* {*
* JSConst * JSConst
* *
* Javascript constants template * Javascript constants template
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2011 Christopher Han * @copyright Copyright (c) 2011 Christopher Han
* @package GitPHP * @package GitPHP
* @subpackage Template * @subpackage Template
*} *}
<script type="text/javascript"> <script type="text/javascript">
   
var GitPHP = GitPHP || {ldelim}{rdelim}; var GitPHP = GitPHP || {ldelim}{rdelim};
   
GitPHP.Resources = {ldelim} GitPHP.Resources = {ldelim}
Loading: "{t escape='js'}Loading…{/t}", Loading: "{t escape='js'}Loading…{/t}",
LoadingBlameData: "{t escape='js'}Loading blame data…{/t}", LoadingBlameData: "{t escape='js'}Loading blame data…{/t}",
Snapshot: "{t escape='js'}snapshot{/t}", Snapshot: "{t escape='js'}snapshot{/t}",
NoMatchesFound: '{t escape=no}No matches found for "%1"{/t}' NoMatchesFound: '{t escape=no}No matches found for "%1"{/t}'
{rdelim}; {rdelim};
   
GitPHP.Snapshot = {ldelim}  
Formats: {ldelim}{foreach from=$snapshotformats key=format item=extension name=formats}"{$format}": "{$extension}"{if !$smarty.foreach.formats.last},{/if}{/foreach}{rdelim}  
{rdelim}  
   
GitPHP.BaseUrl = '{$baseurl}/'; GitPHP.BaseUrl = '{$baseurl}/';
{if $project} {if $project}
GitPHP.Project = '{$project->GetProject()}'; GitPHP.Project = '{$project->GetProject()}';
{/if} {/if}
</script> </script>
   
{* {*
* Main * Main
* *
* Main page template * Main page template
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2011 Christopher Han * @copyright Copyright (c) 2011 Christopher Han
* @packge GitPHP * @packge GitPHP
* @subpackage Template * @subpackage Template
*} *}
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<!-- gitphp web interface {$version}, (C) 2006-2011 Christopher Han <xiphux@gmail.com> --> <!-- gitphp web interface {$version}, (C) 2006-2011 Christopher Han <xiphux@gmail.com> -->
<head> <head>
<title> <title>
{block name=title} {block name=title}
{$pagetitle} {$pagetitle}
{/block} {/block}
</title> </title>
{block name=feeds} {block name=feeds}
{/block} {/block}
{block name=links} {block name=links}
{/block} {/block}
{if file_exists('css/gitphp.min.css')} {if file_exists('css/gitphp.min.css')}
<link rel="stylesheet" href="{$baseurl}/css/gitphp.min.css" type="text/css" /> <link rel="stylesheet" href="{$baseurl}/css/gitphp.min.css" type="text/css" />
{else} {else}
<link rel="stylesheet" href="{$baseurl}/css/gitphp.css" type="text/css" /> <link rel="stylesheet" href="{$baseurl}/css/gitphp.css" type="text/css" />
{/if} {/if}
{if file_exists("css/$stylesheet.min.css")} {if file_exists("css/$stylesheet.min.css")}
<link rel="stylesheet" href="{$baseurl}/css/{$stylesheet}.min.css" type="text/css" /> <link rel="stylesheet" href="{$baseurl}/css/{$stylesheet}.min.css" type="text/css" />
{else} {else}
<link rel="stylesheet" href="{$baseurl}/css/{$stylesheet}.css" type="text/css" /> <link rel="stylesheet" href="{$baseurl}/css/{$stylesheet}.css" type="text/css" />
{/if} {/if}
<link rel="stylesheet" href="{$baseurl}/css/ext/jquery.qtip.min.css" type="text/css" /> <link rel="stylesheet" href="{$baseurl}/css/ext/jquery.qtip.min.css" type="text/css" />
{block name=css} {block name=css}
{/block} {/block}
{if $javascript} {if $javascript}
{include file='jsconst.tpl'} {include file='jsconst.tpl'}
<script type="text/javascript"> <script type="text/javascript">
var require = {ldelim} var require = {ldelim}
baseUrl: GitPHP.BaseUrl + 'js', baseUrl: GitPHP.BaseUrl + 'js',
paths: {ldelim} paths: {ldelim}
jquery: [ jquery: [
{if $googlejs} {if $googlejs}
'https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min', 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min',
{/if} {/if}
'ext/jquery-1.8.1.min' 'ext/jquery-1.8.1.min'
], ],
d3: 'ext/d3.v2.min', d3: 'ext/d3.v2.min',
qtip: 'ext/jquery.qtip.min' qtip: 'ext/jquery.qtip.min'
  {rdelim},
  config: {ldelim}
  'modules/snapshotformats': {ldelim}
  formats: {ldelim}{foreach from=$snapshotformats key=format item=extension name=formats}"{$format}": "{$extension}"{if !$smarty.foreach.formats.last},{/if}{/foreach}{rdelim}
  {rdelim}
{rdelim} {rdelim}
{rdelim}; {rdelim};
{block name=javascript} {block name=javascript}
{if file_exists('js/common.min.js')} {if file_exists('js/common.min.js')}
require.paths.common = 'common.min'; require.paths.common = 'common.min';
{/if} {/if}
require.deps = ['common']; require.deps = ['common'];
{/block} {/block}
</script> </script>
<script type="text/javascript" src="{$baseurl}/js/ext/require.js"></script> <script type="text/javascript" src="{$baseurl}/js/ext/require.js"></script>
{/if} {/if}
</head> </head>
<body> <body>
<div class="page_header"> <div class="page_header">
<a href="http://git-scm.com" title="git homepage" rel="nofollow"> <a href="http://git-scm.com" title="git homepage" rel="nofollow">
<img src="{$baseurl}/images/git-logo.png" width="72" height="27" alt="git" class="logo" /> <img src="{$baseurl}/images/git-logo.png" width="72" height="27" alt="git" class="logo" />
</a> </a>
{if $supportedlocales} {if $supportedlocales}
<div class="lang_select"> <div class="lang_select">
<form action="{$requesturl}" method="get" id="frmLangSelect"> <form action="{$requesturl}" method="get" id="frmLangSelect">
<div> <div>
{foreach from=$requestvars key=var item=val} {foreach from=$requestvars key=var item=val}
{if $var != "l"} {if $var != "l"}
<input type="hidden" name="{$var}" value="{$val|escape}" /> <input type="hidden" name="{$var}" value="{$val|escape}" />
{/if} {/if}
{/foreach} {/foreach}
<label for="selLang">{t}language:{/t}</label> <label for="selLang">{t}language:{/t}</label>
<select name="l" id="selLang"> <select name="l" id="selLang">
{foreach from=$supportedlocales key=locale item=language} {foreach from=$supportedlocales key=locale item=language}
<option {if $locale == $currentlocale}selected="selected"{/if} value="{$locale}">{if $language}{$language} ({$locale}){else}{$locale}{/if}</option> <option {if $locale == $currentlocale}selected="selected"{/if} value="{$locale}">{if $language}{$language} ({$locale}){else}{$locale}{/if}</option>
{/foreach} {/foreach}
</select> </select>
<input type="submit" value="{t}set{/t}" id="btnLangSet" /> <input type="submit" value="{t}set{/t}" id="btnLangSet" />
</div> </div>
</form> </form>
</div> </div>
{/if} {/if}
{block name=header} {block name=header}
<a href="{geturl}">{if $homelink}{$homelink}{else}{t}projects{/t}{/if}</a> / <a href="{geturl}">{if $homelink}{$homelink}{else}{t}projects{/t}{/if}</a> /
{/block} {/block}
</div> </div>
{block name=main} {block name=main}
   
{/block} {/block}
<div class="page_footer"> <div class="page_footer">
{block name=footer} {block name=footer}
{/block} {/block}
</div> </div>
<div class="attr_footer"> <div class="attr_footer">
<a href="http://www.gitphp.org/" target="_blank">GitPHP by Chris Han</a> <a href="http://www.gitphp.org/" target="_blank">GitPHP by Chris Han</a>
</div> </div>
</body> </body>
</html> </html>
   
comments