Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AMD/CommonJS wrapper #82

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
bower_components
.idea
npm-debug.log
4 changes: 2 additions & 2 deletions dest/ng-clip.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions example/bootstrap-tooltip.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="../bower_components/angular/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.11.0/ui-bootstrap-tpls.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.11.0/ui-bootstrap-tpls.js"></script>
<script src="../bower_components/zeroclipboard/dist/ZeroClipboard.min.js"></script>
<script src="../src/ngClip.js"></script>
</head>
Expand Down Expand Up @@ -36,7 +36,7 @@ <h1>ngClip <small>example</small></h1>
var myapp = angular.module('myapp', ['ngClipboard', 'ui.bootstrap']);

myapp.config(['ngClipProvider', function(ngClipProvider) {
ngClipProvider.setPath("../bower_components/zeroclipboard/ZeroClipboard.swf");
ngClipProvider.setPath("../bower_components/zeroclipboard/dist/ZeroClipboard.swf");
}]);

myapp.controller('myctrl', function ($scope) {
Expand All @@ -46,4 +46,4 @@ <h1>ngClip <small>example</small></h1>


</body>
</html>
</html>
4 changes: 2 additions & 2 deletions example/ng-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1>ngClip <small>example</small></h1>
var myapp = angular.module('myapp', ["ngClipboard"]);

myapp.config(['ngClipProvider', function(ngClipProvider) {
ngClipProvider.setPath("../bower_components/zeroclipboard/ZeroClipboard.swf");
ngClipProvider.setPath("../bower_components/zeroclipboard/dist/ZeroClipboard.swf");
}]);

myapp.controller('myctrl', function ($scope) {
Expand All @@ -41,4 +41,4 @@ <h1>ngClip <small>example</small></h1>
</script>

</body>
</html>
</html>
23 changes: 23 additions & 0 deletions example/requirejs/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

define([
'angular',
'ng-clip'
], function(angular) {
var myapp = angular.module('myapp', ["ngClipboard"]);

myapp.config(['ngClipProvider', function (ngClipProvider) {
ngClipProvider.setPath("../../bower_components/zeroclipboard/dist/ZeroClipboard.swf");
}]);

myapp.controller('myctrl', function ($scope) {
$scope.fallback = function (copy) {
window.prompt('Press cmd+c to copy the text below.', copy);
};

$scope.showMessage = function () {
console.log("clip-click works!");
};
});
}
);
49 changes: 49 additions & 0 deletions example/requirejs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!doctype html>
<html>
<head>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div>
<div class="container" ng-controller="myctrl">

<div class="page-header">
<h1>ngClip <small>example</small></h1>
</div>

<form>
<div class="form-group">
<label >Copy #1</label>
<input type="text" class="form-control" placeholder="Enter text to copy" ng-model="copy1">
</div>
<button class="btn btn-default" clip-copy="copy1">Copy!</button>

<br/><br/><br/>

<div class="form-group">
<label >Copy #2 with fallback for users without flash</label>
<p>Try disabling flash to see a graceful fallback</p>
<input type="text" class="form-control" placeholder="Enter text to copy" ng-model="copy2">
</div>
<button class="btn btn-default" clip-copy="copy2" clip-click-fallback="fallback(copy)">Copy!</button>

<br/><br/><br/>

<div class="form-group">
<label >Copy #3 with with clip-click</label>
<input type="text" class="form-control" placeholder="Enter text to copy" ng-model="copy3">
</div>
<button class="btn btn-default" clip-copy="copy3" clip-click="showMessage()">Copy!</button>

<br/><br/><br/>

<textarea class="form-control" rows="3" placeholder="paste here"></textarea>
</form>
</div>
</div>

<script data-main="require-config" src="../../bower_components/requirejs/require.js"></script>

</body>
</html>
30 changes: 30 additions & 0 deletions example/requirejs/require-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";

require.config({
paths: {
angular: '../../bower_components/angular/angular.min',
'ng-clip': '../../dest/ng-clip.min',
'zeroclipboard': '../../bower_components/zeroclipboard/dist/ZeroClipboard.min'
},
shim: {
angular: { exports: 'angular' },
'ng-clip': {
deps: ['angular']
}
},
priority: [
'angular'
]
});

require(
[
'angular',
'app'
], function(angular, app) {
var $html = angular.element(document.getElementsByTagName('html')[0]);
angular.element().ready(function() {
angular.bootstrap(document, ['myapp']);
});
}
);
145 changes: 0 additions & 145 deletions npm-debug.log

This file was deleted.

14 changes: 12 additions & 2 deletions src/ngClip.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/*jslint node: true */
/*global ZeroClipboard */

(function(window, angular, undefined) {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. register as an anonymous module.
define(['exports', 'angular', 'zeroclipboard'], factory);
} else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
// CommonJS
factory(exports, require('angular'), require('zeroclipboard'));
} else {
factory((root.ngClip = {}), root.angular, root.ZeroClipboard);
}
}(this, function(window, angular, ZeroClipboard) {
'use strict';

angular.module('ngClipboard', []).
Expand Down Expand Up @@ -89,4 +99,4 @@
}
};
}]);
})(window, window.angular);
}));