﻿/***************************************************************************************
$Workfile: ClipboardUtilities.js $
$Author: Syed Ghulam Akbar $
$Revision: 1 $
$Created Date: 02/01/07 03:15 PM $
$Description: Contains the JavaScript utilities related to the clip-board
***************************************************************************************/

// The JavaScript class to expose the Clipboard functions
function ClipboardManager()
{
    // This functions returns true if the Clipboard is available for cut, copy and paste operations
    this.IsAvailable = function ()
    {
        // Currently this library only support operation using the clipboardData data. This can be later
        // extended to support the createTextRange, FireFox,etc.
        if (window.clipboardData)
            return true;
        else
            return false;
    }
    
    // Copies the given type of object to the clip-board data. The first parameter is the type
    // of the object being copied to the clipboard i.e. TEXT, HTML, etc
    this.copyToClibpoard = function (objectType, objectToCopy)
    {
        // Only go-ahead if the clip-board is available
        if (this.IsAvailable())
        {
            window.clipboardData.setData(objectType,objectToCopy);
        }
    }
}

// Copies the given text to the clip-board data
function copyTextToClibpoard(textToCopy)
{
    var clipboardMgr = new ClipboardManager();
    clipboardMgr.copyToClibpoard("Text", textToCopy);
    return true;
}

// Copies the text of the given HTML DOM object to clipboard
function copyHTMLControlToClibpoard(objectID)
{
    // First get the object referecne
    objSource = document.getElementById(objectID);
    
    if (objSource && objSource.innerText)
    {
        copyTextToClibpoard(objSource.innerText)
        return true;
    }
    else
        return false;
}

