2016-03-01 07:36:50 -05:00
|
|
|
class @BlobLicenseSelector
|
|
|
|
licenseRegex: /^(.+\/)?(licen[sc]e|copying)($|\.)/i
|
|
|
|
|
2016-04-11 09:49:25 -04:00
|
|
|
constructor: (editor) ->
|
|
|
|
@$licenseSelector = $('.js-license-selector')
|
|
|
|
$fileNameInput = $('#file_name')
|
2016-03-01 07:36:50 -05:00
|
|
|
|
2016-04-11 09:49:25 -04:00
|
|
|
initialFileNameValue = if $fileNameInput.length
|
|
|
|
$fileNameInput.val()
|
|
|
|
else if $('.editor-file-name').length
|
|
|
|
$('.editor-file-name').text().trim()
|
2016-03-01 07:36:50 -05:00
|
|
|
|
2016-04-11 09:49:25 -04:00
|
|
|
@toggleLicenseSelector(initialFileNameValue)
|
|
|
|
|
|
|
|
if $fileNameInput
|
|
|
|
$fileNameInput.on 'keyup blur', (e) =>
|
|
|
|
@toggleLicenseSelector($(e.target).val())
|
|
|
|
|
|
|
|
$('select.license-select').on 'change', (e) ->
|
|
|
|
data =
|
|
|
|
project: $(this).data('project')
|
|
|
|
fullname: $(this).data('fullname')
|
|
|
|
Api.licenseText $(this).val(), data, (license) ->
|
|
|
|
editor.setValue(license.content, -1)
|
2016-03-01 07:36:50 -05:00
|
|
|
|
|
|
|
toggleLicenseSelector: (fileName) =>
|
|
|
|
if @licenseRegex.test(fileName)
|
2016-04-11 09:49:25 -04:00
|
|
|
@$licenseSelector.show()
|
2016-03-01 07:36:50 -05:00
|
|
|
else
|
2016-04-11 09:49:25 -04:00
|
|
|
@$licenseSelector.hide()
|