2011-10-03 13 views
0

「コピーをダウンロード」リボンボタンのすぐにカスタムJavaScript機能をアタッチしたいと思います。リボンボタンを使用してファイルをダウンロードするための分析機能を提供します。OOTBリボンボタンにJavascript機能をアタッチする

私はこのコードを試してみましたが、動作していないよう:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"> 
    </script> 
    <script> 
    _spBodyOnLoadFunctionNames.push("Trackdownloads"); 

    function Trackdownloads(){ 

     debugger; 
     $("a[id='Ribbon.Documents.Copies.Download-Large']").live("click", 
        function() { 
         alert('hello'); 
        } 
      ); 

    } 

    </script> 

この作業を取得する方法任意のアイデアを?

答えて

1

私の問題の解決策が見つかりました。 実際には、ボタンにjavascript関数を接続することは、これを実装する正しい方法ではありません。 正しい実装は、OOTBボタンをカスタムボタンに置​​き換え、カスタムJavaScript関数を呼び出して目的のアクションを実行することです。

http://msdn.microsoft.com/en-us/library/ff407619.aspx

0

あなたはリボンでボタンを上書きしたい場合。カスタムページコンポーネントを作成することをお勧めします。例:

Type.registerNamespace('Company.Project.Ribbon.PageComponent'); 

Company.Project.Ribbon.PageComponent = function (PageComponentId) { 
    this._pageComponentId = PageComponentId; 
    Company.Project.Ribbon.PageComponent.initializeBase(this); 
} 

Company.Project.Ribbon.PageComponent.prototype = 
{ 
    _pageComponentId: "PageComponentIDHolder", 

    getId: function() { 
     return this._pageComponentId; 
    }, 
    init: function() { 
     this._myCommandList = ['DownloadCopy']; 
     this._myHandledCommands = {}; 
     this._myHandledCommands['DownloadCopy'] = Function.createDelegate(this, this.CMD1_Handler); 
    }, 
    getFocusedCommands: function() { 
     return this._myCommandList; 
    }, 
    getGlobalCommands: function() { 
     return this._myCommandList; 
    }, 
    canHandleCommand: function (commandId) { 
     var canHandle = this._myHandledCommands[commandId]; 

     if (canHandle) 
      return true; 
     else 
      return false; 
    }, 
    handleCommand: function (commandId, properties, sequence) { 
     return this._myHandledCommands[commandId](commandId, properties, sequence); 
    }, 
    isFocusable: function() { 
     return true; 
    }, 
    CMD1_Handler: function (commandId, properties, sequence) { 
     alert('Download a copy-button was clicked'); 
    } 
} 

Company.Project.Ribbon.PageComponent.registerClass('Company.Project.Ribbon.PageComponent', CUI.Page.PageComponent) 
NotifyScriptLoadedAndExecuteWaitingJobs("/_layouts/custompagecomponents/PageComponent.js"); 



function init2() { 
    var instance = new Company.Project.Ribbon.PageComponent("ComponentID"); 
    SP.Ribbon.PageManager.get_instance().addPageComponent(instance); 
} 

function init1() { 
    ExecuteOrDelayUntilScriptLoaded(init2, 'sp.ribbon.js'); 
} 
ExecuteOrDelayUntilScriptLoaded(init1, '/_layouts/custompagecomponents/PageComponent.js');