Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.47 KB | None | 0 0
  1. var Character = {
  2.  
  3. loadedIcons: [],
  4. loadedTalents: [],
  5. loadedGlyphs: [],
  6. currentAjax: null,
  7. /**
  8. * Performs an ajax call to get the display name
  9. * This should only be called if the icon cache was empty
  10. * @param id
  11. * @param realm
  12. * @param slot
  13. */
  14. getIcon: function (id, realm, slot) {
  15. if ($.inArray(id, this.loadedIcons) == -1) {
  16. this.loadedIcons.push(id);
  17.  
  18. $.get(Config.URL + "icon/get/" + realm + "/" + id, function (data) {
  19. $(".get_icon_" + id).each(function () {
  20. $(this).html("<div class='item'><a href='" + Config.URL + "item/" + realm + "/" + id + "' " + (Config.UseFusionTooltip ? 'rel-e' : 'rel') + "='item=" + id + "' data-item-slot='" + slot + "' data-realm='" + realm + "'></a><img src='https://wow.zamimg.com/images/wow/icons/large/" + data + ".jpg' /></div>");
  21. TooltipExtended.refresh();
  22. });
  23. });
  24. }
  25. },
  26.  
  27. /**
  28. * Whether the tabs are changing or not
  29. * @type Boolean
  30. */
  31. tabsAreChanging: false,
  32.  
  33. /**
  34. * Change tab
  35. * @param selector
  36. * @param link
  37. */
  38. tab: function (selector, link) {
  39. if (!this.tabsAreChanging) {
  40. this.tabsAreChanging = true;
  41.  
  42. // Find out the current tab
  43. var currentTabLink = $(".armory_current_tab");
  44. var currentTabId = "#tab_" + currentTabLink.attr("onClick").replace("Character.tab('", "").replace("', this)", "");
  45.  
  46. // Change link states
  47. currentTabLink.removeClass("armory_current_tab");
  48. $(link).addClass("armory_current_tab");
  49.  
  50. // Fade the current and show the new
  51. $(currentTabId).fadeOut(300, function () {
  52. $("#tab_" + selector).fadeIn(300, function () {
  53. Character.tabsAreChanging = false;
  54. });
  55. });
  56. }
  57. },
  58.  
  59. /**
  60. * Slide to an attributes tab
  61. * @param id
  62. */
  63. attributes: function (id) {
  64. if (id == 2) {
  65. $("#attributes_wrapper").animate({marginLeft: "-367px"}, 500);
  66. $("#tab_armory_1").fadeTo(500, 0.1);
  67. $("#tab_armory_3").fadeTo(500, 0.1);
  68. $("#tab_armory_2").fadeTo(500, 1);
  69. }
  70. else if (id == 1) {
  71. $("#attributes_wrapper").animate({marginLeft: "0px"}, 500);
  72. $("#tab_armory_2").fadeTo(500, 0.1);
  73. $("#tab_armory_3").fadeTo(500, 0.1);
  74. $("#tab_armory_1").fadeTo(500, 1);
  75. }
  76. else {
  77. $("#attributes_wrapper").animate({marginLeft: "-734px"}, 500);
  78. $("#tab_armory_1").fadeTo(500, 0.1);
  79. $("#tab_armory_2").fadeTo(500, 0.1);
  80. $("#tab_armory_3").fadeTo(500, 1);
  81. }
  82. }
  83. };
  84.  
  85. /**************** TALENTS *************************/
  86.  
  87. $('.talents-spec').click(function()
  88. {
  89. if ($(this).hasClass('talents-spec-active'))
  90. return false;
  91.  
  92. var $tabId = $(this).attr('specId');
  93.  
  94. if ($tabId.length == 0)
  95. return;
  96.  
  97. //disable the currenly selected one
  98. $('.talents-spec').each(function(index, element)
  99. {
  100. if ($(element).hasClass('talents-spec-active'))
  101. {
  102. //the active is found
  103. var activeTabId = $(element).attr('specId');
  104. //remove the class
  105. $(element).removeClass('talents-spec-active');
  106. //hide the talents table and crap
  107. $('.talents[specId="'+activeTabId+'"]').hide();
  108. }
  109. });
  110.  
  111. //enable the new tab
  112. $(this).addClass('talents-spec-active')
  113. $('.talents[specId="'+$tabId+'"]').show();
  114. });
  115.  
  116. $("[data-tip-talent]").hover(
  117. function()
  118. {
  119. var $spellId = $(this).attr("data-tip-talent");
  120. var $realmId = $(this).attr("data-tip-realm");
  121. var $rank = $(this).attr("data-tip-rank");
  122. var $max = $(this).attr("data-tip-max");
  123.  
  124. $(document).bind('mousemove', TooltipExtended.addEvents.handleMouseMove);
  125. Tooltip.show('Loading...');
  126.  
  127. if (typeof Character.loadedTalents[$spellId] == 'undefined')
  128. {
  129. Character.currentAjax = $.getJSON(Config.URL + "spell_data/index/" + $realmId + "/" + $spellId + "/talent", function(data)
  130. {
  131. data.tooltip = $(data.tooltip);
  132. //hide the rank column
  133. data.tooltip.find('#spell-tooltip-rank').css('display', 'none');
  134. //append the talnet rank
  135. data.tooltip.find('#spell-tooltip-name').after('<br><b>Rank '+$rank+'/'+$max+'</b>');
  136.  
  137. //save as loaded
  138. Character.loadedTalents[$spellId] = data;
  139.  
  140. Tooltip.show(data.tooltip);
  141. });
  142. }
  143. else
  144. {
  145. var data = Character.loadedTalents[$spellId];
  146.  
  147. Tooltip.show(data.tooltip);
  148. }
  149. },
  150. function()
  151. {
  152. $("#tooltip").hide();
  153. $(document).unbind('mousemove', TooltipExtended.addEvents.handleMouseMove);
  154.  
  155. if (Character.currentAjax != null)
  156. Character.currentAjax.abort();
  157.  
  158. Character.currentAjax = null;
  159. }
  160. );
  161.  
  162. $("[data-tip-glyph]").hover(
  163. function()
  164. {
  165. var $glyphId = parseInt($(this).attr("data-tip-glyph"));
  166. var $type = $(this).attr("data-tip-type");
  167. var $realmId = $(this).attr("data-tip-realm");
  168.  
  169. $(document).bind('mousemove', TooltipExtended.addEvents.handleMouseMove);
  170. Tooltip.show('Loading...');
  171.  
  172. if ($glyphId > 0)
  173. {
  174. if (typeof Character.loadedGlyphs[$glyphId] == 'undefined')
  175. {
  176. Character.currentAjax = $.getJSON(Config.URL + "spell_data/index/" + $realmId + "/" + $glyphId + "/glyph", function(data)
  177. {
  178. //save as loaded
  179. Character.loadedGlyphs[$glyphId] = data;
  180.  
  181. Tooltip.show('<table>' +
  182. '<tbody>' +
  183. '<tr>' +
  184. '<td style="max-width: 320px;">' +
  185. '<b style="font-size: 15px;">' + data.name + '</b><br>' +
  186. '<span style="color: #71D5FF;">'+$type+'</span><br>' +
  187. '<span class="q">' + data.tooltip + '</span><br>' +
  188. '</td>' +
  189. '</tr>' +
  190. '</tbody>' +
  191. '</table>');
  192. });
  193. }
  194. else
  195. {
  196. var data = Character.loadedGlyphs[$glyphId];
  197.  
  198. Tooltip.show('<table>' +
  199. '<tbody>' +
  200. '<tr>' +
  201. '<td style="max-width: 320px;">' +
  202. '<b style="font-size: 15px;">' + data.name + '</b><br>' +
  203. '<span style="color: #71D5FF;">'+$type+'</span><br>' +
  204. '<span class="q">' + data.tooltip + '</span><br>' +
  205. '</td>' +
  206. '</tr>' +
  207. '</tbody>' +
  208. '</table>');
  209. }
  210. }
  211. else
  212. {
  213. Tooltip.show('<b style="font-size: 15px;">Empty</b><br /><span style="color: #71D5FF;">'+$type+'</span>');
  214. }
  215. },
  216. function()
  217. {
  218. $("#tooltip").hide();
  219. $(document).unbind('mousemove', TooltipExtended.addEvents.handleMouseMove);
  220.  
  221. if (Character.currentAjax != null)
  222. Character.currentAjax.abort();
  223.  
  224. Character.currentAjax = null;
  225. }
  226. );
  227.  
  228. Number.prototype.hasFlag = function (flag) {
  229. return (this & parseInt(flag)) === parseInt(flag);
  230. };
  231.  
  232. var SOCKET_COLOR_META = 1;
  233. var SOCKET_COLOR_RED = 2;
  234. var SOCKET_COLOR_YELLOW = 4;
  235. var SOCKET_COLOR_BLUE = 8;
  236.  
  237. /**
  238. * Extended Tooltip related functions
  239. */
  240. function TooltipExtended() {
  241. /**
  242. * Add event-listeners
  243. */
  244. this.initialize = function () {
  245. // Add mouse-over event listeners
  246. this.addEvents();
  247. };
  248. this.addEvents = function () {
  249. TooltipExtended.addEvents.handleMouseMove = function(e)
  250. {
  251. TooltipExtended.move(e);
  252. };
  253.  
  254. if (Config.UseFusionTooltip) {
  255. $("[rel-e]").hover(
  256. function (e) {
  257. $(document).bind('mousemove', TooltipExtended.addEvents.handleMouseMove);
  258. if (/^item=[0-9]*$/.test($(this).attr("rel-e"))) {
  259. TooltipExtended.Item.get(this, function (data) {
  260. TooltipExtended.show(data);
  261. TooltipExtended.move(e);
  262. });
  263. }
  264. },
  265. function () {
  266. $(document).unbind('mousemove', TooltipExtended.addEvents.handleMouseMove);
  267. $("#tooltip").hide();
  268.  
  269. if (TooltipExtended.Item.currentAjax != null)
  270. TooltipExtended.Item.currentAjax.abort();
  271. }
  272. );
  273. }
  274. };
  275.  
  276. /**
  277. * Used to support Ajax content
  278. * Reloads the tooltip elements
  279. */
  280. this.refresh = function () {
  281. // Re-add
  282. this.addEvents();
  283. };
  284.  
  285. /**
  286. * Displays the tooltip
  287. * @param data
  288. */
  289. this.show = function (data) {
  290.  
  291. $("#tooltip").html(data).show();
  292. };
  293.  
  294. /**
  295. * Moves tooltip
  296. * @param e
  297. */
  298. this.move = function(e)
  299. {
  300. // Get half of the width
  301. var width = ($("#tooltip").css("width").replace("px", "") / 2);
  302.  
  303. // Position it at the mouse, and center
  304. $("#tooltip").css("left", e.pageX - width).css("top", e.pageY + 25);
  305. };
  306.  
  307. this.AllGems = false;
  308.  
  309. /**
  310. * @return {boolean}
  311. * @return {boolean}
  312. */
  313. this.GetAllPlayerGems = function () {
  314. if (this.AllGems)
  315. return this.AllGems;
  316.  
  317. var AllGems = [];
  318. AllGems[SOCKET_COLOR_META] = [];
  319. AllGems[SOCKET_COLOR_RED] = [];
  320. AllGems[SOCKET_COLOR_YELLOW] = [];
  321. AllGems[SOCKET_COLOR_BLUE] = [];
  322.  
  323. $.each(TooltipPlayerData, function (slot, item) {
  324. var Gems = item.gems;
  325.  
  326. if (Gems) {
  327. $.each(Gems, function (i, gem) {
  328. var GemColor = parseInt(gem.color);
  329.  
  330. if (GemColor.hasFlag(SOCKET_COLOR_META)) {
  331. AllGems[SOCKET_COLOR_META].push(gem);
  332. }
  333.  
  334. if (GemColor.hasFlag(SOCKET_COLOR_RED)) {
  335. AllGems[SOCKET_COLOR_RED].push(gem);
  336. }
  337.  
  338. if (GemColor.hasFlag(SOCKET_COLOR_YELLOW)) {
  339. AllGems[SOCKET_COLOR_YELLOW].push(gem);
  340. }
  341.  
  342. if (GemColor.hasFlag(SOCKET_COLOR_BLUE)) {
  343. AllGems[SOCKET_COLOR_BLUE].push(gem);
  344. }
  345. });
  346. }
  347. });
  348.  
  349. //save
  350. this.AllGems = AllGems;
  351.  
  352. //return
  353. return this.AllGems;
  354. };
  355.  
  356. /**
  357. * Item tooltip object
  358. */
  359. this.Item = new function () {
  360. /**
  361. * Loading HTML
  362. */
  363. this.loading = "Loading...";
  364.  
  365. /**
  366. * The currently displayed item ID
  367. */
  368. this.currentId = false;
  369.  
  370. /**
  371. * Used to interrupt the ajax in progress on mouse out
  372. */
  373. this.currentAjax = null;
  374.  
  375. /**
  376. * Runtime cache
  377. */
  378. this.cache = {
  379. gems: [],
  380. spells: []
  381. };
  382.  
  383. /**
  384. * @return {string}
  385. * @return {string}
  386. * @return {string}
  387. * @return {string}
  388. * @return {string}
  389. */
  390. this.GemColorString = function (id) {
  391. switch (parseInt(id)) {
  392. case 1:
  393. return 'Meta';
  394. case 2:
  395. return 'Red';
  396. case 4:
  397. return 'Yellow';
  398. case 8:
  399. return 'Blue';
  400. }
  401.  
  402. return 'Desconocida ' + id;
  403. };
  404.  
  405. /**
  406. * Load an item and display it in the tooltip
  407. * @param element
  408. * @param callback
  409. */
  410. this.get = function (element, callback) {
  411. var obj = $(element);
  412. var realm = obj.attr("data-realm");
  413. var id = obj.attr("rel-e").replace("item=", "");
  414.  
  415. var slot = parseInt(obj.attr("data-item-slot"));
  416.  
  417. //try getting the visit cache
  418. var cache = $.data(element, 'tooltip-cache');
  419.  
  420. TooltipExtended.Item.currentId = id;
  421.  
  422. if (typeof cache != 'undefined') {
  423. callback(cache)
  424. }
  425. else {
  426. callback(this.loading);
  427.  
  428. var RequiredGems = 0;
  429. var MatchedGems = 0;
  430.  
  431. TooltipExtended.Item.currentAjax = $.get(Config.URL + "tooltip/" + realm + "/" + id, function (data) {
  432. data = $(data);
  433.  
  434. //Check required matching sockets for sock bonus
  435. data.find('.socket-slot').each(function (i, s) {
  436. if ($(s).hasClass('socket-required')) {
  437. //increase the required gems count
  438. RequiredGems++;
  439. }
  440. });
  441.  
  442. //handle item player data
  443. if (typeof TooltipPlayerData != 'undefined' && (slot in TooltipPlayerData)) {
  444. var ItemPlayerData = TooltipPlayerData[slot];
  445.  
  446. //handle enchants
  447. if (ItemPlayerData.enchant) {
  448. data.find('#tooltip-item-enchantments').html(ItemPlayerData.enchant.description);
  449. }
  450.  
  451. //handle extra sockets
  452. if (ItemPlayerData.hasExtraSocket) {
  453. data.find('#tooltip-item-sockets').append('<span class="socket-slot socket-prismatic q0">Ranura Prismática</span>');
  454. }
  455.  
  456. //handle gems
  457. if (ItemPlayerData.gems) {
  458. //loop the gems
  459. $.each(ItemPlayerData.gems, function (key, gem) {
  460. var GemPosition = gem.slot;
  461.  
  462. data.find('.socket-slot').each(function (i, s) {
  463. if (i == GemPosition) {
  464. //Set the gem text
  465. $(s).html(gem.text);
  466.  
  467. //Metas should be activated only once checked
  468. if (parseInt(gem.color) != SOCKET_COLOR_META)
  469. $(s).addClass('q1');
  470.  
  471. //Check if we have an icon
  472. if (typeof gem.icon == 'string') {
  473. $(s).css('background-image', 'url(http://wow.zamimg.com/images/wow/icons/tiny/' + gem.icon + '.gif)');
  474. }
  475. else {
  476. //Check the runtine cache
  477. if (typeof TooltipExtended.Item.cache.gems[gem.GemID] == 'undefined') {
  478. //Finally if no icon was found, pull one
  479. $.get(Config.URL + "icon/get/" + realm + "/" + gem.GemID, function (gemIconData) {
  480. $(s).css('background-image', 'url(http://wow.zamimg.com/images/wow/icons/tiny/' + gemIconData + '.gif)');
  481. //save to cache
  482. TooltipExtended.Item.cache.gems[gem.GemID] = gemIconData;
  483. });
  484. }
  485. else {
  486. $(s).css('background-image', 'url(http://wow.zamimg.com/images/wow/icons/tiny/' + TooltipExtended.Item.cache.gems[gem.GemID] + '.gif)');
  487. }
  488. }
  489.  
  490. //Check if the socket is required for socket bonus
  491. if ($(s).hasClass('socket-required')) {
  492. var SocketColor = parseInt($(s).attr('data-socket-color'));
  493. var GemColor = parseInt(gem.color);
  494. //check if this game matches this socket
  495. if (GemColor.hasFlag(SocketColor)) {
  496. MatchedGems++;
  497. }
  498. }
  499.  
  500. //Check for meta requiries
  501. if (parseInt(gem.color) == SOCKET_COLOR_META) {
  502. var TotalGemRequierementsMet = 0;
  503.  
  504. if (gem.requires) {
  505. //Reverse the array order
  506. var Requiries = gem.requires.reverse();
  507.  
  508. //Fetch all the gems
  509. var AllGems = TooltipExtended.GetAllPlayerGems();
  510.  
  511. $.each(Requiries, function (kk, req) {
  512. var text;
  513. var isActive = false;
  514.  
  515. //Switch between the diferent comparators
  516. switch (parseInt(req.comparator)) {
  517. case 2:
  518. text = 'Requires less ' + TooltipExtended.Item.GemColorString(req.color) + ' gems than ' + TooltipExtended.Item.GemColorString(req.compareColor) + ' gems';
  519. if (AllGems[parseInt(req.color)].length < AllGems[parseInt(req.compareColor)].length) {
  520. isActive = true;
  521. TotalGemRequierementsMet++;
  522. }
  523. break;
  524. case 3:
  525. text = 'Requires more ' + TooltipExtended.Item.GemColorString(req.color) + ' gems than ' + TooltipExtended.Item.GemColorString(req.compareColor) + ' gems';
  526. if (AllGems[parseInt(req.color)].length > AllGems[parseInt(req.compareColor)].length) {
  527. isActive = true;
  528. TotalGemRequierementsMet++;
  529. }
  530. break;
  531. case 5:
  532. text = 'Requires at least ' + req.count + ' ' + TooltipExtended.Item.GemColorString(req.color) + ' gem' + (req.count > 1 ? 's' : '');
  533. if (AllGems[parseInt(req.color)].length >= parseInt(req.count)) {
  534. isActive = true;
  535. TotalGemRequierementsMet++;
  536. }
  537. break;
  538. }
  539.  
  540. //Append the text
  541. $(s).after('<br /><span class="meta-socket-requires ' + (isActive ? 'q1' : 'q0') + '">' + text + '</span>');
  542. });
  543. }
  544.  
  545. //Check if all reqs are met
  546. if (!gem.requires || TotalGemRequierementsMet == gem.requires.length) {
  547. $(s).addClass('q1').removeClass('q0');
  548. }
  549. }
  550. }
  551. });
  552. });
  553. }
  554.  
  555. //handle sock bonus
  556. if (RequiredGems > 0) {
  557. if (MatchedGems >= RequiredGems)
  558. data.find('#tooltip-item-sock-bonus').addClass('q2');
  559. }
  560. }
  561.  
  562. //handle active item set pieces
  563. if (typeof TooltipEquippedItems != 'undefined') {
  564. //loop trough the itemset pieces
  565. data.find('.item-set-piece').each(function (i, e) {
  566. var possibleEntriesString = $(e).attr('data-possible-entries');
  567. //split into array
  568. var possibleEntries = [];
  569. //make sure we have more than 1 entry
  570. if (possibleEntriesString.indexOf(':') > -1) {
  571. possibleEntries = possibleEntriesString.split(':');
  572. }
  573. else {
  574. possibleEntries[0] = possibleEntriesString;
  575. }
  576. //loop the possible entries and check if one of the is equipped
  577. $.each(possibleEntries, function (i2, v2) {
  578. if ($.inArray(parseInt(v2), TooltipEquippedItems) > -1) {
  579. //active the piece
  580. $(e).addClass('q8');
  581. $(e).addClass('item-set-active-piece');
  582. }
  583. });
  584. });
  585. //get the active pieces count
  586. var activePiecesCount = data.find('.item-set-active-piece').length;
  587. //update the equipped item set pieces count
  588. if (data.find('#tooltip-item-set-count').length > 0) {
  589. data.find('#tooltip-item-set-count').html(activePiecesCount);
  590. }
  591. //update the set bonuses
  592. if (activePiecesCount > 0) {
  593. data.find('.item-set-bonus').each(function (i, e) {
  594. var requiredPieces = $(e).attr('data-bonus-required-items');
  595. //activate the set bonus
  596. if (activePiecesCount >= requiredPieces) {
  597. $(e).addClass('q2');
  598. }
  599. });
  600. }
  601. }
  602.  
  603. // Cache it this visit
  604. $.data(element, 'tooltip-cache', data);
  605.  
  606. // Make sure it's still visible
  607. if ($("#tooltip").is(":visible") && TooltipExtended.Item.currentId == id) {
  608. callback(data);
  609. }
  610. });
  611. }
  612. }
  613. }
  614. }
  615.  
  616. var TooltipExtended = new TooltipExtended();
  617.  
  618. //initialize the extended tooltip
  619. TooltipExtended.initialize();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement