psergus / ngWYSIWYG

true angular WYSIWYG
MIT License
63 stars 42 forks source link

Print Icon not working on Firefox browser but working fine in chrome browser. #67

Open anandg-optisol opened 8 years ago

anandg-optisol commented 8 years ago

Hi, I am very happy to use your WYSIWYG editor for my project. I am facing few issue while using it. Print icon not working in firefox browser. Another issue is that, when having 3 editor on the same page, Insert hyperlink is not working fine. Insert hyperlink works well for the first one, and for the rest it is not working fine. Pls help me to complete the project.

OlexandrPopov commented 8 years ago

execCommand('print') is not supported by Firefox. You have to use window.print() instead.

Here is how the code can be modified:

scope.$on('execCommand', function(e, cmd) {
    console.log('execCommand: ');
    console.log(cmd);
    $element[0].contentDocument.body.focus();
    //scope.getSelection();
    var sel = $document.selection; //http://stackoverflow.com/questions/11329982/how-refocus-when-insert-image-in-contenteditable-divs-in-ie
    if (sel) {
        var textRange = sel.createRange();
        $document.execCommand(cmd.command, 0, cmd.arg);
        textRange.collapse(false);
        textRange.select();
    }
    else {
        var res = $document.execCommand(cmd.command, 0, cmd.arg);

        if(cmd.command == 'print' && !res)
        {
            // Hello Firefox!
            $element[0].contentWindow.print();
        }
    }
    //scope.restoreSelection();
    $document.body.focus();
    scope.sync();
});