TextAngular fileDropHandler documentation

喜你入骨 提交于 2019-12-05 03:06:20

Sorry about the lack of docs!

Basically the defaultFileDropHandler is triggered when the HTML element.on("drop") event is fired.

Implementing this via the textAngularSetup file is fine, but will be globally applied to all instances. To apply a handler for just one instance of textAngular use the ta-file-drop attribute which should be the name of a function on the scope with the same signature as defaultFileDropHandler. For Example:

JS In Controller

$scope.dropHandler = function(file, insertAction){...};

HTML

<div text-angular data-ng-model="NoteText" ta-file-drop="dropHandler"></div>

Both great answer, thank you!

I would just like to put the full code out to cover the global case since the code was only a snippet...

app.config( function( $provide ) {
    $provide.decorator( 'taOptions', [ '$delegate', function( taOptions ) {

        taOptions.defaultFileDropHandler = function( file, insertAction ) {
            // validation
            if( file.type.substring( 0, 5 ) !== "image" ) {
                // add your own code here
                alert( "only images can be added" );
                return;
            }
            if( file.size > 500000 ) {
                // add your own code here
                alert( "file size cannot exceed 0.5MB" );
                return;
            }

            // create a base64 string
            var reader = new FileReader();
            reader.onload = function() {
                reader.result && insertAction( "insertImage", reader.result, true );
            };

            reader.readAsDataURL(file);
            return true;
        };

        return taOptions;
    }]);
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!