2014-11-25 14:17:04 +08:00
//= require_directory ./rateable
2015-03-04 15:32:00 +08:00
//= require jquery.min
//= require jquery.infinitescroll
2014-11-25 14:17:04 +08:00
/ * R e d m i n e - p r o j e c t m a n a g e m e n t s o f t w a r e
Copyright ( C ) 2006 - 2013 Jean - Philippe Lang * /
function cleanArray ( actual ) {
var newArray = new Array ( ) ;
for ( var i = 0 ; i < actual . length ; i ++ ) {
if ( actual [ i ] ) {
newArray . push ( actual [ i ] ) ;
}
}
return newArray ;
}
function checkAll ( id , checked ) {
if ( checked ) {
$ ( '#' + id ) . find ( 'input[type=checkbox]' ) . attr ( 'checked' , true ) ;
} else {
$ ( '#' + id ) . find ( 'input[type=checkbox]' ) . removeAttr ( 'checked' ) ;
}
}
function toggleCheckboxesBySelector ( selector ) {
var all _checked = true ;
$ ( selector ) . each ( function ( index ) {
if ( ! $ ( this ) . is ( ':checked' ) ) { all _checked = false ; }
} ) ;
$ ( selector ) . attr ( 'checked' , ! all _checked ) ;
}
function showAndScrollTo ( id , focus ) {
$ ( '#' + id ) . show ( ) ;
if ( focus !== null ) {
$ ( '#' + focus ) . focus ( ) ;
}
$ ( 'html, body' ) . animate ( { scrollTop : $ ( '#' + id ) . offset ( ) . top } , 400 ) ;
}
function toggleRowGroup ( el ) {
var tr = $ ( el ) . parents ( 'tr' ) . first ( ) ;
var n = tr . next ( ) ;
tr . toggleClass ( 'open' ) ;
while ( n . length && ! n . hasClass ( 'group' ) ) {
n . toggle ( ) ;
n = n . next ( 'tr' ) ;
}
}
function collapseAllRowGroups ( el ) {
var tbody = $ ( el ) . parents ( 'tbody' ) . first ( ) ;
tbody . children ( 'tr' ) . each ( function ( index ) {
if ( $ ( this ) . hasClass ( 'group' ) ) {
$ ( this ) . removeClass ( 'open' ) ;
} else {
$ ( this ) . hide ( ) ;
}
} ) ;
}
function expandAllRowGroups ( el ) {
var tbody = $ ( el ) . parents ( 'tbody' ) . first ( ) ;
tbody . children ( 'tr' ) . each ( function ( index ) {
if ( $ ( this ) . hasClass ( 'group' ) ) {
$ ( this ) . addClass ( 'open' ) ;
} else {
$ ( this ) . show ( ) ;
}
} ) ;
}
function toggleAllRowGroups ( el ) {
var tr = $ ( el ) . parents ( 'tr' ) . first ( ) ;
if ( tr . hasClass ( 'open' ) ) {
collapseAllRowGroups ( el ) ;
} else {
expandAllRowGroups ( el ) ;
}
}
function toggleFieldset ( el ) {
var fieldset = $ ( el ) . parents ( 'fieldset' ) . first ( ) ;
fieldset . toggleClass ( 'collapsed' ) ;
fieldset . children ( 'div' ) . toggle ( ) ;
}
function hideFieldset ( el ) {
var fieldset = $ ( el ) . parents ( 'fieldset' ) . first ( ) ;
fieldset . toggleClass ( 'collapsed' ) ;
fieldset . children ( 'div' ) . hide ( ) ;
}
function initFilters ( ) {
$ ( '#add_filter_select' ) . change ( function ( ) {
addFilter ( $ ( this ) . val ( ) , '' , [ ] ) ;
} ) ;
$ ( '#filters-table td.field input[type=checkbox]' ) . each ( function ( ) {
toggleFilter ( $ ( this ) . val ( ) ) ;
} ) ;
$ ( '#filters-table td.field input[type=checkbox]' ) . live ( 'click' , function ( ) {
toggleFilter ( $ ( this ) . val ( ) ) ;
} ) ;
$ ( '#filters-table .toggle-multiselect' ) . live ( 'click' , function ( ) {
toggleMultiSelect ( $ ( this ) . siblings ( 'select' ) ) ;
} ) ;
$ ( '#filters-table input[type=text]' ) . live ( 'keypress' , function ( e ) {
if ( e . keyCode == 13 ) submit _query _form ( "query_form" ) ;
} ) ;
}
function addFilter ( field , operator , values ) {
var fieldId = field . replace ( '.' , '_' ) ;
var tr = $ ( '#tr_' + fieldId ) ;
if ( tr . length > 0 ) {
tr . show ( ) ;
} else {
buildFilterRow ( field , operator , values ) ;
}
$ ( '#cb_' + fieldId ) . attr ( 'checked' , true ) ;
toggleFilter ( field ) ;
$ ( '#add_filter_select' ) . val ( '' ) . children ( 'option' ) . each ( function ( ) {
if ( $ ( this ) . attr ( 'value' ) == field ) {
$ ( this ) . attr ( 'disabled' , true ) ;
}
} ) ;
}
function buildFilterRow ( field , operator , values ) {
var fieldId = field . replace ( '.' , '_' ) ;
var filterTable = $ ( "#filters-table" ) ;
var filterOptions = availableFilters [ field ] ;
var operators = operatorByType [ filterOptions [ 'type' ] ] ;
var filterValues = filterOptions [ 'values' ] ;
var i , select ;
var tr = $ ( '<tr class="filter">' ) . attr ( 'id' , 'tr_' + fieldId ) . html (
'<td class="field"><input checked="checked" id="cb_' + fieldId + '" name="f[]" value="' + field + '" type="checkbox"><label for="cb_' + fieldId + '"> ' + filterOptions [ 'name' ] + '</label></td>' +
'<td class="operator"><select id="operators_' + fieldId + '" name="op[' + field + ']"></td>' +
'<td class="values"></td>'
) ;
filterTable . append ( tr ) ;
select = tr . find ( 'td.operator select' ) ;
for ( i = 0 ; i < operators . length ; i ++ ) {
var option = $ ( '<option>' ) . val ( operators [ i ] ) . text ( operatorLabels [ operators [ i ] ] ) ;
if ( operators [ i ] == operator ) { option . attr ( 'selected' , true ) ; }
select . append ( option ) ;
}
select . change ( function ( ) { toggleOperator ( field ) ; } ) ;
switch ( filterOptions [ 'type' ] ) {
case "list" :
case "list_optional" :
case "list_status" :
case "list_subprojects" :
tr . find ( 'td.values' ) . append (
'<span style="display:none;"><select class="value" id="values_' + fieldId + '_1" name="v[' + field + '][]"></select>' +
' <span class="toggle-multiselect"><a>复选/multi-select</a></span></span>'
) ;
select = tr . find ( 'td.values select' ) ;
if ( values . length > 1 ) { select . attr ( 'multiple' , true ) ; }
for ( i = 0 ; i < filterValues . length ; i ++ ) {
var filterValue = filterValues [ i ] ;
var option = $ ( '<option>' ) ;
if ( $ . isArray ( filterValue ) ) {
option . val ( filterValue [ 1 ] ) . text ( filterValue [ 0 ] ) ;
if ( $ . inArray ( filterValue [ 1 ] , values ) > - 1 ) { option . attr ( 'selected' , true ) ; }
} else {
option . val ( filterValue ) . text ( filterValue ) ;
if ( $ . inArray ( filterValue , values ) > - 1 ) { option . attr ( 'selected' , true ) ; }
}
select . append ( option ) ;
}
break ;
case "date" :
case "date_past" :
tr . find ( 'td.values' ) . append (
'<span style="display:none;"><input type="text" name="v[' + field + '][]" id="values_' + fieldId + '_1" size="10" class="value date_value" /></span>' +
' <span style="display:none;"><input type="text" name="v[' + field + '][]" id="values_' + fieldId + '_2" size="10" class="value date_value" /></span>' +
' <span style="display:none;"><input type="text" name="v[' + field + '][]" id="values_' + fieldId + '" size="3" class="value" /> ' + labelDayPlural + '</span>'
) ;
$ ( '#values_' + fieldId + '_1' ) . val ( values [ 0 ] ) . datepicker ( datepickerOptions ) ;
$ ( '#values_' + fieldId + '_2' ) . val ( values [ 1 ] ) . datepicker ( datepickerOptions ) ;
$ ( '#values_' + fieldId ) . val ( values [ 0 ] ) ;
break ;
case "string" :
case "text" :
tr . find ( 'td.values' ) . append (
'<span style="display:none;"><input type="text" name="v[' + field + '][]" id="values_' + fieldId + '" size="30" class="value" /></span>'
) ;
$ ( '#values_' + fieldId ) . val ( values [ 0 ] ) ;
break ;
case "relation" :
tr . find ( 'td.values' ) . append (
'<span style="display:none;"><input type="text" name="v[' + field + '][]" id="values_' + fieldId + '" size="6" class="value" /></span>' +
'<span style="display:none;"><select class="value" name="v[' + field + '][]" id="values_' + fieldId + '_1"></select></span>'
) ;
$ ( '#values_' + fieldId ) . val ( values [ 0 ] ) ;
select = tr . find ( 'td.values select' ) ;
for ( i = 0 ; i < allProjects . length ; i ++ ) {
var filterValue = allProjects [ i ] ;
var option = $ ( '<option>' ) ;
option . val ( filterValue [ 1 ] ) . text ( filterValue [ 0 ] ) ;
if ( values [ 0 ] == filterValue [ 1 ] ) { option . attr ( 'selected' , true ) ; }
select . append ( option ) ;
}
case "integer" :
case "float" :
tr . find ( 'td.values' ) . append (
'<span style="display:none;"><input type="text" name="v[' + field + '][]" id="values_' + fieldId + '_1" size="6" class="value" /></span>' +
' <span style="display:none;"><input type="text" name="v[' + field + '][]" id="values_' + fieldId + '_2" size="6" class="value" /></span>'
) ;
$ ( '#values_' + fieldId + '_1' ) . val ( values [ 0 ] ) ;
$ ( '#values_' + fieldId + '_2' ) . val ( values [ 1 ] ) ;
break ;
}
}
function toggleFilter ( field ) {
var fieldId = field . replace ( '.' , '_' ) ;
if ( $ ( '#cb_' + fieldId ) . is ( ':checked' ) ) {
$ ( "#operators_" + fieldId ) . show ( ) . removeAttr ( 'disabled' ) ;
toggleOperator ( field ) ;
} else {
$ ( "#operators_" + fieldId ) . hide ( ) . attr ( 'disabled' , true ) ;
enableValues ( field , [ ] ) ;
}
}
function enableValues ( field , indexes ) {
var fieldId = field . replace ( '.' , '_' ) ;
$ ( '#tr_' + fieldId + ' td.values .value' ) . each ( function ( index ) {
if ( $ . inArray ( index , indexes ) >= 0 ) {
$ ( this ) . removeAttr ( 'disabled' ) ;
$ ( this ) . parents ( 'span' ) . first ( ) . show ( ) ;
} else {
$ ( this ) . val ( '' ) ;
$ ( this ) . attr ( 'disabled' , true ) ;
$ ( this ) . parents ( 'span' ) . first ( ) . hide ( ) ;
}
if ( $ ( this ) . hasClass ( 'group' ) ) {
$ ( this ) . addClass ( 'open' ) ;
} else {
$ ( this ) . show ( ) ;
}
} ) ;
}
function toggleOperator ( field ) {
var fieldId = field . replace ( '.' , '_' ) ;
var operator = $ ( "#operators_" + fieldId ) ;
switch ( operator . val ( ) ) {
case "!*" :
case "*" :
case "t" :
case "ld" :
case "w" :
case "lw" :
case "l2w" :
case "m" :
case "lm" :
case "y" :
case "o" :
case "c" :
enableValues ( field , [ ] ) ;
break ;
case "><" :
enableValues ( field , [ 0 , 1 ] ) ;
break ;
case "<t+" :
case ">t+" :
case "><t+" :
case "t+" :
case ">t-" :
case "<t-" :
case "><t-" :
case "t-" :
enableValues ( field , [ 2 ] ) ;
break ;
case "=p" :
case "=!p" :
case "!p" :
enableValues ( field , [ 1 ] ) ;
break ;
default :
enableValues ( field , [ 0 ] ) ;
break ;
}
}
function toggleMultiSelect ( el ) {
if ( el . attr ( 'multiple' ) ) {
el . removeAttr ( 'multiple' ) ;
} else {
el . attr ( 'multiple' , true ) ;
}
}
function submit _query _form ( id ) {
selectAllOptions ( "selected_columns" ) ;
$ ( '#' + id ) . submit ( ) ;
}
function showTab ( name ) {
$ ( 'div#content .tab-content' ) . hide ( ) ;
$ ( 'div.tabs a' ) . removeClass ( 'selected' ) ;
$ ( '#tab-content-' + name ) . show ( ) ;
$ ( '#tab-' + name ) . addClass ( 'selected' ) ;
return false ;
}
function moveTabRight ( el ) {
var lis = $ ( el ) . parents ( 'div.tabs' ) . first ( ) . find ( 'ul' ) . children ( ) ;
var tabsWidth = 0 ;
var i = 0 ;
lis . each ( function ( ) {
if ( $ ( this ) . is ( ':visible' ) ) {
tabsWidth += $ ( this ) . width ( ) + 6 ;
}
} ) ;
if ( tabsWidth < $ ( el ) . parents ( 'div.tabs' ) . first ( ) . width ( ) - 60 ) { return ; }
while ( i < lis . length && ! lis . eq ( i ) . is ( ':visible' ) ) { i ++ ; }
lis . eq ( i ) . hide ( ) ;
}
function moveTabLeft ( el ) {
var lis = $ ( el ) . parents ( 'div.tabs' ) . first ( ) . find ( 'ul' ) . children ( ) ;
var i = 0 ;
while ( i < lis . length && ! lis . eq ( i ) . is ( ':visible' ) ) { i ++ ; }
if ( i > 0 ) {
lis . eq ( i - 1 ) . show ( ) ;
}
}
function displayTabsButtons ( ) {
var lis ;
var tabsWidth = 0 ;
var el ;
$ ( 'div.tabs' ) . each ( function ( ) {
el = $ ( this ) ;
lis = el . find ( 'ul' ) . children ( ) ;
lis . each ( function ( ) {
if ( $ ( this ) . is ( ':visible' ) ) {
tabsWidth += $ ( this ) . width ( ) + 6 ;
}
} ) ;
if ( ( tabsWidth < el . width ( ) - 60 ) && ( lis . first ( ) . is ( ':visible' ) ) ) {
el . find ( 'div.tabs-buttons' ) . hide ( ) ;
} else {
el . find ( 'div.tabs-buttons' ) . show ( ) ;
}
} ) ;
}
function setPredecessorFieldsVisibility ( ) {
var relationType = $ ( '#relation_relation_type' ) ;
if ( relationType . val ( ) == "precedes" || relationType . val ( ) == "follows" ) {
$ ( '#predecessor_fields' ) . show ( ) ;
} else {
$ ( '#predecessor_fields' ) . hide ( ) ;
}
}
function showModal ( id , width ) {
var el = $ ( '#' + id ) . first ( ) ;
if ( el . length === 0 || el . is ( ':visible' ) ) { return ; }
var title = el . find ( 'h3.title' ) . text ( ) ;
el . dialog ( {
width : width ,
modal : true ,
resizable : false ,
dialogClass : 'modal' ,
title : title
} ) ;
el . find ( "input[type=text], input[type=submit]" ) . first ( ) . focus ( ) ;
}
function hideModal ( el ) {
var modal ;
if ( el ) {
modal = $ ( el ) . parents ( '.ui-dialog-content' ) ;
} else {
modal = $ ( '#ajax-modal' ) ;
}
modal . dialog ( "close" ) ;
}
function submitPreview ( url , form , target ) {
$ . ajax ( {
url : url ,
type : 'post' ,
data : $ ( '#' + form ) . serialize ( ) ,
success : function ( data ) {
$ ( '#' + target ) . html ( data ) ;
}
} ) ;
}
function collapseScmEntry ( id ) {
$ ( '.' + id ) . each ( function ( ) {
if ( $ ( this ) . hasClass ( 'open' ) ) {
collapseScmEntry ( $ ( this ) . attr ( 'id' ) ) ;
}
$ ( this ) . hide ( ) ;
} ) ;
$ ( '#' + id ) . removeClass ( 'open' ) ;
}
function expandScmEntry ( id ) {
$ ( '.' + id ) . each ( function ( ) {
$ ( this ) . show ( ) ;
if ( $ ( this ) . hasClass ( 'loaded' ) && ! $ ( this ) . hasClass ( 'collapsed' ) ) {
expandScmEntry ( $ ( this ) . attr ( 'id' ) ) ;
}
} ) ;
$ ( '#' + id ) . addClass ( 'open' ) ;
}
function scmEntryClick ( id , url ) {
el = $ ( '#' + id ) ;
if ( el . hasClass ( 'open' ) ) {
collapseScmEntry ( id ) ;
el . addClass ( 'collapsed' ) ;
return false ;
} else if ( el . hasClass ( 'loaded' ) ) {
expandScmEntry ( id ) ;
el . removeClass ( 'collapsed' ) ;
return false ;
}
if ( el . hasClass ( 'loading' ) ) {
return false ;
}
el . addClass ( 'loading' ) ;
$ . ajax ( {
url : url ,
success : function ( data ) {
el . after ( data ) ;
el . addClass ( 'open' ) . addClass ( 'loaded' ) . removeClass ( 'loading' ) ;
}
} ) ;
return true ;
}
function randomKey ( size ) {
var chars = new Array ( '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' , 'M' , 'N' , 'O' , 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , 'z' ) ;
var key = '' ;
for ( i = 0 ; i < size ; i ++ ) {
key += chars [ Math . floor ( Math . random ( ) * chars . length ) ] ;
}
return key ;
}
// Can't use Rails' remote select because we need the form data
function updateIssueFrom ( url ) {
$ . ajax ( {
url : url ,
type : 'post' ,
data : $ ( '#issue-form' ) . serialize ( )
} ) ;
}
function updateBulkEditFrom ( url ) {
$ . ajax ( {
url : url ,
type : 'post' ,
data : $ ( '#bulk_edit_form' ) . serialize ( )
} ) ;
}
function clearMessage ( id ) {
$ ( '#' + id ) . val ( "" ) ;
}
function observeAutocompleteField ( fieldId , url , options ) {
$ ( document ) . ready ( function ( ) {
$ ( '#' + fieldId ) . autocomplete ( $ . extend ( {
source : url ,
select : function ( e , ui ) { self . location = "/issues/" + ui . item . value ; } ,
2015-03-10 15:39:14 +08:00
minLength : 1 ,
2014-11-25 14:17:04 +08:00
search : function ( ) { $ ( '#' + fieldId ) . addClass ( 'ajax-loading' ) ; } ,
response : function ( ) { $ ( '#' + fieldId ) . removeClass ( 'ajax-loading' ) ;
}
} , options ) ) ;
$ ( '#' + fieldId ) . addClass ( 'autocomplete' ) ;
} ) ;
}
function observeSearchfield ( fieldId , targetId , url ) {
$ ( '#' + fieldId ) . each ( function ( ) {
var $this = $ ( this ) ;
$this . addClass ( 'autocomplete' ) ;
$this . attr ( 'data-value-was' , $this . val ( ) ) ;
var check = function ( ) {
var val = $this . val ( ) ;
if ( $this . attr ( 'data-value-was' ) != val ) {
$this . attr ( 'data-value-was' , val ) ;
$ . ajax ( {
url : url ,
type : 'get' ,
data : { q : $this . val ( ) } ,
success : function ( data ) { if ( targetId ) $ ( '#' + targetId ) . html ( data ) ; } ,
beforeSend : function ( ) { $this . addClass ( 'ajax-loading' ) ; } ,
complete : function ( ) { $this . removeClass ( 'ajax-loading' ) ; }
} ) ;
}
} ;
var reset = function ( ) {
if ( timer ) {
clearInterval ( timer ) ;
timer = setInterval ( check , 300 ) ;
}
} ;
var timer = setInterval ( check , 300 ) ;
$this . bind ( 'keyup click mousemove' , reset ) ;
} ) ;
}
function observeProjectModules ( ) {
var f = function ( ) {
/* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */
if ( $ ( '#project_enabled_module_names_issue_tracking' ) . attr ( 'checked' ) ) {
$ ( '#project_trackers' ) . show ( ) ;
} else {
$ ( '#project_trackers' ) . hide ( ) ;
}
} ;
$ ( window ) . load ( f ) ;
$ ( '#project_enabled_module_names_issue_tracking' ) . change ( f ) ;
}
function initMyPageSortable ( list , url ) {
$ ( '#list-' + list ) . sortable ( {
connectWith : '.block-receiver' ,
tolerance : 'pointer' ,
update : function ( ) {
$ . ajax ( {
url : url ,
type : 'post' ,
data : { 'blocks' : $ . map ( $ ( '#list-' + list ) . children ( ) , function ( el ) { return $ ( el ) . attr ( 'id' ) ; } ) }
} ) ;
}
} ) ;
$ ( "#list-top, #list-left, #list-right" ) . disableSelection ( ) ;
}
var warnLeavingUnsavedMessage ;
function warnLeavingUnsaved ( message ) {
warnLeavingUnsavedMessage = message ;
$ ( 'form' ) . submit ( function ( ) {
$ ( 'textarea' ) . removeData ( 'changed' ) ;
} ) ;
$ ( 'textarea' ) . change ( function ( ) {
$ ( this ) . data ( 'changed' , 'changed' ) ;
} ) ;
window . onbeforeunload = function ( ) {
var warn = false ;
$ ( 'textarea' ) . blur ( ) . each ( function ( ) {
if ( $ ( this ) . data ( 'changed' ) ) {
warn = true ;
}
} ) ;
if ( warn ) { return warnLeavingUnsavedMessage ; }
} ;
}
2015-05-06 11:04:57 +08:00
function setupHeartBeat ( ) {
var time = 60 * 1000 * 30 ; // 30 mins
setInterval ( function ( ) { $ . getJSON ( '/account/heartbeat' ) ; } , time ) ;
}
2014-11-25 14:17:04 +08:00
2015-05-06 11:04:57 +08:00
function setupAjaxIndicator ( ) {
2014-11-25 14:17:04 +08:00
$ ( '#ajax-indicator' ) . bind ( 'ajaxSend' , function ( event , xhr , settings ) {
2015-05-11 20:57:59 +08:00
if ( settings && settings . url && settings . url . match ( /account\/heartbeat$/ ) ) {
2015-05-06 11:04:57 +08:00
return ;
}
2014-11-25 14:17:04 +08:00
if ( $ ( '.ajax-loading' ) . length === 0 && settings . contentType != 'application/octet-stream' ) {
$ ( '#ajax-indicator' ) . show ( ) ;
}
} ) ;
$ ( '#ajax-indicator' ) . bind ( 'ajaxStop' , function ( ) {
$ ( '#ajax-indicator' ) . hide ( ) ;
} ) ;
}
function hideOnLoad ( ) {
$ ( '.hol' ) . hide ( ) ;
}
function addFormObserversForDoubleSubmit ( ) {
$ ( 'form[method=post]' ) . each ( function ( ) {
if ( ! $ ( this ) . hasClass ( 'multiple-submit' ) ) {
$ ( this ) . submit ( function ( form _submission ) {
if ( $ ( form _submission . target ) . attr ( 'data-submitted' ) ) {
form _submission . preventDefault ( ) ;
} else {
$ ( form _submission . target ) . attr ( 'data-submitted' , true ) ;
}
} ) ;
}
} ) ;
}
function blockEventPropagation ( event ) {
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
}
function toggleAndSettingWordsVal ( parent _widget , text _widget , value ) {
text _widget . val ( value )
parent _widget . slideToggle ( 400 )
}
function transpotUrl ( scope ) {
$ ( scope ) . each ( function ( ) {
var tmpContent = $ ( this ) . html ( ) ;
tmpContent = tmpContent . replace ( /(^|[^\"\'])(http|ftp|mms|rstp|news|https)(\:\/\/[^<\s\+,, ]+)/gi , "$1<a href='$2$3' target='_blank'>$2$3<\/a>" ) ;
// tmpContent = tmpContent.replace(/(^|[^\/])(www\.[^<\s\+,, ]+)/gi,"$1<a href='http:\/\/$2' style='color:blue' target='_blank'>$2</a>");
$ ( this ) . html ( tmpContent ) ;
} ) ;
}
$ ( document ) . ready ( setupAjaxIndicator ) ;
2015-05-06 11:04:57 +08:00
$ ( document ) . ready ( setupHeartBeat ) ;
2014-11-25 14:17:04 +08:00
$ ( document ) . ready ( hideOnLoad ) ;
$ ( document ) . ready ( addFormObserversForDoubleSubmit ) ;
function img _thumbnails ( ) {
$ ( '.thumbnails a' ) . colorbox ( { rel : 'nofollow' } ) ;
$ ( '.attachments' ) . find ( 'a' ) . each ( function ( index , element ) {
var href _value = $ ( element ) . attr ( 'href' ) ;
2015-03-20 16:49:04 +08:00
if ( /\.(jpg|png|gif|bmp|jpeg|PNG|BMP|GIF|JPG|JPEG)$/ . test ( href _value ) ) {
2014-11-25 14:17:04 +08:00
$ ( element ) . colorbox ( { rel : 'nofollow' } ) ;
}
2015-03-20 17:26:31 +08:00
} ) ;
$ ( '.for_img_thumbnails' ) . find ( 'a' ) . each ( function ( index , element ) {
var href _value = $ ( element ) . attr ( 'href' ) ;
if ( /\.(jpg|png|gif|bmp|jpeg|PNG|BMP|GIF|JPG|JPEG)$/ . test ( href _value ) ) {
$ ( element ) . colorbox ( { rel : 'nofollow' } ) ;
}
2014-11-25 14:17:04 +08:00
} ) ;
}
$ ( document ) . ready ( img _thumbnails ) ;
function TimeClose ( dateText , inst ) {
if ( inst . id == "issue_start_date" ) {
time = dateText ;
}
}
var time = new Date ( ) ;
function TimeBeforeShow ( input ) {
if ( input . id == "issue_due_date" ) {
//var minDate = $(input).datepicker('option', 'minDate');
var tempdata = $ ( "#issue_start_date" ) . attr ( "value" ) ;
$ ( input ) . datepicker ( 'option' , 'minDate' , new Date ( tempdata . replace ( /-/g , "/" ) ) ) ;
//$('.selector').datepicker('option', 'minDate', '12/25/2012');
}
}
function SetMinValue ( ) {
/// var tempdata=$("#issue_start_date").attr("value");
//$('.selector').datepicker('option', 'minDate', '12/25/2012');
//alert(tempdata);
//$("#issue_due_date").datepicker({
// minDate: new Date(2014,08,23)
//var datepickerOptions=
//{dateFormat: 'yy-mm-dd',minDate: new Date(2014,08,23), showOn: 'button', buttonImageOnly: true, buttonImage: "path_to_image('/images/calendar.png')", showButtonPanel: true, showWeek: true, showOtherMonths: true, selectOtherMonths: true};
//alert( $('.issue_due_date').length);
//$('.selector')[1].datepicker('option', 'minDate', new Date(2014, 0 - 8, 23));
//$("#issue_due_date").datepicker(datepickerOptions);
//$("##{issue_due_date}").datepicker(datepickerOptions);
//$("#issue_due_date").datepicker(
// {dateFormat: 'yy-mm-dd',minDate: new Date(2014,08,23), showOn: 'button', buttonImageOnly: true, buttonImage: "path_to_image('/images/calendar.png')", showButtonPanel: true, showWeek: true, showOtherMonths: true, selectOtherMonths: true}
//)
//});
}
function PrecentChange ( obj ) {
var _v = obj ;
if ( _v == 100 )
{
//var select=$("select[id='issue_status_id']");
$ ( "select[id='issue_status_id']" ) . find ( "option[value='3']" ) . attr ( "selected" , "selected" ) ;
}
else if ( _v == 0 )
{
//alert(1);
$ ( "select[id='issue_status_id']" ) . find ( "option[value='1']" ) . attr ( "selected" , "selected" ) ;
}
else if ( _v != 100 && _v != 0 )
{
// alert(2);
$ ( "select[id='issue_status_id']" ) . find ( "option[value='2']" ) . attr ( "selected" , "selected" ) ;
}
}
2015-01-22 16:41:56 +08:00
//added by lizanle 日期選擇js
function HS _DateAdd ( interval , number , date ) {
number = parseInt ( number ) ;
if ( typeof ( date ) == "string" ) { var date = new Date ( date . split ( "-" ) [ 0 ] , date . split ( "-" ) [ 1 ] , date . split ( "-" ) [ 2 ] ) }
if ( typeof ( date ) == "object" ) { var date = date }
switch ( interval ) {
case "y" : return new Date ( date . getFullYear ( ) + number , date . getMonth ( ) , date . getDate ( ) ) ; break ;
case "m" : return new Date ( date . getFullYear ( ) , date . getMonth ( ) + number , checkDate ( date . getFullYear ( ) , date . getMonth ( ) + number , date . getDate ( ) ) ) ; break ;
case "d" : return new Date ( date . getFullYear ( ) , date . getMonth ( ) , date . getDate ( ) + number ) ; break ;
case "w" : return new Date ( date . getFullYear ( ) , date . getMonth ( ) , 7 * number + date . getDate ( ) ) ; break ;
}
}
function checkDate ( year , month , date ) {
var enddate = [ "31" , "28" , "31" , "30" , "31" , "30" , "31" , "31" , "30" , "31" , "30" , "31" ] ;
var returnDate = "" ;
if ( year % 4 == 0 ) { enddate [ 1 ] = "29" }
if ( date > enddate [ month ] ) { returnDate = enddate [ month ] } else { returnDate = date }
return returnDate ;
}
function WeekDay ( date ) {
var theDate ;
if ( typeof ( date ) == "string" ) { theDate = new Date ( date . split ( "-" ) [ 0 ] , date . split ( "-" ) [ 1 ] , date . split ( "-" ) [ 2 ] ) ; }
if ( typeof ( date ) == "object" ) { theDate = date }
return theDate . getDay ( ) ;
}
function HS _calender ( ) {
var lis = "" ;
var style = "" ;
/*可以把下面的css剪切出去独立一个css文件*/
style += "<style type='text/css'>" ;
style += ".calender { width:170px; height:auto; font-size:12px; margin-right:14px; background:url(calenderbg.gif) no-repeat right center #fff; border:1px solid #397EAE; padding:1px}" ;
style += ".calender ul {list-style-type:none; margin:0; padding:0;}" ;
style += ".calender .day { background-color:#EDF5FF; height:20px;}" ;
style += ".calender li { list-style-type: none; float: left; margin: 0 0px; padding: 0 !important; background: #ffffff; background-image: none !important;}" ;
style += ".calender .day li,.calender .date li{ float:left; width:14%; height:20px; line-height:20px; text-align:center}" ;
style += ".calender li a { text-decoration:none; font-family:Tahoma; font-size:11px; color:#333}" ;
style += ".calender li a:hover { color:#f30; text-decoration:underline}" ;
style += ".calender li a.hasArticle {font-weight:bold; color:#f60 !important}" ;
style += ".lastMonthDate, .nextMonthDate {color:#bbb;font-size:11px}" ;
style += ".selectThisYear a, .selectThisMonth a{text-decoration:none; margin:0 2px; color:#000; font-weight:bold}" ;
style += ".calender .LastMonth, .calender .NextMonth{ text-decoration:none; color:#000; font-size:18px; font-weight:bold; line-height:16px;}" ;
style += ".calender .LastMonth { float:left;}" ;
style += ".calender .NextMonth { float:right;}" ;
style += ".calenderBody {clear:both}" ;
style += ".calenderTitle {text-align:center;height:20px; line-height:20px; clear:both}" ;
style += ".today { background-color:#ffffaa;border:1px solid #f60; padding:2px}" ;
style += ".today a { color:#f30; }" ;
style += ".calenderBottom {clear:both; border-top:1px solid #ddd; padding: 3px 0; text-align:left}" ;
style += ".calenderBottom a {text-decoration:none; margin:2px !important; font-weight:bold; color:#000}" ;
style += ".calenderBottom a.closeCalender{float:right}" ;
style += ".closeCalenderBox {float:right; border:1px solid #000; background:#fff; font-size:9px; width:11px; height:11px; line-height:11px; text-align:center;overflow:hidden; font-weight:normal !important}" ;
style += "</style>" ;
var now ;
if ( typeof ( arguments [ 0 ] ) == "string" ) {
selectDate = arguments [ 0 ] . split ( "-" ) ;
var year = selectDate [ 0 ] ;
var month = parseInt ( selectDate [ 1 ] ) - 1 + "" ;
var date = selectDate [ 2 ] ;
now = new Date ( year , month , date ) ;
} else if ( typeof ( arguments [ 0 ] ) == "object" ) {
now = arguments [ 0 ] ;
}
var lastMonthEndDate = HS _DateAdd ( "d" , "-1" , now . getFullYear ( ) + "-" + now . getMonth ( ) + "-01" ) . getDate ( ) ;
var lastMonthDate = WeekDay ( now . getFullYear ( ) + "-" + now . getMonth ( ) + "-01" ) ;
var thisMonthLastDate = HS _DateAdd ( "d" , "-1" , now . getFullYear ( ) + "-" + ( parseInt ( now . getMonth ( ) ) + 1 ) . toString ( ) + "-01" ) ;
var thisMonthEndDate = thisMonthLastDate . getDate ( ) ;
var thisMonthEndDay = thisMonthLastDate . getDay ( ) ;
var todayObj = new Date ( ) ;
today = todayObj . getFullYear ( ) + "-" + todayObj . getMonth ( ) + "-" + todayObj . getDate ( ) ;
for ( i = 0 ; i < lastMonthDate ; i ++ ) { // Last Month's Date
lis = "<li class='lastMonthDate'>" + lastMonthEndDate + "</li>" + lis ;
lastMonthEndDate -- ;
}
for ( i = 1 ; i <= thisMonthEndDate ; i ++ ) { // Current Month's Date
if ( today == now . getFullYear ( ) + "-" + now . getMonth ( ) + "-" + i ) {
var todayString = now . getFullYear ( ) + "-" + ( parseInt ( now . getMonth ( ) ) + 1 ) . toString ( ) + "-" + i ;
lis += "<li><a href=javascript:void(0) class='today' onclick='_selectThisDay(this)' title='" + now . getFullYear ( ) + "-" + ( parseInt ( now . getMonth ( ) ) + 1 ) + "-" + i + "'>" + i + "</a></li>" ;
} else {
lis += "<li><a href=javascript:void(0) onclick='_selectThisDay(this)' title='" + now . getFullYear ( ) + "-" + ( parseInt ( now . getMonth ( ) ) + 1 ) + "-" + i + "'>" + i + "</a></li>" ;
}
}
var j = 1 ;
for ( i = thisMonthEndDay ; i < 6 ; i ++ ) { // Next Month's Date
lis += "<li class='nextMonthDate'>" + j + "</li>" ;
j ++ ;
}
lis += style ;
var CalenderTitle = "<a href='javascript:void(0)' class='NextMonth' onclick=HS_calender(HS_DateAdd('m',1,'" + now . getFullYear ( ) + "-" + now . getMonth ( ) + "-" + now . getDate ( ) + "'),this) title='Next Month'>»</a>" ;
CalenderTitle += "<a href='javascript:void(0)' class='LastMonth' onclick=HS_calender(HS_DateAdd('m',-1,'" + now . getFullYear ( ) + "-" + now . getMonth ( ) + "-" + now . getDate ( ) + "'),this) title='Previous Month'>«</a>" ;
CalenderTitle += "<span class='selectThisYear'><a href='javascript:void(0)' onclick='CalenderselectYear(this)' title='Click here to select other year' >" + now . getFullYear ( ) + "</a></span>年<span class='selectThisMonth'><a href='javascript:void(0)' onclick='CalenderselectMonth(this)' title='Click here to select other month'>" + ( parseInt ( now . getMonth ( ) ) + 1 ) . toString ( ) + "</a></span>月" ;
if ( arguments . length > 1 ) {
arguments [ 1 ] . parentNode . parentNode . getElementsByTagName ( "ul" ) [ 1 ] . innerHTML = lis ;
arguments [ 1 ] . parentNode . innerHTML = CalenderTitle ;
} else {
var CalenderBox = style + "<div class='calender'><div class='calenderTitle'>" + CalenderTitle + "</div><div class='calenderBody'><ul class='day'><li>日</li><li>一</li><li>二</li><li>三</li><li>四</li><li>五</li><li>六</li></ul><ul class='date' id='thisMonthDate'>" + lis + "</ul></div><div class='calenderBottom'><a href='javascript:void(0)' class='closeCalender' onclick='closeCalender(this)'>×</a><span><span><a href=javascript:void(0) onclick='_selectThisDay(this)' title='" + todayString + "'>Today</a></span></span></div></div>" ;
return CalenderBox ;
}
}
function _selectThisDay ( d ) {
var boxObj = d . parentNode . parentNode . parentNode . parentNode . parentNode ;
boxObj . targetObj . value = d . title ;
boxObj . parentNode . removeChild ( boxObj ) ;
}
function closeCalender ( d ) {
var boxObj = d . parentNode . parentNode . parentNode ;
boxObj . parentNode . removeChild ( boxObj ) ;
}
function CalenderselectYear ( obj ) {
var opt = "" ;
var thisYear = obj . innerHTML ;
for ( i = 1970 ; i <= 2020 ; i ++ ) {
if ( i == thisYear ) {
opt += "<option value=" + i + " selected>" + i + "</option>" ;
} else {
opt += "<option value=" + i + ">" + i + "</option>" ;
}
}
opt = "<select onblur='selectThisYear(this)' onchange='selectThisYear(this)' style='font-size:11px'>" + opt + "</select>" ;
obj . parentNode . innerHTML = opt ;
}
function selectThisYear ( obj ) {
HS _calender ( obj . value + "-" + obj . parentNode . parentNode . getElementsByTagName ( "span" ) [ 1 ] . getElementsByTagName ( "a" ) [ 0 ] . innerHTML + "-1" , obj . parentNode ) ;
}
function CalenderselectMonth ( obj ) {
var opt = "" ;
var thisMonth = obj . innerHTML ;
for ( i = 1 ; i <= 12 ; i ++ ) {
if ( i == thisMonth ) {
opt += "<option value=" + i + " selected>" + i + "</option>" ;
} else {
opt += "<option value=" + i + ">" + i + "</option>" ;
}
}
opt = "<select onblur='selectThisMonth(this)' onchange='selectThisMonth(this)' style='font-size:11px'>" + opt + "</select>" ;
obj . parentNode . innerHTML = opt ;
}
function selectThisMonth ( obj ) {
HS _calender ( obj . parentNode . parentNode . getElementsByTagName ( "span" ) [ 0 ] . getElementsByTagName ( "a" ) [ 0 ] . innerHTML + "-" + obj . value + "-1" , obj . parentNode ) ;
}
function HS _setDate ( inputObj ) {
var calenderObj = document . createElement ( "span" ) ;
calenderObj . innerHTML = HS _calender ( new Date ( ) ) ;
calenderObj . style . position = "absolute" ;
calenderObj . targetObj = inputObj ;
inputObj . parentNode . insertBefore ( calenderObj , inputObj . nextSibling ) ;
}
2015-01-21 17:43:06 +08:00
//lizanle 刷新函数
function redo ( ) {
window . location . reload ( )
}
2015-03-11 10:52:09 +08:00
//// 作业附件删除
$ ( function ( ) {
$ ( '.attachments a.delete-homework-icon' ) . bind ( 'ajax:complete' , //this will work
function ( event , data , status , xhr ) { //note parametes
$ ( this ) . parent ( 'p' ) . remove ( ) ;
console . log ( "delete complete." ) ;
} ) ;
2015-03-25 13:13:09 +08:00
$ ( 'a.tb_all' ) . bind ( 'ajax:complete' , function ( event , data , status , xhr ) {
if ( status == 'success' ) {
var res = JSON . parse ( data . responseText ) ;
if ( res . length < 1 ) {
return ;
}
if ( res . length == 1 ) {
2015-06-24 16:07:54 +08:00
var file = encodeURI ( res [ 0 ] . file ) . replace ( /\+/g , '%2B' ) ;
location . href = '/zipdown/download?file=' + file ; return ;
2015-03-25 13:13:09 +08:00
}
document . getElementById ( 'light' ) . style . display = 'block' ;
$container = $ ( '#light .upload_box_ul' ) ;
$container . empty ( ) ;
for ( var i = 0 ; i < res . length ; ++ i ) {
var des = '' ;
if ( res . count > 1 ) {
des = '第' + res [ i ] . index + '-' + ( res [ i ] . count + res [ i ] . index - 1 ) + '个学生的作品下载' ;
} else {
des = '第' + res [ i ] . index + '个学生的作品下载' ;
}
$ ( '<li><span class="upload_box_span" >' + ( i + 1 ) + '.</span> <a href="/zipdown/download?file=' + res [ i ] . file + '">' + des + '</a><span class="c_grey"> (共' + res [ i ] . size + 'M) </span> </li>' ) . appendTo ( $container ) ;
}
}
2015-05-28 10:47:40 +08:00
} ) ;
$ ( '#download_homework_attachments' ) . bind ( 'ajax:complete' , function ( event , data , status , xhr ) {
if ( status == 'success' ) {
var res = JSON . parse ( data . responseText ) ;
2015-06-05 14:33:22 +08:00
if ( res . length == null ) {
alert ( "该作业没有任何附件可下载" ) ;
2015-05-28 10:47:40 +08:00
}
2015-06-05 14:33:22 +08:00
else if ( res . length < 1 ) {
return ;
2015-05-28 10:47:40 +08:00
}
2015-06-05 14:33:22 +08:00
else
{
if ( res . length == 1 ) {
location . href = '/zipdown/download?file=' + res [ 0 ] . file ; return ;
2015-05-28 10:47:40 +08:00
}
2015-06-05 14:33:22 +08:00
document . getElementById ( 'light' ) . style . display = 'block' ;
$container = $ ( '#light .upload_box_ul' ) ;
$container . empty ( ) ;
for ( var i = 0 ; i < res . length ; ++ i ) {
var des = '' ;
if ( res . count > 1 ) {
des = '第' + res [ i ] . index + '-' + ( res [ i ] . count + res [ i ] . index - 1 ) + '个学生的作品下载' ;
} else {
des = '第' + res [ i ] . index + '个学生的作品下载' ;
}
$ ( '<li><span class="upload_box_span" >' + ( i + 1 ) + '.</span> <a href="/zipdown/download?file=' + res [ i ] . file + '">' + des + '</a><span class="c_grey"> (共' + res [ i ] . size + 'M) </span> </li>' ) . appendTo ( $container ) ;
2015-03-25 13:13:09 +08:00
2015-06-05 14:33:22 +08:00
}
2015-05-28 10:47:40 +08:00
}
}
} ) ;
2015-03-11 10:52:09 +08:00
} ) ;
2015-04-13 18:34:44 +08:00
//firefox的pre标签换行
$ ( document ) . ready ( function ( ) {
var userAgent = navigator . userAgent . toLowerCase ( ) ;
var browser = {
version : ( userAgent . match ( /.+(?:rv|it|ra|ie)[/: ]([d.]+)/ ) || [ ] ) [ 1 ] ,
safari : /webkit/ . test ( userAgent ) ,
opera : /opera/ . test ( userAgent ) ,
msie : /msie/ . test ( userAgent ) && ! /opera/ . test ( userAgent ) ,
mozilla : /mozilla/ . test ( userAgent ) && ! /(compatible|webkit)/ . test ( userAgent )
} ;
if ( browser . mozilla || browser . opera ) {
$ ( "pre" ) . addClass ( "break_word_firefox" ) ;
}
else {
$ ( "pre" ) . addClass ( "break_word" ) ;
}
} ) ;