0

I have registered javascript under portal_javascript using the answer 1 from How to Disable Copy Paste (Browser) steps I followed: 1> copied the script in a file

document.onkeydown = function(e) {
    if (e.ctrlKey && e.keyCode === 65) {
   //     alert('not allowed');
        return false;
    }
     if (e.ctrlKey && e.keyCode === 67) {
     //   alert('not allowed');
        return false; 
    }
     if (e.ctrlKey && e.keyCode === 86) {
       // alert('not allowed');
        return false;
    }
};​
document.oncontextmenu=new Function("return false")

Step 2)Selected portal_javascripts /added this script with just the same id/url under development mode and saved. 3.In the atreal.richfile.preview customize the template (atreal.richfile.preview.interfaces.ipreview-atreal.richfile.preview.viewlet) by setting the mouse buttons events onSelectStart and onSelectDrag to False. Change the code by removing the right top buttons of the preview window and also displaying files other than pdf in this window. Use the code block as :

<dl class="richfile portlet"
    tal:condition="view/available"
    tal:attributes="id view/plugin_id"
    i18n:domain="atreal.richfile.preview">

    <dt tal:attributes="id string:${view/plugin_id}Header" class="rfheader portletHeader">
        <span class="portletTopLeft"></span>
        <!--tal:block tal:replace="structure view/controls"-->
        <span class="title" style="font-weight:bold"
            i18n:translate="">
            Preview
        </span>

        <span class="portletTopRight" ></span>
    </dt>

        <!--Your specific code here      tal:condition="not:ispdf" -->        
    <dd>
        <tal:block define="ispdf python:here.absolute_url().endswith('.pdf')">
        <IFRAME src="http://www.xyz.com" 
                    tal:condition="not:ispdf"
            tal:attributes="src string:${here/absolute_url}/rfpreview"
            width="100%" height="400" scrolling="auto" frameborder="1"> 
                    draggable="false" onselectstart="false"
           </IFRAME>  
    </tal:block>
    </dd>   
</dl>
  1. In ZMI, portal_types/File select Aliases tab and change the methods to (selected layout) for both Default and View Aliases and save.
  2. IN ZMI, portal_skins/archetypes customize at_download code to return nothing or rather deleted the code there.
  3. Use the add-on collective.documentviewer to preview pdf files. This works fine for me. I have been persueing this problem past 1 1/2 month. Finally I am happy with the end result. Thought of sharing with you all. :)
Community
  • 1
  • 1
user956424
  • 1,611
  • 2
  • 37
  • 67

1 Answers1

2

Try this to prevent default behaviour.

document.onkeydown = function(e) {
    if (e.ctrlKey && e.keyCode === 65) {
        alert('not allowed');
    }
     if (e.ctrlKey && e.keyCode === 67) {
        alert('not allowed');
    }
     if (e.ctrlKey && e.keyCode === 86) {
        alert('not allowed');
    }

    return false;
};​

*DEMO* Test on the result window, not anywhere else.

UPDATE To disable right-click

<SCRIPT TYPE="text/javascript"> 
<!-- 
//Disable right click script 
//visit http://www.rainbow.arch.scriptmania.com/scripts/ 
var message="Sorry, right-click has been disabled"; 
/////////////////////////////////// 
function clickIE() {if (document.all) {(message);return false;}} 
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) { 
if (e.which==2||e.which==3) {(message);return false;}}} 
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} 
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} 
document.oncontextmenu=new Function("return false") 
// --> 
</SCRIPT> 
Ashwin Singh
  • 7,197
  • 4
  • 36
  • 55
  • Have a look here http://jsbin.com/animub/edit#preview and please first click in the whitespace to select the window and then proceed. – Ashwin Singh Jul 09 '12 at 03:51
  • You do see that the code is working in the example. Maybe, you are doing something in copying the script. Have you included the jQuery library. The above needs jQuery to run. – Ashwin Singh Jul 09 '12 at 04:47
  • the 'return false' should be for eack of the 3 keycodes checked in the above javascript to work correctly. Edited the script above – user956424 Jul 10 '12 at 04:59