kf5 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 067e0f1ed75a0789fa7b36b14a2ad25b767894fb
4
- data.tar.gz: ddb5dc544d6a5dfba2903f5dcc8c523bb1f2b31e
3
+ metadata.gz: d83a317cfcb4a8b7ce82d2842121e0c3bed1aaea
4
+ data.tar.gz: 15deb7bcb118dd873e7cd5e8447c814f4bb709d3
5
5
  SHA512:
6
- metadata.gz: fd12d8e5636bdc901f94785f7a90d11c6208a32f4d9c6d16515b847a31547e82d7a7f269aa352d933868165a05518d873f16b3c44ecf937484ca49f4383da359
7
- data.tar.gz: 7faeaf7f17290d95ad23222238d2afecd27a76641bcb9a024ef2b278ee9d3104dbd26dd3352f293c39e325db0aaee2416cdf7b0198b62e8321071ebd0bd40fc3
6
+ metadata.gz: 66f74b3e0e67130d5889aee6132965b0eab5ef79e455e0b9c1a0708af10c0c454946df090c6abff2266042a430d4fa9d35601a129dfd2c287522743500acbfb8
7
+ data.tar.gz: 699d0b568532a923af50228d1bc151347b0517da8e0e811979fc5e8d448ac09b1d8c0799fba256dd718e0b6767a49e587be77133b82d4c4d7243b40278938abf
@@ -1,3 +1,7 @@
1
+ # v0.4.0 / 2016-05-30
2
+
3
+ * Used kfs CDN instead of asset file.
4
+
1
5
  # v0.3.3 / 2015-11-17
2
6
 
3
7
  * Disable SSO if key is nil.
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Chen Yi-Cyuan
3
+ Copyright (c) 2015-2016 Chen, Yi-Cyuan
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -32,7 +32,7 @@ For rails, create config `config/initializers/kf5.rb`
32
32
  KF5.configure do |config|
33
33
  config.domain = "your.domain"
34
34
 
35
- # do not set key to disable SSO
35
+ # disable SSO if key is nil
36
36
  config.key = "your key of KF5 service"
37
37
 
38
38
  # 1: login for 30 days, 0: login for 30 minutes
@@ -76,10 +76,16 @@ In view, you can use `kf5_tag` to include javascript plugin.
76
76
  = kf5_tag
