You've already forked mattlution
'初始化提交'
This commit is contained in:
20
plugins/com.verso.cordova.clipboard/LICENSE
Normal file
20
plugins/com.verso.cordova.clipboard/LICENSE
Normal file
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Verso Solutions LLC
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
68
plugins/com.verso.cordova.clipboard/README.md
Normal file
68
plugins/com.verso.cordova.clipboard/README.md
Normal file
@@ -0,0 +1,68 @@
|
||||
Clipboard
|
||||
=========
|
||||
|
||||
Clipboard management plugin for Cordova/PhoneGap that supports iOS, Android
|
||||
|
||||
Original Plugin: https://github.com/VersoSolutions/CordovaClipboard
|
||||
|
||||
We forked and updated this plugin to support HTML content copy & paste for both Android and iOS platform according to our needs
|
||||
1. Support added to copy html content
|
||||
2. Support added to copy/paste plain text from copied html content.
|
||||
|
||||
|
||||
## Usage
|
||||
Install the plugin using the CLI, for instance with PhoneGap:
|
||||
|
||||
cordova plugin add https://github.com/Anuj-Raghuvanshi/cordova-clipboard-plugin
|
||||
|
||||
The plugin creates the object `cordova.plugins.clipboard` with the methods `copy(text, onSuccess, onError)` and `paste(onSuccess, onError)`.
|
||||
|
||||
Example:
|
||||
|
||||
var text = "Hello World!";
|
||||
|
||||
cordova.plugins.clipboard.copy(text);
|
||||
|
||||
cordova.plugins.clipboard.paste(function (text) { alert(text); });
|
||||
|
||||
## Notes
|
||||
|
||||
### All platforms
|
||||
|
||||
- The plugin only works with text content.
|
||||
|
||||
### Windows Phone
|
||||
|
||||
- The Windows Phone platform doesn't allow applications to read the content of the clipboard. Using the `paste` method will return an error.
|
||||
|
||||
### Android
|
||||
|
||||
- The minimum supported API Level is 11. Make sure that `minSdkVersion` is larger or equal to 11 in `AndroidManifest.xml`.
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
This plugin was inspired by [ClipboardManagerPlugin](https://github.com/jacob/ClipboardManagerPlugin) (Android) and [ClipboardPlugin](https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/ClipboardPlugin) (iOS).
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Verso Solutions LLC
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
34
plugins/com.verso.cordova.clipboard/package.json
Normal file
34
plugins/com.verso.cordova.clipboard/package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "cordova-clipboard-plugin",
|
||||
"version": "0.0.3",
|
||||
"description": "Clipboard management plugin for Cordova/PhoneGap",
|
||||
"cordova": {
|
||||
"id": "com.verso.cordova.clipboard",
|
||||
"platforms": [
|
||||
"ios",
|
||||
"android"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Anuj-Raghuvanshi/cordova-clipboard-plugin"
|
||||
},
|
||||
"keywords": [
|
||||
"clipboard",
|
||||
"copy",
|
||||
"paste",
|
||||
"ecosystem:cordova",
|
||||
"cordova-ios",
|
||||
"cordova-android"
|
||||
],
|
||||
"engines": [{
|
||||
"name": "cordova",
|
||||
"version": ">=3.0.0"
|
||||
}],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/VersoSolutions/CordovaClipboard/issues"
|
||||
},
|
||||
"homepage": "https://github.com/VersoSolutions/CordovaClipboard#readme"
|
||||
}
|
||||
59
plugins/com.verso.cordova.clipboard/plugin.xml
Normal file
59
plugins/com.verso.cordova.clipboard/plugin.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="com.verso.cordova.clipboard"
|
||||
version="0.1.0">
|
||||
|
||||
<engines>
|
||||
<engine name="cordova" version=">=3.0.0" />
|
||||
</engines>
|
||||
|
||||
<name>Clipboard</name>
|
||||
|
||||
<description>Clipboard management plugin for Cordova/PhoneGap</description>
|
||||
|
||||
<author>Verso Solutions LLC</author>
|
||||
|
||||
<keywords>clipboard,copy,paste</keywords>
|
||||
|
||||
<license>MIT</license>
|
||||
|
||||
<js-module src="www/clipboard.js" name="Clipboard">
|
||||
<clobbers target="cordova.plugins.clipboard" />
|
||||
</js-module>
|
||||
|
||||
<!-- iOS -->
|
||||
<platform name="ios">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="Clipboard">
|
||||
<param name="ios-package" value="CDVClipboard" />
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<header-file src="src/ios/CDVClipboard.h" />
|
||||
<source-file src="src/ios/CDVClipboard.m" />
|
||||
</platform>
|
||||
|
||||
<!-- Android -->
|
||||
<platform name="android">
|
||||
<source-file src="src/android/Clipboard.java" target-dir="src/com/verso/cordova/clipboard" />
|
||||
|
||||
<config-file target="res/xml/config.xml" parent="/*">
|
||||
<feature name="Clipboard">
|
||||
<param name="android-package" value="com.verso.cordova.clipboard.Clipboard" />
|
||||
</feature>
|
||||
</config-file>
|
||||
</platform>
|
||||
|
||||
<!-- Windows Phone 8 -->
|
||||
<platform name="wp8">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="Clipboard">
|
||||
<param name="wp-package" value="Clipboard"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<source-file src="src/wp8/Clipboard.cs" />
|
||||
</platform>
|
||||
|
||||
</plugin>
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.verso.cordova.clipboard;
|
||||
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.PluginResult;
|
||||
import org.apache.cordova.CallbackContext;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipDescription;
|
||||
import android.text.Html;
|
||||
|
||||
public class Clipboard extends CordovaPlugin {
|
||||
|
||||
private static final String actionCopy = "copy";
|
||||
private static final String actionPaste = "paste";
|
||||
|
||||
@Override
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
ClipboardManager clipboard = (ClipboardManager) cordova.getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
|
||||
if (action.equals(actionCopy)) {
|
||||
try {
|
||||
String text = args.getString(0);
|
||||
//ClipData clip = ClipData.newPlainText("Text", text);
|
||||
String plainText = Html.fromHtml(text).toString();
|
||||
ClipData clip = ClipData.newHtmlText("html", plainText, text);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
callbackContext.success(text);
|
||||
|
||||
return true;
|
||||
} catch (JSONException e) {
|
||||
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
|
||||
} catch (Exception e) {
|
||||
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString()));
|
||||
}
|
||||
} else if (action.equals(actionPaste)) {
|
||||
|
||||
//if (!clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
|
||||
if (!clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)) {
|
||||
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.NO_RESULT));
|
||||
}
|
||||
|
||||
try {
|
||||
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
|
||||
String text = item.getText().toString();
|
||||
|
||||
if (text == null) text = "";
|
||||
|
||||
callbackContext.success(text);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
|
||||
@interface CDVClipboard : CDVPlugin {}
|
||||
|
||||
- (void)copy:(CDVInvokedUrlCommand*)command;
|
||||
- (void)paste:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
@end
|
||||
36
plugins/com.verso.cordova.clipboard/src/ios/CDVClipboard.m
Normal file
36
plugins/com.verso.cordova.clipboard/src/ios/CDVClipboard.m
Normal file
@@ -0,0 +1,36 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
#import <Cordova/CDVPluginResult.h>
|
||||
#import <MobileCoreServices/MobileCoreServices.h>
|
||||
#import "CDVClipboard.h"
|
||||
|
||||
@implementation CDVClipboard
|
||||
|
||||
- (void)copy:(CDVInvokedUrlCommand*)command {
|
||||
[self.commandDelegate runInBackground:^{
|
||||
NSString *html = [command.arguments objectAtIndex:0];
|
||||
NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSDictionary *dict = @{@"WebMainResource": @{@"WebResourceData": data, @"WebResourceFrameName": @"", @"WebResourceMIMEType": @"text/html", @"WebResourceTextEncodingName": @"UTF-8", @"WebResourceURL": @"about:blank"}};
|
||||
data = [NSPropertyListSerialization dataWithPropertyList:dict format:NSPropertyListXMLFormat_v1_0 options:0 error:nil];
|
||||
NSString *archive = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
NSAttributedString *decodedString = [[NSAttributedString alloc] initWithData:data
|
||||
options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType}
|
||||
documentAttributes:NULL
|
||||
error:NULL];
|
||||
[UIPasteboard generalPasteboard].items = @[@{@"Apple Web Archive pasteboard type": archive, (id)kUTTypeUTF8PlainText: [decodedString string]}];
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:archive];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)paste:(CDVInvokedUrlCommand*)command {
|
||||
[self.commandDelegate runInBackground:^{
|
||||
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
|
||||
NSString *text = [pasteboard valueForPasteboardType:@"public.text"];
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:text];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
58
plugins/com.verso.cordova.clipboard/src/wp8/Clipboard.cs
Normal file
58
plugins/com.verso.cordova.clipboard/src/wp8/Clipboard.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using WPCordovaClassLib.Cordova;
|
||||
using WPCordovaClassLib.Cordova.Commands;
|
||||
using WPCordovaClassLib.Cordova.JSON;
|
||||
|
||||
namespace Cordova.Extension.Commands
|
||||
{
|
||||
public class Clipboard : BaseCommand
|
||||
{
|
||||
public void copy(string options)
|
||||
{
|
||||
string text = "";
|
||||
|
||||
try
|
||||
{
|
||||
text = JsonHelper.Deserialize<string[]>(options)[0];
|
||||
}
|
||||
catch
|
||||
{
|
||||
DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
System.Windows.Clipboard.SetText(text);
|
||||
});
|
||||
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text));
|
||||
}
|
||||
catch
|
||||
{
|
||||
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void paste(string options)
|
||||
{
|
||||
string text = "";
|
||||
|
||||
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
text = System.Windows.Clipboard.GetText();
|
||||
|
||||
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text));
|
||||
}
|
||||
catch
|
||||
{
|
||||
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
34
plugins/com.verso.cordova.clipboard/www/clipboard.js
Normal file
34
plugins/com.verso.cordova.clipboard/www/clipboard.js
Normal file
@@ -0,0 +1,34 @@
|
||||
var cordova = require('cordova');
|
||||
|
||||
/**
|
||||
* Clipboard plugin for Cordova
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function Clipboard () {}
|
||||
|
||||
/**
|
||||
* Sets the clipboard content
|
||||
*
|
||||
* @param {String} text The content to copy to the clipboard
|
||||
* @param {Function} onSuccess The function to call in case of success (takes the copied text as argument)
|
||||
* @param {Function} onFail The function to call in case of error
|
||||
*/
|
||||
Clipboard.prototype.copy = function (text, onSuccess, onFail) {
|
||||
if (typeof text === "undefined" || text === null) text = "";
|
||||
cordova.exec(onSuccess, onFail, "Clipboard", "copy", [text]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the clipboard content
|
||||
*
|
||||
* @param {Function} onSuccess The function to call in case of success
|
||||
* @param {Function} onFail The function to call in case of error
|
||||
*/
|
||||
Clipboard.prototype.paste = function (onSuccess, onFail) {
|
||||
cordova.exec(onSuccess, onFail, "Clipboard", "paste", []);
|
||||
};
|
||||
|
||||
// Register the plugin
|
||||
var clipboard = new Clipboard();
|
||||
module.exports = clipboard;
|
||||
Reference in New Issue
Block a user