<commit_before>angular.module 'ngBlockEditor', []

.provider 'BlockEditor', ->
    @blockTypes = {}
    @editorTemplateUrl = 'ng-block-editor/editor.html'
    @blockTemplateUrl = 'ng-block-editor/block.html'
    @dragAndDropEnabled = no
    @toolbar = []
    @messages =
        removeBlockConfirm: 'Are you sure you want to remove this block?'

    try
        angular.module 'angular-sortable-view'
        @dragAndDropEnabled = yes
    catch e
        @dragAndDropEnabled = no

    @registerBlockType = (id, config) ->
        config.type = id
        @blockTypes[id] = config

    self = @

    @$get = ['$injector', '$log', ($injector, $log) ->
        return {
            editorTemplateUrl: self.editorTemplateUrl
            blockTemplateUrl: self.blockTemplateUrl
            blockTypes: self.blockTypes
            dragAndDropEnabled: self.dragAndDropEnabled
            toolbar: self.toolbar,
            getMessage: (_id, editor, block) ->
                if not self.messages[_id]?
                    $log.error '[ngBlockEditor] No message with _id ' + _id

                # DI enabled function
                if _.isFunction(self.messages[_id]) or _.isArray(self.messages[_id])
                    return $injector.invoke(self.messages[_id], {$editor: editor, $block: block})

                return self.messages[_id]
        }
    ]

    return @


.controller 'BlockEditorEmbedController', ($scope, $timeout, $sce, $block) ->
    $scope.embeddables = [
        {
            provider: 'youtube'
            displayName: 'YouTube'
            regex: /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/
        },
        {
            provider: 'soundcloud'
            displayName: 'SoundCloud'
            regex: /https?:\/\/(soundcloud.com\/[a-zA-Z0-9\/_-]*)/
        }
    ]
    $scope.data =
        url: ''
        isValid: no
        contentId: undefined

    $scope.trustedConcat = ->
        args = Array.prototype.slice.call arguments
        return $sce.trustAsResourceUrl(args.join '')

    _update = _.debounce (url) ->
        $timeout ->
            if not url?
                delete $block.content.provider
                delete $block.content.url
                $scope.data.contentId = undefined
                $scope.data.isValid = no
            else
                service = _.find $scope.embeddables, (e) -> e.regex.test url

                if service
                    $block.content.provider = service.provider
                    $block.content.url = url
                    $scope.data.contentId = service.regex.exec(url)[1]
                    $scope.data.isValid = yes
                    $scope.data.url = url
                else
                    delete $block.content.provider
                    delete $block.content.url
                    $scope.data.contentId = undefined<commit_msg>Add a short comment.<commit_after>angular.module 'ngBlockEditor', []

.provider 'BlockEditor', ->
    @blockTypes = {}
    @editorTemplateUrl = 'ng-block-editor/editor.html'
    @blockTemplateUrl = 'ng-block-editor/block.html'
    @dragAndDropEnabled = no
    @toolbar = []
    @messages =
        removeBlockConfirm: 'Are you sure you want to remove this block?'

    try
        angular.module 'angular-sortable-view'
        @dragAndDropEnabled = yes
    catch e
        @dragAndDropEnabled = no

    @registerBlockType = (id, config) ->
        config.type = id
        @blockTypes[id] = config

    self = @

    @$get = ['$injector', '$log', ($injector, $log) ->
        return {
            editorTemplateUrl: self.editorTemplateUrl
            blockTemplateUrl: self.blockTemplateUrl
            blockTypes: self.blockTypes
            dragAndDropEnabled: self.dragAndDropEnabled
            toolbar: self.toolbar,
            getMessage: (_id, editor, block) ->
                if not self.messages[_id]?
                    $log.error '[ngBlockEditor] No message with _id ' + _id

                # DI enabled function
                if _.isFunction(self.messages[_id]) or _.isArray(self.messages[_id])
                    return $injector.invoke(self.messages[_id], {$editor: editor, $block: block})

                return self.messages[_id]
        }
    ]

    return @


.controller 'BlockEditorEmbedController', ($scope, $timeout, $sce, $block) ->
    $scope.embeddables = [
        {
            provider: 'youtube'
            displayName: 'YouTube'
            regex: /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/
        },
        {
            provider: 'soundcloud'
            displayName: 'SoundCloud'
            regex: /https?:\/\/(soundcloud.com\/[a-zA-Z0-9\/_-]*)/
        }
    ]
    $scope.data =
        url: ''
        isValid: no
        contentId: undefined

    $scope.trustedConcat = ->
        # The regular expressions protect us from XSS.
        args = Array.prototype.slice.call arguments
        return $sce.trustAsResourceUrl(args.join '')

    _update = _.debounce (url) ->
        $timeout ->
            if not url?
                delete $block.content.provider
                delete $block.content.url
                $scope.data.contentId = undefined
                $scope.data.isValid = no
            else
                service = _.find $scope.embeddables, (e) -> e.regex.test url

                if service
                    $block.content.provider = service.provider
                    $block.content.url = url
                    $scope.data.contentId = service.regex.exec(url)[1]
                    $scope.data.isValid = yes
                    $scope.data.url = url
                else
                    delete $block.content.provider
                    delete $block.content.url
                    $scope.data.contentId = undefined
{'fraction_non_alphanumeric': 0.1301765105227427, 'fraction_numerical': 0.0016972165648336728, 'mean_word_length': 1.6426008968609866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5865615', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1617, 'n_words': 325}