77
77
  ```
78
78
 
79
+ ### Turbolinks
80
+ If you're using turbolinks, add the following to js file:
81
+ ```JavaScript
82
+ //= require kf5.turbolinks
83
+ ```
84
+
79
85
  ## License
80
86
 
81
87
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
82
88
 
83
89
  ## Contact
84
90
  The project's website is located at https://github.com/emn178/kf5
85
- Author: emn178@gmail.com
91
+ Author: Chen, Yi-Cyuan (emn178@gmail.com)
@@ -1,14 +1,15 @@
1
- ;(function($, undefined) {
1
+ (function ($) {
2
2
  var widgets = $();
3
3
 
4
4
  $(document).on('page:before-unload', function store() {
5
- if(!widgets.length) {
5
+ if (!widgets.length) {
6
6
  widgets = $('#kf5-support-123456789');
7
- if(widgets.length) {
7
+ if (widgets.length) {
8
8
  widgets = $([widgets[0], widgets.prev()[0], widgets.prev().prev()[0]]);
9
9
  }
10
10
  }
11
11
  });
12
+
12
13
  $(document).on('page:load', function (argument) {
13
14
  $('body').append(widgets);
14
15
  });
@@ -1,3 +1,3 @@
1
1
  module KF5
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  module KF5
2
2
  module ViewHelper
3
3
  def kf5_tag
4
- javascript_include_tag "kf5.js", :id => "kf5-provide-supportBox", :"kf5-domain" => "#{KF5.configuration.domain}.kf5.com"
4
+ javascript_include_tag "//assets.kf5.com/supportbox/main.js", :id => "kf5-provide-supportBox", :"kf5-domain" => "#{KF5.configuration.domain}.kf5.com"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kf5
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chen Yi-Cyuan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-17 00:00:00.000000000 Z
11
+ date: 2016-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,7 +95,6 @@ files:
95
95
  - LICENSE.txt
96
96
  - README.md
97
97
  - Rakefile
98
- - app/assets/javascripts/kf5.js
99
98
  - app/assets/javascripts/kf5.turbolinks.js
100
99
  - kf5.gemspec
101
100
  - lib/kf5.rb
@@ -126,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
125
  version: '0'
127
126
  requirements: []
128
127
  rubyforge_project:
129
- rubygems_version: 2.4.8
128
+ rubygems_version: 2.5.1
130
129
  signing_key:
131
130
  specification_version: 4
132
131
  summary: A simple presenter pattern for ruby. It can work in rails.
@@ -1,609 +0,0 @@
1
- //= require kf5.turbolinks
2
-
3
- (function(window, config)
4
- {
5
- "use strict";
6
-
7
- var
8
- script = window.document.getElementById('kf5-provide-supportBox'),
9
- parts = script.src.split('//'),
10
- host = parts.length > 1 ? parts[0] + '//' + parts[1].split('/')[0] : '',
11
- kf5Domain = script.getAttribute('kf5-domain'),
12
- supportboxConfigURL = '//' + kf5Domain + '/supportbox/buttonconfig',
13
- _config = {
14
- btn_name : '帮助按钮',
15
- facade : '1',
16
- color : '#7A88FF',
17
- position : 'right',
18
- iframeURL : '//' + kf5Domain + '/supportbox/index',
19
- btn_icon : '//assets.kf5.com/supportbox/images/icon2.png',
20
- styleURL : '//assets.kf5.com/supportbox/css/btn.css',
21
- template : '<div id="kw-tab" class="kf5-support-btn" style="{{bg_color}}"> <img src="{{btn_icon}}" alt=""><span>{{title}}</span> </div> <div id="kw-block" class="kf5-support"> <a id="kw-close" class="kf5-close" title="关闭"><i class="kf5-icon-clear"></i></a> <div id="kw-loading" class="kf5-loading"> </div> <iframe id="kw-widget-iframe" src="" scrolling="no" frameborder="0"></iframe> </div>'
22
- };
23
-
24
- function KF5SupportBox(config)
25
- {
26
- this.config = config || {};
27
-
28
- this.init();
29
- }
30
-
31
- window.KF5SupportBox = KF5SupportBox;
32
-
33
- KF5SupportBox.prototype = {
34
-
35
- el: null,
36
-
37
- getElement: function(selector)
38
- {
39
- return window.document.getElementById(selector.replace('#', ''));
40
- },
41
-
42
- getOpt: function(key)
43
- {
44
- if(this.config.hasOwnProperty(key))
45
- {
46
- return this.config[key];
47
- }
48
- else
49
- {
50
- return _config[key];
51
- }
52
- },
53
-
54
- init: function()
55
- {
56
- this._prepareStyle();
57
-
58
- return this;
59
- },
60
-
61
- initElements: function()
62
- {
63
- this._prepareElement();
64
- this.append();
65
-
66
- this._bindEvents();
67
- },
68
-
69
- append: function()
70
- {
71
- window.document.body.appendChild(this.el);
72
-
73
- return this;
74
- },
75
-
76
- _prepareStyle: function()
77
- {
78
- var link = window.document.createElement('link');
79
-
80
- link.rel = 'styleSheet';
81
- link.type = 'text/css';
82
- link.href = this.getOpt('styleURL');
83
-
84
- var self = this;
85
- link.onload = function()
86
- {
87
- self.initElements();
88
- link.onload = null;
89
- };
90
-
91
- window.document.body.appendChild(link);
92
-
93
- return this;
94
- },
95
-
96
- _prepareElement: function()
97
- {
98
- var className = 'kf5-support-123456789';
99
-
100
- // 位置
101
- if(this.getOpt('position') === 'left')
102
- {
103
- className += ' kf5-left';
104
- }
105
- else
106
- {
107
- className += ' kf5-right'
108
- }
109
-
110
- // 外观
111
- className += ' kf5-style' + (parseInt(this.getOpt('facade')) || 1);
112
-
113
- // 设备
114
- if(this.getOpt('is_mobile'))
115
- {
116
- className += ' kf5-mobile';
117
- }
118
-
119
- this.el = window.document.createElement('div');
120
- this.el.setAttribute('class', className);
121
- this.el.setAttribute('id', 'kf5-support-123456789');
122
- this.el.innerHTML = this.getOpt('template')
123
- .replace('{{title}}', this.getOpt('btn_name') || '获取帮助')
124
- .replace('{{btn_icon}}', this.getOpt('btn_icon'))
125
- .replace('{{bg_color}}', this.getOpt('color') ? 'background:' + this.getOpt('color') : '');
126
-
127
- return this;
128
- },
129
-
130
- _bindEvents: function()
131
- {
132
- var self = this;
133
- this.getElement('#kw-tab').onclick = function()
134
- {
135
- self.open();
136
- };
137
-
138
- this.getElement('#kw-close').onclick = function()
139
- {
140
- self.close();
141
- };
142
-
143
- this.getElement('#kw-widget-iframe').onload = function()
144
- {
145
- // setTimeout(function()
146
- // {
147
- self.getElement('#kw-loading').style.display = 'none';
148
- // }, 2000);
149
-
150
- };
151
-
152
- if(cookie('kf5-supportBox-autoOpen'))
153
- {
154
- this.open();
155
- }
156
-
157
- return this;
158
- },
159
-
160
- loadIframe: function()
161
- {
162
- var iframe = this.getElement('#kw-widget-iframe');
163
-
164
- if(!iframe.getAttribute('src'))
165
- {
166
- iframe.setAttribute('src', this.getOpt('iframeURL'));
167
- }
168
-
169
- return this;
170
- },
171
-
172
- // resizeIframe: function(data)
173
- // {
174
- // var elem = this.getElement('#kw-block');
175
-
176
- // if(elem)
177
- // {
178
- // elem.style.height = parseFloat(data) + 'px';
179
- // }
180
- // },
181
-
182
- open: function(e)
183
- {
184
- if(!this.isOpened)
185
- {
186
- var self = this;
187
-
188
- this.loadIframe();
189
- slideDown(this.getElement('#kw-tab'), {duration: 200, easing: 'swing'});
190
- slideUp(self.getElement('#kw-block'), {duration: 200, easing: 'swing'});
191
-
192
- cookie('kf5-supportBox-autoOpen', 1, {expires: 3 / 24, path: '/'});
193
-
194
- this.isOpened = true;
195
- }
196
- },
197
-
198
- close: function(e)
199
- {
200
- // slideDown(this.getElement('#kw-block'), 200);
201
- // showElement(this.getElement('#kw-tab'));
202
- var self = this;
203
-
204
- slideDown(
205
- this.getElement('#kw-block'),
206
- {
207
- duration: 200,
208
- easing: 'swing',
209
- callback: function()
210
- {
211
- slideUp(
212
- self.getElement('#kw-tab'),
213
- {
214
- duration: 200,
215
- easing: 'swing'
216
- }
217
- );
218
- }
219
- }
220
- );
221
-
222
- cookie('kf5-supportBox-autoOpen', null, {path: '/'});
223
-
224
- this.isOpened = false;
225
- }
226
- };
227
-
228
- var supportbox;
229
- function onload()
230
- {
231
- if(supportbox)
232
- {
233
- return;
234
- }
235
-
236
- var script = window.document.createElement('script'),
237
- configURL = supportboxConfigURL;
238
-
239
- embed(configURL, function(win)
240
- {
241
- if(win.KF5_SUPPORTBOX_BUTTON && win.KF5_SUPPORTBOX_BUTTON.show)
242
- {
243
- supportbox = new KF5SupportBox(win.KF5_SUPPORTBOX_BUTTON);
244
-
245
- // 延时自动加载iframe
246
- // setTimeout(function()
247
- // {
248
- // supportbox.loadIframe();
249
- // }, 30 * 1000);
250
- }
251
- });
252
- }
253
-
254
- window.addEventListener('load', onload, false);
255
-
256
- if(!window.initializeKF5SupportBox)
257
- {
258
- // 暴露初始化方法,以解决特殊情况下load事件无法触发
259
- window.initializeKF5SupportBox = onload;
260
- }
261
-
262
- // allow cross origin operation
263
- window.addEventListener('message', function(e)
264
- {
265
- var context, cmd, data;
266
-
267
- if(e.data)
268
- {
269
- context = e.data.match(/^([^ ]+)(?: +(.*))?/);
270
- cmd = context[1];
271
- data = context[2];
272
- }
273
-
274
- if(cmd === 'CMD::showSupportbox')
275
- {
276
- if(supportbox)
277
- {
278
- supportbox.open();
279
- }
280
- }
281
- else if(cmd === 'CMD::hideSupportbox')
282
- {
283
- if(supportbox)
284
- {
285
- supportbox.close();
286
- }
287
- }
288
- else if(cmd === 'CMD::resizeIframe')
289
- {
290
- // supportbox.resizeIframe(data);
291
- }
292
- });
293
-
294
- function embed(mainJS, output)
295
- {
296
- var domain, doc, iframeWindow, iframeDoc,
297
- iframe = window.document.createElement("iframe");
298
-
299
- iframe.src = "javascript:false",
300
- iframe.title = "",
301
- iframe.role = "presentation",
302
- (iframe.frameElement || iframe).style.cssText = "display: none",
303
- window.document.body.appendChild(iframe);
304
- iframeWindow = iframe.contentWindow,
305
- iframeDoc = iframeWindow.document;
306
-
307
- try {
308
- doc = iframeDoc
309
- } catch (c) {
310
- domain = window.document.domain,
311
- iframe.src = 'javascript:var doc=document.open();doc.domain="' + domain + '";void(0);',
312
- doc = iframeDoc
313
- }
314
-
315
- doc.open().start = function() {
316
- if(output)
317
- {
318
- if(typeof output === 'object')
319
- {
320
- output.iframeWindow = iframeWindow;
321
- }
322
- else if(typeof output === 'function')
323
- {
324
- output(iframeWindow);
325
- }
326
- }
327
- },
328
-
329
- doc.write('<body onload="document.start();">'),
330
- doc.write('<script src="' + mainJS + '""></script>'),
331
- doc.close();
332
- }
333
-
334
- function getStyle(el, style)
335
- {
336
- var
337
- pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source,
338
- rmargin = /^margin/,
339
- rposition = /^(top|right|bottom|left)$/,
340
- rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" ),
341
-
342
- getStyles, curCSS;
343
-
344
- if ( window.getComputedStyle ) {
345
- getStyles = function( elem ) {
346
- return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
347
- };
348
-
349
- curCSS = function( elem, name, computed ) {
350
- var width, minWidth, maxWidth, ret,
351
- style = elem.style;
352
-
353
- computed = computed || getStyles( elem );
354
-
355
- // getPropertyValue is only needed for .css('filter') in IE9, see #12537
356
- ret = computed ? computed.getPropertyValue( name ) || computed[ name ] : undefined;
357
-
358
- if ( computed ) {
359
-
360
- // if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
361
- // ret = jQuery.style( elem, name );
362
- // }
363
-
364
- // A tribute to the "awesome hack by Dean Edwards"
365
- // Chrome < 17 and Safari 5.0 uses "computed value" instead of "used value" for margin-right
366
- // Safari 5.1.7 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
367
- // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
368
- if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
369
-
370
- // Remember the original values
371
- width = style.width;
372
- minWidth = style.minWidth;
373
- maxWidth = style.maxWidth;
374
-
375
- // Put in the new values to get a computed value out
376
- style.minWidth = style.maxWidth = style.width = ret;
377
- ret = computed.width;
378
-
379
- // Revert the changed values
380
- style.width = width;
381
- style.minWidth = minWidth;
382
- style.maxWidth = maxWidth;
383
- }
384
- }
385
-
386
- // Support: IE
387
- // IE returns zIndex value as an integer.
388
- return ret === undefined ?
389
- ret :
390
- ret + "";
391
- };
392
- } else if ( document.documentElement.currentStyle ) {
393
- getStyles = function( elem ) {
394
- return elem.currentStyle;
395
- };
396
-
397
- curCSS = function( elem, name, computed ) {
398
- var left, rs, rsLeft, ret,
399
- style = elem.style;
400
-
401
- computed = computed || getStyles( elem );
402
- ret = computed ? computed[ name ] : undefined;
403
-
404
- // Avoid setting ret to empty string here
405
- // so we don't default to auto
406
- if ( ret == null && style && style[ name ] ) {
407
- ret = style[ name ];
408
- }
409
-
410
- // From the awesome hack by Dean Edwards
411
- // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
412
-
413
- // If we're not dealing with a regular pixel number
414
- // but a number that has a weird ending, we need to convert it to pixels
415
- // but not position css attributes, as those are proportional to the parent element instead
416
- // and we can't measure the parent instead because it might trigger a "stacking dolls" problem
417
- if ( rnumnonpx.test( ret ) && !rposition.test( name ) ) {
418
-
419
- // Remember the original values
420
- left = style.left;
421
- rs = elem.runtimeStyle;
422
- rsLeft = rs && rs.left;
423
-
424
- // Put in the new values to get a computed value out
425
- if ( rsLeft ) {
426
- rs.left = elem.currentStyle.left;
427
- }
428
- style.left = name === "fontSize" ? "1em" : ret;
429
- ret = style.pixelLeft + "px";
430
-
431
- // Revert the changed values
432
- style.left = left;
433
- if ( rsLeft ) {
434
- rs.left = rsLeft;
435
- }
436
- }
437
-
438
- // Support: IE
439
- // IE returns zIndex value as an integer.
440
- return ret === undefined ?
441
- ret :
442
- ret + "" || "auto";
443
- };
444
- }
445
-
446
- return curCSS && curCSS(el, style);
447
- }
448
-
449
- var easing = {
450
-
451
- swing: function(p)
452
- {
453
- return 0.5 - Math.cos( p * Math.PI ) / 2;
454
- },
455
-
456
- linear: function(p)
457
- {
458
- return p;
459
- }
460
- };
461
-
462
- function slideUp(elem, options)
463
- {
464
- var originalStyle = elem.getAttribute('style');
465
- elem.style.display = 'block';
466
- var originalHeight = parseInt(getStyle(elem, 'height'));
467
-
468
- elem.style.height = '0px';
469
-
470
- var duration = options.duration || 500;
471
- var tStart = Date.now(),
472
- percent = 0,
473
- timer = setInterval(function()
474
- {
475
- percent = (Date.now() - tStart) / duration;
476
- percent = percent > 1 ? 1 : percent;
477
-
478
- elem.style.height = (easing[options.easing || 'swing'](percent)
479
- * originalHeight) + 'px';
480
-
481
- if(percent >= 1)
482
- {
483
- clearInterval(timer);
484
- timer = null;
485
-
486
- if(originalStyle)
487
- {
488
- elem.setAttribute('style', originalStyle);
489
- }
490
- else
491
- {
492
- elem.removeAttribute('style');
493
- }
494
- elem.style.display = 'block';
495
-
496
- options.callback && options.callback.call(elem);
497
- }
498
- }, 1000 / 60);
499
- }
500
-
501
- function slideDown(elem, options)
502
- {
503
- var originalStyle = elem.getAttribute('style');
504
- elem.style.display = 'block';
505
-
506
- var originalHeight = parseInt(getStyle(elem, 'height'));
507
-
508
- var duration = options.duration || 500;
509
- var tStart = Date.now(),
510
- percent = 0,
511
- timer = setInterval(function()
512
- {
513
- percent = (Date.now() - tStart) / duration;
514
- percent = percent > 1 ? 1 : percent;
515
-
516
- elem.style.height = (easing[options.easing || 'swing'](1 - percent)
517
- * originalHeight) + 'px';
518
-
519
- if(percent >= 1)
520
- {
521
- clearInterval(timer);
522
- timer = null;
523
-
524
- if(originalStyle)
525
- {
526
- elem.setAttribute('style', originalStyle);
527
- }
528
- else
529
- {
530
- elem.removeAttribute('style');
531
- }
532
- elem.style.display = 'none';
533
-
534
- options.callback && options.callback.call(elem);
535
- }
536
- }, 1000 / 60);
537
- }
538
-
539
- function hideElement(el)
540
- {
541
- el.style.display = 'none';
542
- }
543
-
544
- function showElement(el)
545
- {
546
- el.style.display = 'block';
547
- }
548
-
549
- function cookie(name, value, options)
550
- {
551
- if (typeof value != 'undefined')
552
- { // name and value given, set cookie
553
- options = options || {};
554
- if (value === null) {
555
- value = '';
556
- options.expires = -1;
557
- }
558
- var expires = '';
559
- if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
560
- var date;
561
- if (typeof options.expires == 'number') {
562
- date = new Date();
563
- date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
564
- } else {
565
- date = options.expires;
566
- }
567
- expires = '; expires=' + date.toUTCString();
568
- }
569
- var path = options.path ? '; path=' + (options.path) : '';
570
- var domain = options.domain ? '; domain=' + (options.domain) : '';
571
- var secure = options.secure ? '; secure' : '';
572
- document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
573
- } else {
574
- var cookieValue = null;
575
- if (document.cookie && document.cookie != '') {
576
- var cookies = document.cookie.split(';');
577
- for (var i = 0; i < cookies.length; i++) {
578
- var cookie = cookies[i].replace(/^\s+|\s+$/g, '');
579
- if (cookie.substring(0, name.length + 1) == (name + '=')) {
580
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
581
- break;
582
- }
583
- }
584
- }
585
- return cookieValue;
586
- }
587
- }
588
-
589
- function isPC()
590
- {
591
- var userAgentInfo = navigator.userAgent;
592
- var Agents = ['Android', 'iPhone',
593
- 'SymbianOS', 'Windows Phone',
594
- 'iPad', 'iPod'];
595
- var flag = true;
596
-
597
- for(var i = 0; i < Agents.length; i++)
598
- {
599
- if(userAgentInfo.indexOf(Agents[i]) !== -1)
600
- {
601
- flag = false;
602
- break;
603
- }
604
- }
605
-
606
- return flag;
607
- }
608
-
609
- })(window);