Skip to content

Commit

Permalink
feat: send hostname (#28)
Browse files Browse the repository at this point in the history
feat: send hostname
  • Loading branch information
kyuwoo-choi committed Apr 12, 2018
2 parents 7b61464 + 4d02efb commit db9ea39
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Canvas image editor

## Dependency
* [fabric.js](https://github.com/kangax/fabric.js/releases/tag/v1.6.7) >=1.6.7
* [tui.code-snippet](https://github.com/nhnent/tui.code-snippet/releases/tag/v1.2.5) >=1.2.5
* [tui.code-snippet](https://github.com/nhnent/tui.code-snippet/releases/tag/v1.2.5) >=1.3.0

## Test Environment
### PC
Expand Down
2 changes: 1 addition & 1 deletion examples/example01-basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
<div class="tui-image-editor"></div>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.6.7/fabric.js"></script>
<script type="text/javascript" src="https://unpkg.com/tui-code-snippet@1.3.0/dist/tui-code-snippet.min.js"></script>
<script type="text/javascript" src="https://uicdn.toast.com/tui.code-snippet/v1.3.0/tui-code-snippet.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/nhnent/tui.component.colorpicker/1.0.2/dist/colorpicker.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion examples/example02-mobile.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
<p class="msg">Menu Scrolling <b>Left ⇔ Right</b></p>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.6.7/fabric.js"></script>
<script type="text/javascript" src="https://unpkg.com/tui-code-snippet@1.3.0/dist/tui-code-snippet.min.js"></script>
<script type="text/javascript" src="https://uicdn.toast.com/tui.code-snippet/v1.3.0/tui-code-snippet.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/nhnent/tui.component.colorpicker/1.0.2/dist/colorpicker.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion src/js/imageEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const {isUndefined, forEach, CustomEvents} = snippet;
* @param {Object} [option] - Canvas max width & height of css
* @param {number} option.cssMaxWidth - Canvas css-max-width
* @param {number} option.cssMaxHeight - Canvas css-max-height
* @param {boolean} [options.usageStatistics=true] - send hostname to google analytics
* @param {Boolean} [option.usageStatistics=true] - Let us know the hostname. If you don't want to send the hostname, please set to false.
*/
class ImageEditor {
constructor(wrapper, option) {
Expand Down
5 changes: 5 additions & 0 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
import {forEach, imagePing} from 'tui-code-snippet';
const {min, max} = Math;
let hostnameSent = false;

module.exports = {
/**
Expand Down Expand Up @@ -78,6 +79,10 @@ module.exports = {
*/
sendHostName() {
const {hostname} = location;
if (hostnameSent) {
return;
}
hostnameSent = true;

imagePing('https://www.google-analytics.com/collect', {
v: 1,
Expand Down
19 changes: 10 additions & 9 deletions test/imageEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ import snippet from 'tui-code-snippet';
import ImageEditor from '../src/js/imageEditor';

describe('ImageEditor', () => {
// hostnameSent module scope variable can not be reset.
// maintain cases with xit as it always fail, if you want to test these cases, change xit to fit one by one
describe('constructor', () => {
let imageEditor;
let imageEditor, el;

beforeEach(() => {
el = document.createElement('div');
spyOn(snippet, 'imagePing');
});

afterEach(() => {
imageEditor.destroy();
});

it('should send hostname by default', () => {
const el = document.createElement('div');
spyOn(snippet, 'imagePing');

xit('should send hostname by default', () => {
imageEditor = new ImageEditor(el);

expect(snippet.imagePing).toHaveBeenCalled();
});

it('should not send hostname on usageStatistics option false', () => {
const el = document.createElement('div');
spyOn(snippet, 'imagePing');

xit('should not send hostname on usageStatistics option false', () => {
imageEditor = new ImageEditor(el, {
usageStatistics: false
});
Expand Down

0 comments on commit db9ea39

Please sign in to comment.