GitHub Custom Emojis

Add custom emojis from json source

目前為 2016-03-07 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name GitHub Custom Emojis
  3. // @version 0.1.4
  4. // @description Add custom emojis from json source
  5. // @namespace https://github.com/StylishThemes
  6. // @include /https?://((gist)\.)?github\.com/
  7. // @grant GM_addStyle
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_xmlhttpRequest
  11. // @grant GM_info
  12. // @run-at document-end
  13. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js
  14. // @require https://greasyfork.org/scripts/16936-ichord-caret-js/code/ichord-Caretjs.js?version=106431
  15. // @require https://greasyfork.org/scripts/16996-ichord-at-js-mod/code/ichord-Atjs-mod.js?version=109194
  16. // @require https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.1.2/js/ion.rangeSlider.min.js
  17. // ==/UserScript==
  18. /* global jQuery, GM_addStyle, GM_getValue, GM_setValue, GM_xmlhttpRequest, GM_info */
  19. /* eslint-disable indent, quotes */
  20. (function($) {
  21. 'use strict';
  22.  
  23. var ghe = {
  24.  
  25. version : GM_info.script.version,
  26.  
  27. vars : {
  28. // delay until package.json allowed to load
  29. delay : 8.64e7, // 24 hours in milliseconds
  30.  
  31. // base url to fetch package.json
  32. root : 'https://raw.githubusercontent.com/StylishThemes/GitHub-Custom-Emojis/master/',
  33. emojiClass : 'ghe-custom-emoji',
  34. emojiTemplate : ':_${name}:',
  35. maxEmojiZoom : 3,
  36. maxEmojiHeight : 150,
  37.  
  38. // Keyboard shortcut to open panel
  39. keyboardOpen : 'g+=',
  40. keyboardDelay : 1000
  41. },
  42.  
  43. regex : {
  44. // nodes to skip while traversing the dom
  45. skipElm : /^(script|style|svg|iframe|br|meta|link|textarea|input|code|pre)$/i,
  46. // emoji template
  47. template : /\$\{name\}/,
  48. // character to escape in regex
  49. charsToEsc : /[-\/\\^$*+?.()|[\]{}]/g
  50. },
  51.  
  52. defaults : {
  53. activeZoom : 1.8,
  54. caseSensitive : false,
  55. rangeHeight : '20;40', // min;max as set by ion.rangeSlider
  56. insertAsImage : false,
  57. // emoji json sources
  58. sources : [
  59. 'https://raw.githubusercontent.com/StylishThemes/GitHub-Custom-Emojis/master/collections/emoji-custom.json',
  60. 'https://raw.githubusercontent.com/StylishThemes/GitHub-Custom-Emojis/master/collections/emoji-crazy-rabbit.json',
  61. 'https://raw.githubusercontent.com/StylishThemes/GitHub-Custom-Emojis/master/collections/emoji-onion-head.json'
  62. ]
  63. },
  64.  
  65. // emoji json stored here
  66. collections : {},
  67.  
  68. // GitHub ajax containers
  69. containers : [
  70. '#js-pjax-container',
  71. '#js-repo-pjax-container',
  72. '.js-contribution-activity',
  73. '.more-repos'
  74. ],
  75.  
  76. // mutant observers to disconnect after ajax load
  77. previewObserver : [],
  78. // promises used when loading JSON
  79. promises : {},
  80.  
  81. getStoredValues : function() {
  82. var defaults = this.defaults;
  83. this.settings = {
  84. rangeHeight : GM_getValue('rangeHeight', defaults.rangeHeight),
  85. activeZoom : GM_getValue('activeZoom', defaults.activeZoom),
  86. caseSensitive : GM_getValue('caseSensitive', defaults.caseSensitive),
  87. insertAsImage : GM_getValue('insertAsImage', defaults.insertAsImage),
  88. sources : GM_getValue('sources', defaults.sources),
  89.  
  90. date : GM_getValue('date', 0)
  91. };
  92.  
  93. this.collections = GM_getValue('collections', {});
  94.  
  95. debug('Retrieved stored values', this.settings);
  96. },
  97.  
  98. storeVal : function(key, set, $el) {
  99. var tmp,
  100. val = set[key];
  101. GM_setValue(key, val);
  102. if (typeof val === 'boolean') {
  103. $el.prop('checked', val);
  104. } else {
  105. $el.val(val);
  106. }
  107. // update sliders
  108. if ($el.hasClass('ghe-height')) {
  109. tmp = val.split(';');
  110. $el.data('ionRangeSlider').update({
  111. from: tmp[0],
  112. to: tmp[1]
  113. });
  114. } else if ($el.hasClass('ghe-zoom')) {
  115. $el.data('ionRangeSlider').update({
  116. from: val
  117. });
  118. }
  119. },
  120.  
  121. setStoredValues : function(reset) {
  122. var $el, tmp, len, indx,
  123. s = ghe.settings,
  124. d = ghe.defaults,
  125. $panel = $('#ghe-settings-inner');
  126.  
  127. ghe.busy = true;
  128. ghe.storeVal('caseSensitive', reset ? d : s, $panel.find('.ghe-case'));
  129. ghe.storeVal('insertAsImage', reset ? d : s, $panel.find('.ghe-image'));
  130. ghe.storeVal('activeZoom', reset ? d : s, $panel.find('.ghe-zoom'));
  131. ghe.storeVal('rangeHeight', reset ? d : s, $panel.find('.ghe-height'));
  132.  
  133. GM_setValue('collections', this.collections);
  134. GM_setValue('date', s.date);
  135.  
  136. if (reset) {
  137. // add defaults back into source list; but don't remove any new stuff
  138. len = d.sources.length;
  139. for (indx = 0; indx < len; indx++) {
  140. if (s.sources.indexOf(d.sources[indx]) < 0) {
  141. s.sources[s.sources.length] = d.sources[indx];
  142. }
  143. }
  144. }
  145. tmp = s.sources;
  146. len = tmp.length;
  147. GM_setValue('sources', tmp);
  148. for (indx = 0; indx < len; indx++) {
  149. if ($panel.find('.ghe-source').eq(indx).length) {
  150. $el = $panel
  151. .find('.ghe-source-input')
  152. .eq(indx)
  153. .attr('data-url', tmp[indx]);
  154. } else {
  155. $el = $(ghe.sourceHTML)
  156. .appendTo($panel.find('.ghe-sources'))
  157. .find('.ghe-source-input')
  158. .attr('data-url', tmp[indx]);
  159. }
  160. // only show file name when not focused
  161. ghe.showFileName($el);
  162. }
  163. // remove extras
  164. $panel.find('.ghe-source').filter(':gt(' + len + ')').remove();
  165. if (reset) {
  166. this.updateSettings();
  167. }
  168.  
  169. debug((reset ? 'Resetting' : 'Saving') + ' current values & updating panel', s);
  170. ghe.busy = false;
  171. },
  172.  
  173. updateSettings : function() {
  174. this.isUpdating = true;
  175. var settings = this.settings,
  176. $panel = $('#ghe-settings-inner');
  177. settings.rangeHeight = $panel.find('.ghe-height').val();
  178. settings.activeZoom = $panel.find('.ghe-zoom').val();
  179. settings.insertAsImage = $panel.find('.ghe-image').is(':checked');
  180. settings.caseSensitive = $panel.find('.ghe-case').is(':checked');
  181. settings.sources = $panel.find('.ghe-source-input').map(function(){
  182. return $(this).attr('data-url');
  183. }).get();
  184.  
  185. debug('Updating user settings', settings);
  186. this.updateStyleSheet();
  187. this.isUpdating = false;
  188. },
  189.  
  190. loadEmojiJson : function(update) {
  191. // only load emoji.json once a day, or after a forced update
  192. if (update || (new Date().getTime() > this.settings.date + this.vars.delay)) {
  193. var indx,
  194. promises = [],
  195. sources = this.settings.sources,
  196. len = sources.length;
  197. for (indx = 0; indx < len; indx++) {
  198. promises[promises.length] = this.fetchCustomEmojis(sources[indx]);
  199. }
  200. $.when.apply(null, promises).done(function(){
  201. ghe.checkPage();
  202. ghe.promises = [];
  203. ghe.settings.date = new Date().getTime();
  204. });
  205. }
  206. },
  207.  
  208. fetchCustomEmojis : function(url) {
  209. if (!this.promises[url]) {
  210. this.promises[url] = $.Deferred(function(defer) {
  211. debug('Fetching custom emoji list', url);
  212. GM_xmlhttpRequest({
  213. method : 'GET',
  214. url : url,
  215. onload : function(response) {
  216. var json = false;
  217. try {
  218. json = JSON.parse(response.responseText);
  219. } catch (err) {
  220. debug('Invalid JSON', url);
  221. return defer.reject();
  222. }
  223. if (json && json[0].name) {
  224. // save url to make removing the entry easier
  225. json[0].url = url;
  226. ghe.collections[json[0].name] = json;
  227. debug('Adding "' + json[0].name + '" Emoji Collection');
  228. }
  229. return defer.resolve();
  230. }
  231. });
  232. }).promise();
  233. }
  234. return this.promises[url];
  235. },
  236.  
  237. // Using: document.evaluate('//*[text()="tuzki"]', document.body, null,
  238. // XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);
  239. // to find matching content as it is much faster than scanning each node
  240. // sometimes it misses things...
  241. checkPage : function(node) {
  242. this.isUpdating = true;
  243. // not sure why but document evaluate doesn't work on wiki page
  244. // preview tab, so we need to search the entire document
  245. if ($('#wiki-wrapper').length) {
  246. node = null;
  247. }
  248. var indx = 0,
  249. parts = this.vars.emojiTemplate.split('${name}'), // parts = [':_', ':']
  250. // adding "//" starts from document, so if node is defined, don't
  251. // include it so the search starts from the node
  252. path = (node ? '' : '//') + '*[contains(text(),"' + parts[0] + '")]',
  253. nodes = document.evaluate(path, node || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null),
  254. len = nodes.snapshotLength;
  255. try {
  256. node = nodes.snapshotItem(indx);
  257. while (node && indx++ < len) {
  258. if (!ghe.regex.skipElm.test(node.nodeName)) {
  259. ghe.findEmoji(node);
  260. }
  261. node = nodes.snapshotItem(indx);
  262. }
  263. } catch (e) {
  264. debug('Nothing to replace!', e);
  265. }
  266. this.isUpdating = false;
  267. },
  268.  
  269. findEmoji : function(node) {
  270. var indx, len, group, match, matchesLen,
  271. regex = ghe.regex.nameRegex,
  272. matches = [],
  273. emojis = this.collections,
  274. str = node.textContent;
  275. while ((match = regex.exec(str)) !== null) {
  276. matches[matches.length] = match[1];
  277. }
  278. if (matches && matches[0]) {
  279. matchesLen = matches.length;
  280. for (group in emojis) {
  281. if (emojis.hasOwnProperty(group)) {
  282. len = emojis[group].length;
  283. for (indx = 0; indx < len; indx++) {
  284. for (match = 0; match < matchesLen; match++) {
  285. if (matches[match] === emojis[group][indx].name) {
  286. debug('found "' + matches[match] + '" in "' + node.textContent + '"');
  287. ghe.replaceText(node, emojis[group][indx]);
  288. }
  289. }
  290. }
  291. }
  292. }
  293. }
  294. },
  295.  
  296. replaceText : function(node, emoji) {
  297. var data, pos, imgnode, middlebit, endbit,
  298. isCased = this.settings.caseSensitive,
  299. name = this.vars.emojiTemplate.replace(ghe.regex.template, emoji.name),
  300. skip = 0;
  301. name = isCased ? name : name.toUpperCase();
  302. // Code modified from highlight-5 (MIT license)
  303. // http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
  304. if (node.nodeType === 3) {
  305. data = isCased ? node.data : node.data.toUpperCase();
  306. pos = data.indexOf(name);
  307. pos -= (data.substr(0, pos).length - node.data.substr(0, pos).length);
  308. if (pos >= 0) {
  309. imgnode = ghe.createEmoji(emoji);
  310. middlebit = node.splitText(pos);
  311. endbit = middlebit.splitText(name.length);
  312. middlebit.parentNode.replaceChild(imgnode, middlebit);
  313. skip = 1;
  314. }
  315. } else if (node.nodeType === 1 && node.childNodes) {
  316. for (var i = 0; i < node.childNodes.length; ++i) {
  317. i += ghe.replaceText(node.childNodes[i], emoji);
  318. }
  319. }
  320. return skip;
  321. },
  322.  
  323. // This function does the surrounding for every matched piece of text
  324. // and can be customized to do what you like
  325. // <img class="emoji" title=":smile:" alt=":smile:" src="x.png" height="20" width="20" align="absmiddle">
  326. createEmoji : function(emoji) {
  327. var el = document.createElement('img');
  328. el.src = emoji.url;
  329. el.className = ghe.vars.emojiClass + ' emoji';
  330. el.title = el.alt = ghe.vars.emojiTemplate.replace(ghe.regex.template, emoji.name);
  331. // el.align = 'absmiddle'; // deprecated attribute
  332. return el;
  333. },
  334.  
  335. // used by autocomplete (atwho) filter function
  336. matches : function(query, labels) {
  337. if (query === '') {
  338. return 1;
  339. }
  340. var i, partial,
  341. count = 0,
  342. arry = (labels || '').split(/[\s,_]+/),
  343. parts = query.split(/[,_]/),
  344. len = parts.length;
  345. for (i = 0; i < len; i++) {
  346. // full match or partial
  347. partial = arry.join('_').indexOf(parts.join('_'));
  348. if (arry.indexOf(parts[i]) > -1 || partial > -1) {
  349. count++;
  350. }
  351. // give more weight to results with indexOf closer to zero
  352. if (partial > -1 && partial < len / 2) {
  353. count++;
  354. }
  355. }
  356. // return fraction of query matches
  357. return count / len;
  358. },
  359.  
  360. // init when comment textarea is focused
  361. initAutocomplete : function($el) {
  362. if (!$el.data('atwho')) {
  363. var indx, len, name, group,
  364. data = [];
  365. // combine data
  366. for (name in ghe.collections) {
  367. if (ghe.collections.hasOwnProperty(name)) {
  368. group = ghe.collections[name].slice(1);
  369. data = data.concat(group);
  370. }
  371. }
  372. len = data.length;
  373. // alphabetic sort
  374. data = data.sort(function(a, b) {
  375. return a.name > b.name ? 1 : a.name < b.name ? -1 : 0;
  376. });
  377. // add prepend name to labels
  378. for (indx = 0; indx < len; indx++) {
  379. data[indx].labels = data[indx].name.replace(/_/g, ' ') + ' ' + data[indx].labels;
  380. }
  381. // add emoji autocomplete to comment textareas
  382. $el.atwho({
  383. at : ':_', // first two characters from emojiTemplate
  384. data : data,
  385. searchKey: 'labels',
  386. displayTpl : '<li><span><img src="${url}" height="30" /></span>${name}</li>',
  387. insertTpl : ghe.vars.emojiTemplate,
  388. delay : 400,
  389. callbacks : {
  390. matcher: function(flag, subtext) {
  391. var regexp = ghe.regex.emojiFilter,
  392. match = regexp.exec(subtext);
  393. // this next line does some magic...
  394. // for some reason, without it, moving the caret from "p" to "r" in
  395. // ":_people,fear," opens & closes the popup with each letter typed
  396. subtext.match(regexp);
  397. if (match) {
  398. return match[2] || match[1];
  399. } else {
  400. return null;
  401. }
  402. },
  403. filter: function(query, data, searchKey) {
  404. var i, item,
  405. len = data.length,
  406. _results = [];
  407. for (i = 0; i < len; i++) {
  408. item = data[i];
  409. item.atwho_order = ghe.matches(query, item[searchKey]);
  410. if (item.atwho_order > 0.9) {
  411. _results[_results.length] = item;
  412. }
  413. }
  414. return query === '' ? _results : _results.sort(function(a, b) {
  415. // descending sort
  416. return b.atwho_order - a.atwho_order;
  417. });
  418. },
  419. sorter: function(query, items) {
  420. // sorted by filter
  421. return items;
  422. },
  423. // event parameter adding in atwho.js mod
  424. beforeInsert: function(value, $li, event) {
  425. if (event.shiftKey || ghe.settings.insertAsImage) {
  426. // add image tag directly if shift is held
  427. return '<img title="' +
  428. ghe.vars.emojiTemplate.replace(ghe.regex.template, $li.text()) +
  429. '" src="' + $li.find('img').attr('src') + '">';
  430. }
  431. return value;
  432. }
  433. }
  434. });
  435. // use classes from GitHub-Dark to make theme match GitHub-Dark
  436. $('.atwho-view').addClass('popover suggester');
  437. }
  438. },
  439.  
  440. setupPreviews : function() {
  441. // Add mutant observer to previews
  442. var previews = document.querySelectorAll('.preview-content .comment-body');
  443. if (ghe.previewObserver.length) {
  444. // disconnect previous observers
  445. $.each(ghe.previewObserver, function() {
  446. this.disconnect();
  447. });
  448. ghe.previewObserver = [];
  449. }
  450. Array.prototype.forEach.call(previews, function(target) {
  451. var obs = new MutationObserver(function(mutations) {
  452. mutations.forEach(function(mutation) {
  453. // preform checks before adding code wrap to minimize function calls
  454. if (mutation.target === target && !ghe.isUpdating) {
  455. ghe.checkPage(target);
  456. }
  457. });
  458. });
  459. obs.observe(target, {
  460. childList : true,
  461. subtree : false
  462. });
  463. ghe.previewObserver[ghe.previewObserver.length] = obs;
  464. });
  465. },
  466.  
  467. addToolbarIcon : function() {
  468. // add Emoji setting icons
  469. var indx, $el,
  470. $toolbars = $('.toolbar-commenting'),
  471. len = $toolbars.length;
  472. for (indx = 0; indx < len; indx++) {
  473. $el = $toolbars.eq(indx);
  474. if (!$el.find('.ghe-settings-icon').length) {
  475. $el.prepend([
  476. '<button type="button" class="ghe-settings-open toolbar-item tooltipped tooltipped-n tooltipped-multiline" aria-label="Browse collections & Set Emojis Options" tabindex="-1">',
  477. '<svg class="ghe-settings-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor">',
  478. '<path d="M7.205 3.233c0 .952-.753 1.73-1.722 1.73-.953 0-1.707-.793-1.707-1.73 0-.937.762-1.73 1.707-1.73.97 0 1.73.793 1.73 1.73h-.008zm6.904 0c0 .952-.794 1.73-1.747 1.73-.95 0-1.722-.793-1.722-1.73 0-.937.795-1.73 1.73-1.73.938 0 1.747.793 1.747 1.73h-.008zM7.204 10.1v5.19c0 1.728 6.904 1.728 6.904 0V10.1M10.642 10.1v3.46"/>',
  479. '<path d="M.878 8.777s3.167 1.893 8.002 1.92c4.365.02 8.135-1.92 8.135-1.92"/>',
  480. '</svg>',
  481. '</button>'
  482. ].join(''));
  483. }
  484. }
  485. },
  486.  
  487. // dynamic stylesheet
  488. updateStyleSheet : function() {
  489. var range = this.settings.rangeHeight.split(';');
  490. ghe.$style.text([
  491. // img styling - vertically center with set height range
  492. '.atwho-view li img, #ghe-popup .select-menu-item img, img[alt="ghe-emoji"], .' +
  493. this.vars.emojiClass + ' { ' +
  494. 'margin-bottom:.25em; vertical-align:middle; ' +
  495. 'min-height: ' + (range[0] || 'none') + 'px;' +
  496. 'max-height: ' + (range[1] || 'none') + 'px }',
  497. // click (make active) on image to zoom
  498. '.' + this.vars.emojiClass + ':active, a:active img[alt="ghe-emoji"] { zoom:' +
  499. this.settings.activeZoom + ' }'
  500. ].join(''));
  501. },
  502.  
  503. addBindings : function() {
  504. var lastKey,
  505. $popup = $('#ghe-popup'),
  506. $settings = $('#ghe-settings');
  507. // Delegated bindings
  508. $('body')
  509. .on('click', '.ghe-settings-open', function() {
  510. // open all collections panel
  511. ghe.openCollections($(this));
  512. return false;
  513. })
  514. .on('click', '.ghe-collection', function() {
  515. // open targeted collection
  516. var name = $(this).attr('data-group');
  517. ghe.showCollection(name);
  518. })
  519. .on('click', '.ghe-emoji', function(e) {
  520. // click on emoji in collection to add to textarea
  521. ghe.addEmoji(e, $(this));
  522. })
  523. .on('click keypress keydown', function(e) {
  524. clearTimeout(ghe.timer);
  525. var panelVisible = $popup.hasClass('in') || $settings.hasClass('in'),
  526. openPanel = ghe.vars.keyboardOpen.split('+'),
  527. key = String.fromCharCode(e.which).toLowerCase();
  528. // press escape or click outside to close the panel
  529. if (panelVisible && e.which === 27 || e.type === 'click' && !$(e.target).closest('#ghe-wrapper').length) {
  530. ghe.closePanels();
  531. return;
  532. }
  533. // keydown is only needed for escape key detection
  534. if (e.type === 'keydown' || /(input|textarea)/i.test(document.activeElement.nodeName)) {
  535. return;
  536. }
  537. // shortcut keys need keypress
  538. if (lastKey === openPanel[0] && key === openPanel[1]) {
  539. if ($settings.hasClass('in')) {
  540. ghe.closePanels();
  541. } else {
  542. ghe.openSettings();
  543. }
  544. }
  545. lastKey = key;
  546. ghe.timer = setTimeout(function() {
  547. lastKey = null;
  548. }, ghe.vars.keyboardDelay);
  549.  
  550. // add shortcut to help menu
  551. if (key === '?') {
  552. // table doesn't exist until user presses "?"
  553. setTimeout(function() {
  554. if (!$('.ghe-shortcut').length) {
  555. $('.keyboard-mappings:eq(0) tbody:eq(0)').append([
  556. '<tr class="ghe-shortcut">',
  557. '<td class="keys">',
  558. '<kbd>' + openPanel[0] + '</kbd> <kbd>' + openPanel[1] + '</kbd>',
  559. '</td>',
  560. '<td>GitHub Emojis: open settings</td>',
  561. '</tr>'
  562. ].join(''));
  563. }
  564. }, 300);
  565. }
  566. });
  567.  
  568. // popup & settings interactions
  569. $('#ghe-popup .octicon-gear').on('click keyup', function(e) {
  570. if (e.type === 'keyup' && e.which !== 13) {
  571. return;
  572. }
  573. ghe.openSettings();
  574. });
  575. $('#ghe-settings, #ghe-settings-close, #ghe-settings-inner').on('click', function(e) {
  576. if (this.id === 'ghe-settings-inner') {
  577. e.stopPropagation();
  578. } else {
  579. ghe.closePanels();
  580. }
  581. });
  582. // ghe-checkbox added to checkboxes
  583. $('.ghe-checkbox').on('change', function() {
  584. ghe.updateSettings();
  585. });
  586. // go back - switch from single collection to showing all collections
  587. $('#ghe-popup .ghe-back').on('click', function(){
  588. $('.ghe-single-collection, .ghe-back').hide();
  589. $('.ghe-all-collections').show();
  590. });
  591.  
  592. // add new source input
  593. $('#ghe-add-source').on('click', function() {
  594. var $panel = $('#ghe-settings-inner');
  595. // lets not get crazy!
  596. if ($panel.find('.ghe-source').length < 20) {
  597. $(ghe.sourceHTML).appendTo($panel.find('.ghe-sources'));
  598. }
  599. return false;
  600. });
  601. $('#ghe-refresh-sources, #ghe-restore').on('click', function() {
  602. // update sources from settings panel
  603. ghe.setStoredValues(this.id === 'ghe-restore');
  604. // load json files
  605. ghe.loadEmojiJson(true);
  606. return false;
  607. });
  608.  
  609. // Init range slider
  610. $('.ghe-height')
  611. .val(ghe.settings.rangeHeight)
  612. .ionRangeSlider({
  613. type : 'double',
  614. min : 0,
  615. max : ghe.vars.maxEmojiHeight,
  616. onChange : function() {
  617. ghe.updateSettings();
  618. },
  619. force_edges : true,
  620. hide_min_max : true
  621. });
  622. $('.ghe-zoom')
  623. .val(ghe.settings.activeZoom)
  624. .ionRangeSlider({
  625. min : 0,
  626. max : ghe.vars.maxEmojiZoom,
  627. step : 0.1,
  628. onChange : function() {
  629. ghe.updateSettings();
  630. },
  631. force_edges : true,
  632. hide_min_max : true
  633. });
  634.  
  635. // Remove source input - delegated binding
  636. $('.ghe-settings-wrapper')
  637. .on('click', '.ghe-remove', function(e) {
  638. var $wrapper = $(this).closest('.ghe-source'),
  639. url = $wrapper.find('.ghe-source-input').attr('data-url');
  640. ghe.removeSource(url);
  641. $wrapper.remove();
  642. ghe.setStoredValues();
  643. return false;
  644. })
  645. .on('focus blur input change', '.ghe-source-input', function(e) {
  646. if (ghe.busy) { return; }
  647. ghe.busy = true;
  648. var val,
  649. $this = $(this);
  650. switch (e.type) {
  651. case 'focus':
  652. case 'focusin':
  653. // show entire url when focused
  654. $this.val( $this.attr('data-url') );
  655. break;
  656. case 'blur':
  657. case 'focusout':
  658. ghe.showFileName($this);
  659. break;
  660. default:
  661. $this.attr('data-url', $this.val());
  662. }
  663. if (e.type === 'change' || e.which === 13) {
  664. val = $this.val();
  665. $this.attr('data-url', val);
  666. ghe.fetchCustomEmojis(val);
  667. }
  668. ghe.busy = false;
  669. });
  670.  
  671. // initialize autocomplete that add emojis, but only on focus
  672. // since every comment has a hidden textarea
  673. $('body').on('focus', '.comment-form-textarea', function() {
  674. ghe.initAutocomplete($(this));
  675. });
  676. },
  677.  
  678. showFileName : function($el) {
  679. var str = $el.attr('data-url'),
  680. v = str.substring( str.lastIndexOf('/') + 1, str.length );
  681. // show only the file name in the input when blurred
  682. // unless there is no file name
  683. $el.val(v === '' ? str : '...' + v);
  684. },
  685.  
  686. closePanels : function() {
  687. $('#ghe-popup').removeClass('in');
  688. $('#ghe-settings').removeClass('in');
  689. ghe.$currentInput = null;
  690. },
  691.  
  692. openSettings : function() {
  693. $('.modal-backdrop').click();
  694. $('#ghe-settings').addClass('in');
  695. },
  696.  
  697. openCollections : function($el) {
  698. ghe.addCollections();
  699. var pos = $el.offset();
  700. $('#ghe-settings').removeClass('in');
  701. $('#ghe-popup')
  702. .addClass('in')
  703. .css({
  704. left: pos.left + 25,
  705. top: pos.top
  706. });
  707. ghe.$currentInput = $el.closest('.previewable-comment-form').find('.comment-form-textarea');
  708. },
  709.  
  710. addCollections : function() {
  711. var indx, len, key, group, img,
  712. collections = ghe.collections,
  713. range = ghe.settings.rangeHeight.split(';'),
  714. list = [],
  715. items = [];
  716. // build collections list -
  717. for (key in collections) {
  718. if (collections.hasOwnProperty(key)) {
  719. list[list.length] = key;
  720. }
  721. }
  722. list = list.sort(function(a, b) {
  723. return a > b ? 1 : (a < b ? -1 : 0);
  724. });
  725. len = list.length;
  726. // add random image from group
  727. for (indx = 0; indx < len; indx++) {
  728. group = collections[list[indx]];
  729. // random image (skip first entry)
  730. img = Math.round(Math.random() * (group.length - 2)) + 1;
  731. items[items.length] = '<div class="select-menu-item js-navigation-item ghe-collection" ' +
  732. 'data-group="' + list[indx] + '">' +
  733. // collection info stored in first entry
  734. group[0].name + ' <span class="ghe-right"><img src="' +
  735. group[img].url + '" title="' +
  736. ghe.vars.emojiTemplate.replace(ghe.regex.template, group[img].name) + '" style="' +
  737. 'min-height:' + (range[0] || 'none') + 'px;' +
  738. 'max-height:' + (range[1] || 'none') + 'px;">' +
  739. '</span></div>';
  740. }
  741. $('.ghe-single-collection, .ghe-back').hide();
  742. $('.ghe-all-collections').html(items.join('')).show();
  743. },
  744.  
  745. showCollection : function(name) {
  746. var indx,
  747. range = ghe.settings.rangeHeight.split(';'),
  748. group = ghe.collections[name].sort(function(a, b) {
  749. return a.name > b.name ? 1 : ( a.name < b.name ? -1 : 0 );
  750. }),
  751. list = [],
  752. len = group.length;
  753. for (indx = 1; indx < len; indx++) {
  754. list[indx - 1] = '<div class="select-menu-item js-navigation-item ghe-emoji" ' +
  755. 'data-name="' + group[indx].name + '">' +
  756. group[indx].name + '<span class="ghe-right"><img src="' +
  757. group[indx].url + '" style="min-height:' + (range[0] || 'none') + 'px;' +
  758. 'max-height:' + (range[1] || 'none') + 'px"></span></div>';
  759. }
  760. $('.ghe-all-collections').hide();
  761. $('.ghe-single-collection').html(list.join('')).show();
  762. $('.ghe-back').show();
  763. },
  764.  
  765. // add emoji from collection
  766. addEmoji : function(e, $el) {
  767. var val, emoji,
  768. name = $el.attr('data-name'),
  769. caretPos = ghe.$currentInput.caret('pos');
  770. // insert into textarea
  771. if (e.shiftKey || ghe.settings.insertAsImage) {
  772. // add image tag directly if shift is held;
  773. // GitHub does NOT allow class names so we are forced to use alt
  774. emoji = '<img alt="ghe-emoji" title="' +
  775. ghe.vars.emojiTemplate.replace(ghe.regex.template, name) +
  776. '" src="' + $el.find('img').attr('src') + '">';
  777. } else {
  778. emoji = ghe.vars.emojiTemplate.replace(ghe.regex.template, name);
  779. }
  780. val = ghe.$currentInput.val();
  781. ghe.$currentInput
  782. .val(val.slice(0, caretPos) + emoji + ' ' + val.slice(caretPos))
  783. .focus()
  784. .caret('pos', caretPos + emoji.length + 1);
  785. ghe.closePanels();
  786. },
  787.  
  788. removeSource : function(url) {
  789. var indx,
  790. list = [],
  791. collections = this.collections,
  792. sources = this.settings.sources,
  793. len = sources.length;
  794. // remove from source
  795. for (indx = 0; indx < len; indx++) {
  796. if (sources[indx] !== url) {
  797. list[list.length] = sources[indx];
  798. }
  799. }
  800. this.settings.sources = list;
  801. for (indx in collections) {
  802. if (collections.hasOwnProperty(indx) && collections[indx][0].url === url) {
  803. delete collections[indx];
  804. debug('Removing "' + indx + '" collection', collections);
  805. }
  806. }
  807. },
  808.  
  809. update : function(target) {
  810. this.isUpdating = true;
  811. this.setupPreviews();
  812. this.addToolbarIcon();
  813. // checkPage clears isUpdating flag
  814. this.checkPage(target);
  815. },
  816.  
  817. addPanels : function() {
  818. /* https://github.com/ichord/At.js styles for autocomplete */
  819. GM_addStyle([
  820. // settings panel
  821. '#ghe-menu:hover { cursor:pointer }',
  822. '#ghe-settings { position:fixed; z-index:65535; top:0; bottom:0; left:0; right:0; opacity:0; visibility:hidden }',
  823. '#ghe-settings.in { opacity:1; visibility:visible; background:rgba(0,0,0,.5) }',
  824. '#ghe-settings-inner { position:fixed; left:50%; top:50%; transform:translate(-50%,-50%); width:25rem; box-shadow:0 .5rem 1rem #111; color:#c0c0c0 }',
  825. '#ghe-settings label { margin-left:.5rem; position:relative; top:-1px }',
  826. '#ghe-settings .ghe-remove { float:right; margin-top:2px; padding:4px; cursor:pointer }',
  827. '#ghe-settings .ghe-remove-icon { position:relative; top:3px }',
  828. '#ghe-settings-close { fill:#666; float:right; cursor:pointer }',
  829. '#ghe-settings-close:hover { fill:#ccc }',
  830. '#ghe-settings .ghe-settings-wrapper { max-height:60vh; overflow-y:auto; padding: 1px 10px }',
  831. '#ghe-settings .ghe-right, #ghe-popup .ghe-right { float:right }',
  832. '#ghe-settings p { line-height:25px; }',
  833. '#ghe-settings .checkbox input { margin-top:.35em }',
  834. '#ghe-settings input[type="checkbox"] { width:16px !important; height:16px !important; border-radius:3px !important }',
  835. '#ghe-settings .boxed-group-inner { padding:0; }',
  836. '#ghe-settings .ghe-footer { padding: 10px; border-top: #555 solid 1px; }',
  837. '#ghe-settings .ghe-min-height, #ghe-settings .ghe-max-height, .ghe-zoom { width: 5em; }',
  838. '#ghe-settings .ghe-source-input { width: 90%; }',
  839. '#ghe-settings .ghe-slider-wrapper { height:40px; }',
  840. '#ghe-settings .ghe-slider-wrapper label { position:relative; top:22px }',
  841. '#ghe-settings .ghe-range-slider, #ghe-settings .ghe-zoom-slider { position:relative; height:40px; width:250px; float:right }',
  842.  
  843. // show emoji collections
  844. '#ghe-popup { display:none }',
  845. '#ghe-popup .ghe-content, #ghe-popup .ghe-content > div { max-height: 200px }',
  846. '#ghe-popup .octicon-gear { margin-left:4px }',
  847. '#ghe-popup .ghe-back svg { height:20px; padding:4px 14px 4px 4px }',
  848. '#ghe-popup .select-menu-item { font-size:1.1em; font-weight:bold; line-height:40px; padding:8px }',
  849. '.ghe-settings-icon, #ghe-popup.in { display:inline-block }',
  850.  
  851. // autocomplete popup in comment
  852. '.atwho-view { position:absolute; top:0; left:0; display:none; margin-top:18px; background:#fff; color:#000; border:1px solid #ddd; border-radius:3px; box-shadow:0 0 5px rgba(0,0,0,.1); min-width:300px; max-width:none!important; max-height:225px; overflow:auto; z-index:11110!important }',
  853. '.atwho-view .navigation-focus { background:#36f; color:#fff }',
  854. '.atwho-view .navigation-focus small { color:#fff }',
  855. '.atwho-view strong { color:#36F }',
  856. '.atwho-view .navigation-focus strong { color:#fff; font:700 }',
  857. '.atwho-view ul { list-style:none; padding:0; margin:auto }',
  858. '.atwho-view ul li { display:block; padding:5px 10px; border-bottom:1px solid #ddd; cursor:pointer }',
  859. '.atwho-view li span { display:inline-block; min-width:60px; padding-right:4px }',
  860. '.atwho-view small { font-size:smaller; color:#777; font-weight:400 }',
  861.  
  862. // rangeSlider
  863. '.irs{position:relative;display:block;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}',
  864. '.irs-line{position:relative;display:block;overflow:hidden;outline:none !important}.irs-line-left,.irs-line-mid,.irs-line-right{position:absolute;display:block;top:0}',
  865. '.irs-line-left{left:0;width:9%}.irs-line-mid{left:9%;width:82%}.irs-line-right{right:0;width:9%}.irs-bar{position:absolute;display:block;left:0;width:0}.irs-bar-edge{position:absolute;display:block;top:0;left:0}',
  866. '.irs-shadow{position:absolute;display:none;left:0;width:0}.irs-slider{position:absolute;display:block;cursor:default;z-index:1}.irs-slider.type_last{z-index:2}.irs-min{position:absolute;display:block;left:0;cursor:default}',
  867. '.irs-max{position:absolute;display:block;right:0;cursor:default}.irs-from,.irs-to,.irs-single{position:absolute;display:block;top:0;left:0;cursor:default;white-space:nowrap}.irs-grid{position:absolute;display:none;bottom:0;left:0;width:100%;height:20px}',
  868. '.irs-with-grid .irs-grid{display:block}.irs-grid-pol{position:absolute;top:0;left:0;width:1px;height:8px;background:#000}.irs-grid-pol.small{height:4px}.irs-grid-text{position:absolute;bottom:0;left:0;white-space:nowrap;text-align:center;font-size:9px;line-height:9px;padding:0 3px;color:#000}',
  869. '.irs-disable-mask{position:absolute;display:block;top:0;left:-1%;width:102%;height:100%;cursor:default;background:rgba(0,0,0,0.0);z-index:2}.lt-ie9 .irs-disable-mask{background:#000;filter:alpha(opacity=0);cursor:not-allowed}.irs-disabled{opacity:0.4}',
  870. '.irs-hidden-input{position:absolute !important;display:block !important;top:0 !important;left:0 !important;width:0 !important;height:0 !important;font-size:0 !important;line-height:0 !important;padding:0 !important;margin:0 !important;outline:none !important;z-index:-9999 !important;background:none !important;border-style:solid !important;border-color:transparent !important}',
  871. '.irs-line-mid,.irs-line-left,.irs-line-right,.irs-bar,.irs-bar-edge,.irs-slider{background:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQQAAAC0BAMAAACAm0/4AAAAHlBMVEUAAADh5OlIPakuJnU8MZzh5Onh5Onlt8BIPamDg6ND+SBkAAAACnRSTlMAgMzMzHlXE4oe0nCEQQAAAMJJREFUeNrt1qENAkEQhtENkBDkCtCECiiBFjCgEXgMDVwJVEzGQ7KnZnJ5r4JP7E7+1tNJkCBBgoSqCQAAjNg+e6rbq717snt79GSHdu3J9hVGfE8nIVR4jgU+ZYHTVOBAAwAw4pROggQJEiRUTQAAYMRuSl9Rn/whN+UnFJizEiQUSijwKQucpgIHGgCAQatjy7a5tJkkBAlBQpAQJAQJQUJYYkKByQIA/6zPbSYJQUKQECQECUFCkBAkhCUmAMAvX+TSxQIIIKq9AAAAAElFTkSuQmCC") repeat-x}',
  872. '.irs{height:40px}.irs-with-grid{height:60px}.irs-line{height:12px;top:25px}.irs-line-left{height:12px;background-position:0 -30px}',
  873. '.irs-line-mid{height:12px;background-position:0 0}.irs-line-right{height:12px;background-position:100% -30px}.irs-bar{height:12px;top:25px;background-position:0 -60px}',
  874. '.irs-bar-edge{top:25px;height:12px;width:9px;background-position:0 -90px}.irs-shadow{height:3px;top:34px;background:#000;opacity:.25}',
  875. '.lt-ie9 .irs-shadow{filter:alpha(opacity=25)}.irs-slider{width:16px;height:18px;top:22px;background-position:0 -120px}',
  876. '.irs-slider.state_hover,.irs-slider:hover{background-position:0 -150px}.irs-min,.irs-max{color:#fff;font-size:10px;line-height:1.333;text-shadow:none;top:0;padding:1px 3px;background:#7D7E81;-moz-border-radius:4px;border-radius:4px}',
  877. '.irs-from,.irs-to,.irs-single{color:#fff;font-size:10px;line-height:1.333;text-shadow:none;padding:1px 5px;background:#534AA1;-moz-border-radius:4px;border-radius:4px}',
  878. '.irs-from:after,.irs-to:after,.irs-single:after{position:absolute;display:block;content:"";bottom:-6px;left:50%;width:0;height:0;margin-left:-3px;overflow:hidden;border:3px solid transparent;border-top-color:#534AA1}',
  879. '.irs-grid-pol{background:#e1e4e9}.irs-grid-text{color:#999}'
  880. ].join(''));
  881.  
  882. // Settings panel markup
  883. $('body').append([
  884. '<div id="ghe-wrapper">',
  885. '<div id="ghe-popup" class="select-menu-modal-holder js-menu-content js-navigation-container js-active-navigation-container">',
  886. '<div class="select-menu-modal">',
  887. '<div class="select-menu-header">',
  888. '<span class="select-menu-title">',
  889. '<text>Emoji Collections</text>',
  890. '<span class="octicon tooltipped tooltipped-w" aria-label="Change GitHub Custom Emoji Settings">',
  891. '<svg class="octicon-gear" viewBox="0 0 16 14" style="height: 16px; width: 14px;"><path d="M14 8.77V7.17l-1.94-0.64-0.45-1.09 0.88-1.84-1.13-1.13-1.81 0.91-1.09-0.45-0.69-1.92H6.17l-0.63 1.94-1.11 0.45-1.84-0.88-1.13 1.13 0.91 1.81-0.45 1.09L0 7.23v1.59l1.94 0.64 0.45 1.09-0.88 1.84 1.13 1.13 1.81-0.91 1.09 0.45 0.69 1.92h1.59l0.63-1.94 1.11-0.45 1.84 0.88 1.13-1.13-0.92-1.81 0.47-1.09 1.92-0.69zM7 11c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3z"/></svg>',
  892. '</span>',
  893. '<span class="octicon tooltipped tooltipped-w ghe-back" aria-label="Go back to see all collections">',
  894. '<svg xmlns="http://www.w3.org/2000/svg" width="6.5" height="10" viewBox="0 0 6.5 10"><path d="M5.008 0l1.497 1.504-3.76 3.49 3.743 3.51L4.984 10l-4.99-5.013L5.01 0z"/></svg>',
  895. '</span>',
  896. '</span>',
  897. '</div>',
  898. '<div class="js-select-menu-deferred-content ghe-content">',
  899. '<div class="select-menu-list ghe-all-collections"></div>',
  900. '<div class="select-menu-list ghe-single-collection"></div>',
  901. '</div>',
  902. '</div>',
  903. '</div>',
  904. '<div id="ghe-settings">',
  905. '<div id="ghe-settings-inner" class="boxed-group">',
  906. '<h3>GitHub Custom Emoji Settings',
  907. '<svg id="ghe-settings-close" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="160 160 608 608"><path d="M686.2 286.8L507.7 465.3l178.5 178.5-45 45-178.5-178.5-178.5 178.5-45-45 178.5-178.5-178.5-178.5 45-45 178.5 178.5 178.5-178.5z"/></svg>',
  908. '</h3>',
  909. '<div class="boxed-group-inner">',
  910. '<form>',
  911. '<div class="ghe-settings-wrapper">',
  912. '<p>',
  913. '<label>Insert as Image:',
  914. '<sup class="tooltipped tooltipped-e" aria-label="Or Shift + select the emoji">?</sup>',
  915. '<input class="ghe-image ghe-checkbox ghe-right" type="checkbox">',
  916. '</label>',
  917. '</p>',
  918. '<p class="checkbox">',
  919. '<label>Case Sensitive <input class="ghe-case ghe-checkbox ghe-right" type="checkbox"></label>',
  920. '</p>',
  921. '<div class="ghe-slider-wrapper">',
  922. '<div class="ghe-range-slider">',
  923. '<input type="text" class="ghe-height" value="" />',
  924. '</div>',
  925. '<label>Emoji Height',
  926. '<sup class="tooltipped tooltipped-e" aria-label="Set emoji minimum & maximum&#10;height in pixels">?</sup>',
  927. '</label>',
  928. '</div>',
  929. '<div class="ghe-slider-wrapper">',
  930. '<div class="ghe-zoom-slider">',
  931. '<input class="ghe-zoom ghe-right" type="text">',
  932. '</div>',
  933. '<label>Emoji Zoom',
  934. '<sup class="tooltipped tooltipped-e" aria-label="Set Emoji zoom factor&#10;while actively clicked">?</sup>',
  935. '</label>',
  936. '</div>',
  937. '<p>',
  938. '<hr>',
  939. '<h3>Sources',
  940. '<a href="https://github.com/StylishThemes/GitHub-Custom-Emojis/wiki/Add-Emojis" class="tooltipped tooltipped-e tooltipped-multiline" aria-label="Click to get more details on how to set up an Emoji source JSON file">',
  941. '<sup>?</sup>',
  942. '</a>',
  943. '</h3>',
  944. '<div class="ghe-sources"></div>',
  945. '</p>',
  946. '</div>',
  947. '<div class="ghe-footer">',
  948. '<div class="btn-group">',
  949. '<a href="#" id="ghe-add-source" class="btn btn-sm">Add Source</a>',
  950. '<a href="#" id="ghe-refresh-sources" class="btn btn-sm">Refresh Sources</a>&nbsp;',
  951. '</div>',
  952. '<a href="#" id="ghe-restore" class="btn btn-sm btn-danger tooltipped tooltipped-n ghe-right" aria-label="Default sources are restored;&#10;other source will remain">Restore Defaults</a>',
  953. '</div>',
  954. '</form>',
  955. '</div>',
  956. '</div>',
  957. '</div>',
  958. '</div>'
  959. ].join(''));
  960. },
  961.  
  962. // JSON source inputs
  963. sourceHTML : [
  964. '<div class="ghe-source">',
  965. '<input class="ghe-source-input" type="text" value="" placeholder="Add JSON sources only">',
  966. '<a href="#" class="ghe-remove btn btn-sm btn-danger">',
  967. '<svg class="ghe-remove-icon" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="160 160 608 608" fill="currentColor"><path d="M686.2 286.8L507.7 465.3l178.5 178.5-45 45-178.5-178.5-178.5 178.5-45-45 178.5-178.5-178.5-178.5 45-45 178.5 178.5 178.5-178.5z"/></svg>',
  968. '</a>',
  969. '</div>'
  970. ].join(''),
  971.  
  972. init : function() {
  973. debug('GitHub-Emoji Script initializing!');
  974.  
  975. // add style tag to head
  976. this.$style = $('<style class="ghe-style">').appendTo('head');
  977.  
  978. this.getStoredValues();
  979. this.loadEmojiJson();
  980. this.updateStyleSheet();
  981. this.isUpdating = true;
  982.  
  983. var targets = document.querySelectorAll(this.containers.join(',')),
  984. // parts = [':_', ':']
  985. parts = this.vars.emojiTemplate.split('${name}');
  986.  
  987. // emojiFilter = /:_([a-z\u00c0-\u00ff0-9_,'.+-]*)$|:_([^\x00-\xff]*)$/gi
  988. // used by atwho.js autocomplete
  989. this.regex.emojiFilter = new RegExp(
  990. parts[0] + '([a-z\u00c0-\u00ff0-9_,\'\.\+\-]*)$|' +
  991. parts[0] + '([^\\x00-\\xff]*)$', 'gi'
  992. );
  993.  
  994. // used by
  995. this.regex.nameRegex = new RegExp(
  996. parts[0].replace(ghe.regex.charsToEsc, '\\$&') +
  997. '([\\w_]+)' +
  998. parts[1].replace(ghe.regex.charsToEsc, '\\$&'), 'g' +
  999. (ghe.settings.caseSensitive ? 'i' : '')
  1000. );
  1001.  
  1002. Array.prototype.forEach.call(targets, function(target) {
  1003. new MutationObserver(function(mutations) {
  1004. mutations.forEach(function(mutation) {
  1005. // preform checks before adding code wrap to minimize function calls
  1006. if (mutation.target === target && !$.isEmptyObject(ghe.collections) &&
  1007. !(ghe.isUpdating || target.querySelector('.ghe-processed'))) {
  1008. ghe.update(target);
  1009. }
  1010. });
  1011. }).observe(target, {
  1012. childList : true,
  1013. subtree : true
  1014. });
  1015. });
  1016.  
  1017. this.addPanels();
  1018.  
  1019. // Add emoji autocomplete & watch for preview rendering
  1020. this.setupPreviews();
  1021. this.addToolbarIcon();
  1022. this.addBindings();
  1023. // update panel values after bindings (rangeslider)
  1024. this.setStoredValues();
  1025.  
  1026. // checkPage clears isUpdating flag
  1027. this.checkPage();
  1028. }
  1029. };
  1030.  
  1031. // add style at document-start
  1032. ghe.init();
  1033.  
  1034. // include a "?debug" anywhere in the browser URL to enable debugging
  1035. function debug() {
  1036. if (/\?debug/.test(window.location.href)) {
  1037. console.log.apply(console, arguments);
  1038. }
  1039. }
  1040. })(jQuery.noConflict(true));