var Preact = require('preact'), h = require('preact').h, createClass = require('preact-compat').createClass, SupportedPlatforms = require('./supportedplatforms.jsx'), classNames = require('classnames'), ZeroClipboard = require('../js/lib/ZeroClipboard.js'); var Plugin = createClass({ shouldComponentUpdate: function(nextProps, nextState) { return this.props.plugin !== nextProps.plugin; }, setClipboardText: function() { if(this.props.plugin && this.props.flashEnabled) { var client = new ZeroClipboard(document.getElementById("copy-" + this.props.plugin.name)); var copyText = "cordova plugin add " + this.props.plugin.name; client.off(); client.on("copy", function(event) { event.clipboardData.setData("text/plain", copyText); }); } }, copyTextWithoutFlash: function() { if(!this.props.flashEnabled) { var range = document.createRange(); range.selectNode(this.getDOMNode().getElementsByClassName("cordova-add-command")[0]); var select = window.getSelection(); select.removeAllRanges(); select.addRange(range); try { document.execCommand("copy"); } catch(e) { // Silently fail for now } select.removeAllRanges(); } }, render: function() { if(!this.props.plugin) { // Empty card with loading wheel return (

Loading...

) } var license = this.props.plugin.license; if (license && license.length > 1) { license = license[0]; } var downloadField; var copyIcon; var npmLink = 'https://www.npmjs.com/package/' + this.props.plugin.name; if(this.props.plugin.downloadCount) { var downloadCount = this.props.plugin.downloadCount.toLocaleString(); downloadField =

{downloadCount} downloads last month

; } if(this.props.plugin) { copyIcon = ( ); } var classes = classNames({ 'container': true, 'plugin-results-result': true, 'plugins-featured': this.props.plugin.isOfficial }); return (

{this.props.plugin.name}

v{this.props.plugin.version} by {this.props.plugin.author}

{copyIcon}

{this.props.plugin.description}


{license}

{downloadField}

Last updated {this.props.plugin.modified} days ago

{"cordova plugin add " + this.props.plugin.name}
) }, componentDidMount: function() { this.setClipboardText(); if(this.props.plugin) { $(this.getDOMNode()).find(".plugins-copy-to-clipboard").tooltip(); } }, componentDidUpdate: function() { this.setClipboardText(); } }); function trackOutboundLink(url) { ga('send', 'event', 'outbound', 'click', url); } module.exports = Plugin;