mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
Merge branch 'master' into purge-old-plugin-system
This commit is contained in:
@@ -88,6 +88,12 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
"name" -> trim(label("Repository name", text(required)))
|
||||
)(ForkRepositoryForm.apply)
|
||||
|
||||
case class AccountForm(accountName: String)
|
||||
|
||||
val accountForm = mapping(
|
||||
"account" -> trim(label("Group/User name", text(required, validAccountName)))
|
||||
)(AccountForm.apply)
|
||||
|
||||
/**
|
||||
* Displays user information.
|
||||
*/
|
||||
@@ -354,11 +360,31 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
||||
val loginAccount = context.loginAccount.get
|
||||
val loginUserName = loginAccount.userName
|
||||
val groups = getGroupsByUserName(loginUserName)
|
||||
groups match {
|
||||
case _: List[String] =>
|
||||
val managerPermissions = groups.map { group =>
|
||||
val members = getGroupMembers(group)
|
||||
context.loginAccount.exists(x => members.exists { member => member.userName == x.userName && member.isManager })
|
||||
}
|
||||
_root_.helper.html.forkrepository(
|
||||
repository,
|
||||
(groups zip managerPermissions).toMap
|
||||
)
|
||||
case _ => redirect(s"/${loginUserName}")
|
||||
}
|
||||
})
|
||||
|
||||
LockUtil.lock(s"${loginUserName}/${repository.name}"){
|
||||
if(repository.owner == loginUserName || getRepository(loginAccount.userName, repository.name, baseUrl).isDefined){
|
||||
post("/:owner/:repository/fork", accountForm)(readableUsersOnly { (form, repository) =>
|
||||
val loginAccount = context.loginAccount.get
|
||||
val loginUserName = loginAccount.userName
|
||||
val accountName = form.accountName
|
||||
|
||||
LockUtil.lock(s"${accountName}/${repository.name}"){
|
||||
if(getRepository(accountName, repository.name, baseUrl).isDefined ||
|
||||
(accountName != loginUserName && !getGroupsByUserName(loginUserName).contains(accountName))){
|
||||
// redirect to the repository if repository already exists
|
||||
redirect(s"/${loginUserName}/${repository.name}")
|
||||
redirect(s"/${accountName}/${repository.name}")
|
||||
} else {
|
||||
// Insert to the database at first
|
||||
val originUserName = repository.repository.originUserName.getOrElse(repository.owner)
|
||||
@@ -366,7 +392,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
|
||||
createRepository(
|
||||
repositoryName = repository.name,
|
||||
userName = loginUserName,
|
||||
userName = accountName,
|
||||
description = repository.repository.description,
|
||||
isPrivate = repository.repository.isPrivate,
|
||||
originRepositoryName = Some(originRepositoryName),
|
||||
@@ -376,22 +402,22 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
)
|
||||
|
||||
// Insert default labels
|
||||
insertDefaultLabels(loginUserName, repository.name)
|
||||
insertDefaultLabels(accountName, repository.name)
|
||||
|
||||
// clone repository actually
|
||||
JGitUtil.cloneRepository(
|
||||
getRepositoryDir(repository.owner, repository.name),
|
||||
getRepositoryDir(loginUserName, repository.name))
|
||||
getRepositoryDir(accountName, repository.name))
|
||||
|
||||
// Create Wiki repository
|
||||
JGitUtil.cloneRepository(
|
||||
getWikiRepositoryDir(repository.owner, repository.name),
|
||||
getWikiRepositoryDir(loginUserName, repository.name))
|
||||
getWikiRepositoryDir(accountName, repository.name))
|
||||
|
||||
// Record activity
|
||||
recordForkActivity(repository.owner, repository.name, loginUserName)
|
||||
recordForkActivity(repository.owner, repository.name, loginUserName, accountName)
|
||||
// redirect to the repository
|
||||
redirect(s"/${loginUserName}/${repository.name}")
|
||||
redirect(s"/${accountName}/${repository.name}")
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -431,4 +457,13 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
case None => Some("Key is invalid.")
|
||||
}
|
||||
}
|
||||
|
||||
private def validAccountName: Constraint = new Constraint(){
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||
getAccountByUserName(value) match {
|
||||
case Some(_) => None
|
||||
case None => Some("Invalid Group/User Account.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,6 +442,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
|
||||
repo.html.files(revision, repository,
|
||||
if(path == ".") Nil else path.split("/").toList, // current path
|
||||
context.loginAccount match {
|
||||
case None => List()
|
||||
case account: Option[model.Account] => getGroupsByUserName(account.get.userName)
|
||||
}, // groups of current user
|
||||
new JGitUtil.CommitInfo(lastModifiedCommit), // last modified commit
|
||||
files, readme, hasWritePermission(repository.owner, repository.name, context.loginAccount),
|
||||
flash.get("info"), flash.get("error"))
|
||||
|
||||
@@ -160,10 +160,10 @@ trait ActivityService {
|
||||
None,
|
||||
currentDate)
|
||||
|
||||
def recordForkActivity(userName: String, repositoryName: String, activityUserName: String)(implicit s: Session): Unit =
|
||||
def recordForkActivity(userName: String, repositoryName: String, activityUserName: String, forkedUserName: String)(implicit s: Session): Unit =
|
||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
||||
"fork",
|
||||
s"[user:${activityUserName}] forked [repo:${userName}/${repositoryName}] to [repo:${activityUserName}/${repositoryName}]",
|
||||
s"[user:${activityUserName}] forked [repo:${userName}/${repositoryName}] to [repo:${forkedUserName}/${repositoryName}]",
|
||||
None,
|
||||
currentDate)
|
||||
|
||||
|
||||
18
src/main/twirl/helper/forkrepository.scala.html
Normal file
18
src/main/twirl/helper/forkrepository.scala.html
Normal file
@@ -0,0 +1,18 @@
|
||||
@(repository: service.RepositoryService.RepositoryInfo,
|
||||
groupAndPerm: Map[String, Boolean])(implicit context: app.Context)
|
||||
@import context._
|
||||
@import view.helpers._
|
||||
<h2 class="facebox-header">Where should we fork this repository?</h2>
|
||||
<form action="@url(repository)/fork" id="fork" method="post">
|
||||
<div class="owner-select-grid">
|
||||
<div class="owner-select-target js-fork-owner-select-target enabled">@avatar(loginAccount.get.userName, 100)<span class="owner css-truncate" title="@@@loginAccount.get.userName">@@@loginAccount.get.userName</span></div>
|
||||
@for((groupName, isManager) <- groupAndPerm) {
|
||||
@if(isManager) {
|
||||
<div class="owner-select-target js-fork-owner-select-target enabled">@avatar(groupName, 100)<span class="owner css-truncate" title="@@@groupName">@@@groupName</span></div>
|
||||
} else {
|
||||
<div title="You don't have permission to fork here." class="owner-select-target js-fork-owner-select-target disabled">@avatar(groupName, 100)<span class="owner css-truncate" title="@@@groupName">@@@groupName</span></div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<input id="account" name="account" type="hidden" />
|
||||
</form>
|
||||
@@ -1,17 +1,17 @@
|
||||
@(repository: service.RepositoryService.RepositoryInfo, content: String, enableWikiLink: Boolean, enableRefsLink: Boolean, enableTaskList: Boolean, hasWritePermission: Boolean,
|
||||
style: String = "", placeholder: String = "Leave a comment", elastic: Boolean = false)(implicit context: app.Context)
|
||||
style: String = "", placeholder: String = "Leave a comment", elastic: Boolean = false, uid: Long = new java.util.Date().getTime())(implicit context: app.Context)
|
||||
@import context._
|
||||
@import view.helpers._
|
||||
<div class="tabbable">
|
||||
<ul class="nav nav-tabs" style="height: 37px;">
|
||||
<li class="active"><a href="#tab1" data-toggle="tab">Write</a></li>
|
||||
<li><a href="#tab2" data-toggle="tab" id="preview">Preview</a></li>
|
||||
<li class="active"><a href="#tab@uid" data-toggle="tab">Write</a></li>
|
||||
<li><a href="#tab@(uid+1)" data-toggle="tab" id="preview@uid">Preview</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="tab1">
|
||||
<div class="tab-pane active" id="tab@uid">
|
||||
<span id="error-content" class="error"></span>
|
||||
@textarea = {
|
||||
<textarea id="content" name="content"@if(style.nonEmpty){ style="@style"} placeholder="@placeholder">@content</textarea>
|
||||
<textarea id="content@uid" name="content"@if(style.nonEmpty){ style="@style"} placeholder="@placeholder">@content</textarea>
|
||||
}
|
||||
@if(enableWikiLink){
|
||||
@textarea
|
||||
@@ -19,8 +19,8 @@
|
||||
@helper.html.attached(repository.owner, repository.name)(textarea)
|
||||
}
|
||||
</div>
|
||||
<div class="tab-pane" id="tab2">
|
||||
<div class="markdown-body" id="preview-area">
|
||||
<div class="tab-pane" id="tab@(uid+1)">
|
||||
<div class="markdown-body" id="preview-area@uid">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -30,18 +30,18 @@
|
||||
<script>
|
||||
$(function(){
|
||||
@if(elastic){
|
||||
$('#content').elastic();
|
||||
$('#content@uid').elastic();
|
||||
}
|
||||
|
||||
$('#preview').click(function(){
|
||||
$(this).closest('#preview-area').html('<img src="@assets/common/images/indicator.gif"> Previewing...');
|
||||
$('#preview@uid').click(function(){
|
||||
$('#preview-area@uid').html('<img src="@assets/common/images/indicator.gif"> Previewing...');
|
||||
$.post('@url(repository)/_preview', {
|
||||
content : $('#content').val(),
|
||||
content : $('#content@uid').val(),
|
||||
enableWikiLink : @enableWikiLink,
|
||||
enableRefsLink : @enableRefsLink,
|
||||
enableTaskList : @enableTaskList
|
||||
}, function(data){
|
||||
$('#preview-area').html(data);
|
||||
$('#preview-area@uid').html(data);
|
||||
prettyPrint();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<link href="@assets/vendors/datepicker/css/datepicker.css" rel="stylesheet">
|
||||
<link href="@assets/vendors/colorpicker/css/bootstrap-colorpicker.css" rel="stylesheet">
|
||||
<link href="@assets/vendors/google-code-prettify/prettify.css" type="text/css" rel="stylesheet"/>
|
||||
<link href="@assets/vendors/facebox/facebox.css" rel="stylesheet"/>
|
||||
<link href="@assets/common/css/gitbucket.css" rel="stylesheet">
|
||||
<script src="@assets/vendors/jquery/jquery-1.9.1.js"></script>
|
||||
<script src="@assets/vendors/dropzone/dropzone.js"></script>
|
||||
@@ -29,6 +30,7 @@
|
||||
<script src="@assets/vendors/google-code-prettify/prettify.js"></script>
|
||||
<script src="@assets/vendors/zclip/ZeroClipboard.min.js"></script>
|
||||
<script src="@assets/vendors/elastic/jquery.elastic.source.js"></script>
|
||||
<script src="@assets/vendors/facebox/facebox.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<form id="search" action="@path/search" method="POST">
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
repository: service.RepositoryService.RepositoryInfo,
|
||||
id: Option[String] = None,
|
||||
expand: Boolean = false,
|
||||
isNoGroup: Boolean = true,
|
||||
info: Option[Any] = None,
|
||||
error: Option[Any] = None)(body: Html)(implicit context: app.Context)
|
||||
@import context._
|
||||
@@ -38,7 +39,15 @@
|
||||
@if(repository.commitCount > 0){
|
||||
<div class="pull-right">
|
||||
<div class="input-prepend">
|
||||
<a href="@path/@repository.owner/@repository.name/fork" class="btn btn-small" style="margin-bottom: 10px;">Fork</a>
|
||||
@if(loginAccount.isEmpty){
|
||||
<a title="You must be signed in to fork a repository" href="@path/signin" class="btn btn-small" style="margin-bottom: 10px;">Fork</a>
|
||||
} else {
|
||||
@if(isNoGroup) {
|
||||
<a href="@path/@repository.owner/@repository.name/fork" class="btn btn-small" style="margin-bottom: 10px;" data-account="@loginAccount.get.userName">Fork</a>
|
||||
} else {
|
||||
<a href="@path/@repository.owner/@repository.name/fork" class="btn btn-small" rel="facebox" style="margin-bottom: 10px;">Fork</a>
|
||||
}
|
||||
}
|
||||
<span class="add-on count"><a href="@url(repository)/network/members">@repository.forkedCount</a></span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -170,6 +179,33 @@ $(function(){
|
||||
$(target).children('img.menu-icon' ).css('display', 'inline');
|
||||
});
|
||||
|
||||
$('a[rel*=facebox]').facebox();
|
||||
|
||||
$(document).on("click", ".js-fork-owner-select-target", function() {
|
||||
if (!$(this).hasClass("disabled")) {
|
||||
var account = $(this).text().replace("@@", "");
|
||||
$("#account").val(account);
|
||||
$("#fork").submit();
|
||||
}
|
||||
});
|
||||
|
||||
@if(loginAccount.isDefined){
|
||||
$(document).on("click", "a[data-account]", function(e) {
|
||||
e.preventDefault();
|
||||
var form = $('<form/>', {
|
||||
action: $(this).attr('href'),
|
||||
method: "post"
|
||||
});
|
||||
var account = $('<input/>', {
|
||||
type: "hidden",
|
||||
name: "account",
|
||||
value: $(this).data('account')
|
||||
});
|
||||
form.append(account);
|
||||
form.submit();
|
||||
});
|
||||
}
|
||||
|
||||
@if(settings.ssh && loginAccount.isDefined){
|
||||
$('#repository-url-http').click(function(){
|
||||
$('#repository-url-proto').text('HTTP');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@(branch: String,
|
||||
repository: service.RepositoryService.RepositoryInfo,
|
||||
pathList: List[String],
|
||||
groupNames: List[String],
|
||||
latestCommit: util.JGitUtil.CommitInfo,
|
||||
files: List[util.JGitUtil.FileInfo],
|
||||
readme: Option[(List[String], String)],
|
||||
@@ -10,7 +11,7 @@
|
||||
@import context._
|
||||
@import view.helpers._
|
||||
@html.main(s"${repository.owner}/${repository.name}", Some(repository)) {
|
||||
@html.menu("code", repository, Some(branch), pathList.isEmpty, info, error){
|
||||
@html.menu("code", repository, Some(branch), pathList.isEmpty, groupNames.isEmpty, info, error){
|
||||
<div class="head">
|
||||
@helper.html.branchcontrol(
|
||||
branch,
|
||||
|
||||
BIN
src/main/webapp/assets/vendors/facebox/closelabel.png
vendored
Normal file
BIN
src/main/webapp/assets/vendors/facebox/closelabel.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 168 B |
142
src/main/webapp/assets/vendors/facebox/facebox.css
vendored
Normal file
142
src/main/webapp/assets/vendors/facebox/facebox.css
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
#facebox {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 100;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
|
||||
#facebox .popup{
|
||||
position:relative;
|
||||
border:3px solid rgba(0,0,0,0);
|
||||
-webkit-border-radius:5px;
|
||||
-moz-border-radius:5px;
|
||||
border-radius:5px;
|
||||
-webkit-box-shadow:0 0 18px rgba(0,0,0,0.4);
|
||||
-moz-box-shadow:0 0 18px rgba(0,0,0,0.4);
|
||||
box-shadow:0 0 18px rgba(0,0,0,0.4);
|
||||
}
|
||||
|
||||
#facebox .content {
|
||||
overflow: hidden;
|
||||
width: 455px;
|
||||
padding: 10px;
|
||||
background: #fff;
|
||||
-webkit-border-radius:4px;
|
||||
-moz-border-radius:4px;
|
||||
border-radius:4px;
|
||||
}
|
||||
|
||||
#facebox .content > p:first-child{
|
||||
margin-top:0;
|
||||
}
|
||||
#facebox .content > p:last-child{
|
||||
margin-bottom:0;
|
||||
}
|
||||
|
||||
#facebox .close{
|
||||
position:absolute;
|
||||
top:5px;
|
||||
right:5px;
|
||||
padding:2px;
|
||||
background:#fff;
|
||||
}
|
||||
#facebox .close img{
|
||||
opacity:0.3;
|
||||
}
|
||||
#facebox .close:hover img{
|
||||
opacity:1.0;
|
||||
}
|
||||
|
||||
#facebox .loading {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#facebox .image {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#facebox img {
|
||||
border: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#facebox_overlay {
|
||||
position: fixed;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
height:100%;
|
||||
width:100%;
|
||||
}
|
||||
|
||||
.facebox_hide {
|
||||
z-index:-100;
|
||||
}
|
||||
|
||||
.facebox_overlayBG {
|
||||
background-color: #000;
|
||||
z-index: 99;
|
||||
}
|
||||
|
||||
.facebox-header {
|
||||
margin: -15px -15px 15px;
|
||||
padding: 15px;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
font-size: 18px;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.owner-select-grid {
|
||||
margin-left: -8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.owner-select-target {
|
||||
float: left;
|
||||
padding: 10px;
|
||||
margin: 0 8px 10px;
|
||||
text-align: center;
|
||||
background-color: #f2f2f2;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.owner-select-target.enabled {
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.owner-select-target.disabled {
|
||||
color: #999;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.owner-select-grid .avatar {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
line-height: 1;
|
||||
vertical-align: middle;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.owner-select-target.enabled .avatar {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.owner-select-target.disabled .avatar {
|
||||
margin-bottom: 9px;
|
||||
opacity: 0.3;
|
||||
}
|
||||
|
||||
.css-truncate {
|
||||
display: inline-block;
|
||||
max-width: 125px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.owner-select-target .css-truncate {
|
||||
max-width: 90px;
|
||||
}
|
||||
313
src/main/webapp/assets/vendors/facebox/facebox.js
vendored
Normal file
313
src/main/webapp/assets/vendors/facebox/facebox.js
vendored
Normal file
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
* Facebox (for jQuery)
|
||||
* version: 1.3
|
||||
* @requires jQuery v1.2 or later
|
||||
* @homepage https://github.com/defunkt/facebox
|
||||
*
|
||||
* Licensed under the MIT:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* Copyright Forever Chris Wanstrath, Kyle Neath
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* jQuery(document).ready(function() {
|
||||
* jQuery('a[rel*=facebox]').facebox()
|
||||
* })
|
||||
*
|
||||
* <a href="#terms" rel="facebox">Terms</a>
|
||||
* Loads the #terms div in the box
|
||||
*
|
||||
* <a href="terms.html" rel="facebox">Terms</a>
|
||||
* Loads the terms.html page in the box
|
||||
*
|
||||
* <a href="terms.png" rel="facebox">Terms</a>
|
||||
* Loads the terms.png image in the box
|
||||
*
|
||||
*
|
||||
* You can also use it programmatically:
|
||||
*
|
||||
* jQuery.facebox('some html')
|
||||
* jQuery.facebox('some html', 'my-groovy-style')
|
||||
*
|
||||
* The above will open a facebox with "some html" as the content.
|
||||
*
|
||||
* jQuery.facebox(function($) {
|
||||
* $.get('blah.html', function(data) { $.facebox(data) })
|
||||
* })
|
||||
*
|
||||
* The above will show a loading screen before the passed function is called,
|
||||
* allowing for a better ajaxy experience.
|
||||
*
|
||||
* The facebox function can also display an ajax page, an image, or the contents of a div:
|
||||
*
|
||||
* jQuery.facebox({ ajax: 'remote.html' })
|
||||
* jQuery.facebox({ ajax: 'remote.html' }, 'my-groovy-style')
|
||||
* jQuery.facebox({ image: 'stairs.jpg' })
|
||||
* jQuery.facebox({ image: 'stairs.jpg' }, 'my-groovy-style')
|
||||
* jQuery.facebox({ div: '#box' })
|
||||
* jQuery.facebox({ div: '#box' }, 'my-groovy-style')
|
||||
*
|
||||
* Want to close the facebox? Trigger the 'close.facebox' document event:
|
||||
*
|
||||
* jQuery(document).trigger('close.facebox')
|
||||
*
|
||||
* Facebox also has a bunch of other hooks:
|
||||
*
|
||||
* loading.facebox
|
||||
* beforeReveal.facebox
|
||||
* reveal.facebox (aliased as 'afterReveal.facebox')
|
||||
* init.facebox
|
||||
* afterClose.facebox
|
||||
*
|
||||
* Simply bind a function to any of these hooks:
|
||||
*
|
||||
* $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... })
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
$.facebox = function(data, klass) {
|
||||
$.facebox.loading(data.settings || [])
|
||||
|
||||
if (data.ajax) fillFaceboxFromAjax(data.ajax, klass)
|
||||
else if (data.image) fillFaceboxFromImage(data.image, klass)
|
||||
else if (data.div) fillFaceboxFromHref(data.div, klass)
|
||||
else if ($.isFunction(data)) data.call($)
|
||||
else $.facebox.reveal(data, klass)
|
||||
}
|
||||
|
||||
/*
|
||||
* Public, $.facebox methods
|
||||
*/
|
||||
|
||||
$.extend($.facebox, {
|
||||
settings: {
|
||||
opacity : 0.2,
|
||||
overlay : true,
|
||||
loadingImage : '/assets/vendors/facebox/loading.gif',
|
||||
closeImage : '/assets/vendors/facebox/closelabel.png',
|
||||
imageTypes : [ 'png', 'jpg', 'jpeg', 'gif' ],
|
||||
faceboxHtml : '\
|
||||
<div id="facebox" style="display:none;"> \
|
||||
<div class="popup"> \
|
||||
<div class="content"> \
|
||||
</div> \
|
||||
<a href="#" class="close"></a> \
|
||||
</div> \
|
||||
</div>'
|
||||
},
|
||||
|
||||
loading: function() {
|
||||
init()
|
||||
if ($('#facebox .loading').length == 1) return true
|
||||
showOverlay()
|
||||
|
||||
$('#facebox .content').empty().
|
||||
append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>')
|
||||
|
||||
$('#facebox').show().css({
|
||||
top: getPageScroll()[1] + (getPageHeight() / 10),
|
||||
left: $(window).width() / 2 - ($('#facebox .popup').outerWidth() / 2)
|
||||
})
|
||||
|
||||
$(document).bind('keydown.facebox', function(e) {
|
||||
if (e.keyCode == 27) $.facebox.close()
|
||||
return true
|
||||
})
|
||||
$(document).trigger('loading.facebox')
|
||||
},
|
||||
|
||||
reveal: function(data, klass) {
|
||||
$(document).trigger('beforeReveal.facebox')
|
||||
if (klass) $('#facebox .content').addClass(klass)
|
||||
$('#facebox .content').empty().append(data)
|
||||
$('#facebox .popup').children().fadeIn('normal')
|
||||
$('#facebox').css('left', $(window).width() / 2 - ($('#facebox .popup').outerWidth() / 2))
|
||||
$(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
|
||||
},
|
||||
|
||||
close: function() {
|
||||
$(document).trigger('close.facebox')
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
* Public, $.fn methods
|
||||
*/
|
||||
|
||||
$.fn.facebox = function(settings) {
|
||||
if ($(this).length == 0) return
|
||||
|
||||
init(settings)
|
||||
|
||||
function clickHandler() {
|
||||
$.facebox.loading(true)
|
||||
|
||||
// support for rel="facebox.inline_popup" syntax, to add a class
|
||||
// also supports deprecated "facebox[.inline_popup]" syntax
|
||||
var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
|
||||
if (klass) klass = klass[1]
|
||||
|
||||
fillFaceboxFromHref(this.href, klass)
|
||||
return false
|
||||
}
|
||||
|
||||
return this.bind('click.facebox', clickHandler)
|
||||
}
|
||||
|
||||
/*
|
||||
* Private methods
|
||||
*/
|
||||
|
||||
// called one time to setup facebox on this page
|
||||
function init(settings) {
|
||||
if ($.facebox.settings.inited) return true
|
||||
else $.facebox.settings.inited = true
|
||||
|
||||
$(document).trigger('init.facebox')
|
||||
makeCompatible()
|
||||
|
||||
var imageTypes = $.facebox.settings.imageTypes.join('|')
|
||||
$.facebox.settings.imageTypesRegexp = new RegExp('\\.(' + imageTypes + ')(\\?.*)?$', 'i')
|
||||
|
||||
if (settings) $.extend($.facebox.settings, settings)
|
||||
$('body').append($.facebox.settings.faceboxHtml)
|
||||
|
||||
var preload = [ new Image(), new Image() ]
|
||||
preload[0].src = $.facebox.settings.closeImage
|
||||
preload[1].src = $.facebox.settings.loadingImage
|
||||
|
||||
$('#facebox').find('.b:first, .bl').each(function() {
|
||||
preload.push(new Image())
|
||||
preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
|
||||
})
|
||||
|
||||
$('#facebox .close')
|
||||
.click($.facebox.close)
|
||||
.append('<img src="'
|
||||
+ $.facebox.settings.closeImage
|
||||
+ '" class="close_image" title="close">')
|
||||
}
|
||||
|
||||
// getPageScroll() by quirksmode.com
|
||||
function getPageScroll() {
|
||||
var xScroll, yScroll;
|
||||
if (self.pageYOffset) {
|
||||
yScroll = self.pageYOffset;
|
||||
xScroll = self.pageXOffset;
|
||||
} else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
|
||||
yScroll = document.documentElement.scrollTop;
|
||||
xScroll = document.documentElement.scrollLeft;
|
||||
} else if (document.body) {// all other Explorers
|
||||
yScroll = document.body.scrollTop;
|
||||
xScroll = document.body.scrollLeft;
|
||||
}
|
||||
return new Array(xScroll,yScroll)
|
||||
}
|
||||
|
||||
// Adapted from getPageSize() by quirksmode.com
|
||||
function getPageHeight() {
|
||||
var windowHeight
|
||||
if (self.innerHeight) { // all except Explorer
|
||||
windowHeight = self.innerHeight;
|
||||
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
|
||||
windowHeight = document.documentElement.clientHeight;
|
||||
} else if (document.body) { // other Explorers
|
||||
windowHeight = document.body.clientHeight;
|
||||
}
|
||||
return windowHeight
|
||||
}
|
||||
|
||||
// Backwards compatibility
|
||||
function makeCompatible() {
|
||||
var $s = $.facebox.settings
|
||||
|
||||
$s.loadingImage = $s.loading_image || $s.loadingImage
|
||||
$s.closeImage = $s.close_image || $s.closeImage
|
||||
$s.imageTypes = $s.image_types || $s.imageTypes
|
||||
$s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
|
||||
}
|
||||
|
||||
// Figures out what you want to display and displays it
|
||||
// formats are:
|
||||
// div: #id
|
||||
// image: blah.extension
|
||||
// ajax: anything else
|
||||
function fillFaceboxFromHref(href, klass) {
|
||||
// div
|
||||
if (href.match(/#/)) {
|
||||
var url = window.location.href.split('#')[0]
|
||||
var target = href.replace(url,'')
|
||||
if (target == '#') return
|
||||
$.facebox.reveal($(target).html(), klass)
|
||||
|
||||
// image
|
||||
} else if (href.match($.facebox.settings.imageTypesRegexp)) {
|
||||
fillFaceboxFromImage(href, klass)
|
||||
// ajax
|
||||
} else {
|
||||
fillFaceboxFromAjax(href, klass)
|
||||
}
|
||||
}
|
||||
|
||||
function fillFaceboxFromImage(href, klass) {
|
||||
var image = new Image()
|
||||
image.onload = function() {
|
||||
$.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
|
||||
}
|
||||
image.src = href
|
||||
}
|
||||
|
||||
function fillFaceboxFromAjax(href, klass) {
|
||||
$.facebox.jqxhr = $.get(href, function(data) { $.facebox.reveal(data, klass) })
|
||||
}
|
||||
|
||||
function skipOverlay() {
|
||||
return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null
|
||||
}
|
||||
|
||||
function showOverlay() {
|
||||
if (skipOverlay()) return
|
||||
|
||||
if ($('#facebox_overlay').length == 0)
|
||||
$("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')
|
||||
|
||||
$('#facebox_overlay').hide().addClass("facebox_overlayBG")
|
||||
.css('opacity', $.facebox.settings.opacity)
|
||||
.click(function() { $(document).trigger('close.facebox') })
|
||||
.fadeIn(200)
|
||||
return false
|
||||
}
|
||||
|
||||
function hideOverlay() {
|
||||
if (skipOverlay()) return
|
||||
|
||||
$('#facebox_overlay').fadeOut(200, function(){
|
||||
$("#facebox_overlay").removeClass("facebox_overlayBG")
|
||||
$("#facebox_overlay").addClass("facebox_hide")
|
||||
$("#facebox_overlay").remove()
|
||||
})
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/*
|
||||
* Bindings
|
||||
*/
|
||||
|
||||
$(document).bind('close.facebox', function() {
|
||||
if ($.facebox.jqxhr) {
|
||||
$.facebox.jqxhr.abort()
|
||||
$.facebox.jqxhr = null
|
||||
}
|
||||
$(document).unbind('keydown.facebox')
|
||||
$('#facebox').fadeOut(function() {
|
||||
$('#facebox .content').removeClass().addClass('content')
|
||||
$('#facebox .loading').remove()
|
||||
$(document).trigger('afterClose.facebox')
|
||||
})
|
||||
hideOverlay()
|
||||
})
|
||||
|
||||
})(jQuery);
|
||||
BIN
src/main/webapp/assets/vendors/facebox/loading.gif
vendored
Normal file
BIN
src/main/webapp/assets/vendors/facebox/loading.gif
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
Reference in New Issue
Block a user