Path: blob/master/webroot/rsrc/js/application/differential/behavior-populate.js
12242 views
/**1* @provides javelin-behavior-differential-populate2* @requires javelin-behavior3* javelin-dom4* javelin-stratcom5* phabricator-tooltip6* phabricator-diff-changeset-list7* phabricator-diff-changeset8* phuix-formation-view9* @javelin10*/1112JX.behavior('differential-populate', function(config, statics) {1314// When we perform a Quicksand navigation, deactivate the changeset lists on15// the current page and activate the changeset lists on the new page.16var onredraw = function(page_id) {17// If the current page is already active, we don't need to do anything.18if (statics.pageID === page_id) {19return;20}2122var ii;2324// Put the old lists to sleep.25var old_lists = get_lists(statics.pageID);26for (ii = 0; ii < old_lists.length; ii++) {27old_lists[ii].sleep();28}29statics.pageID = null;3031// Awaken the new lists, if they exist.32if (statics.pages.hasOwnProperty(page_id)) {33var new_lists = get_lists(page_id);34for (ii = 0; ii < new_lists.length; ii++) {35new_lists[ii].wake();36}3738statics.pageID = page_id;39}40};4142// Get changeset lists on the current page.43var get_lists = function(page_id) {44if (page_id === null) {45return [];46}4748return statics.pages[page_id] || [];49};5051if (!statics.installed) {52statics.installed = true;53statics.pages = {};54statics.pageID = null;5556JX.Stratcom.listen('quicksand-redraw', null, function(e) {57onredraw(e.getData().newResponseID);58});59}6061var changeset_list = new JX.DiffChangesetList()62.setTranslations(JX.phtize(config.pht))63.setInlineURI(config.inlineURI)64.setInlineListURI(config.inlineListURI)65.setIsStandalone(config.isStandalone);6667if (config.formationViewID) {68var formation_node = JX.$(config.formationViewID);69var formation_view = new JX.PHUIXFormationView(formation_node);70changeset_list.setFormationView(formation_view);71formation_view.start();72}7374for (var ii = 0; ii < config.changesetViewIDs.length; ii++) {75var id = config.changesetViewIDs[ii];76var node = JX.$(id);77var changeset = changeset_list.newChangesetForNode(node);78if (changeset.shouldAutoload()) {79changeset.setStabilize(true).load();80}81}8283// Install and activate the current page.84var page_id = JX.Quicksand.getCurrentPageID();85statics.pages[page_id] = [changeset_list];86onredraw(page_id);8788var highlighted = null;89var highlight_class = null;9091JX.Stratcom.listen(92['mouseover', 'mouseout'],93['differential-changeset', 'tag:td'],94function(e) {95var t = e.getTarget();9697// NOTE: Using className is not best practice, but the diff UI is perf98// sensitive.99if (!t.className.match(/cov|copy/)) {100return;101}102103if (e.getType() == 'mouseout') {104JX.Tooltip.hide();105if (highlighted) {106JX.DOM.alterClass(highlighted, highlight_class, false);107highlighted = null;108}109} else {110highlight_class = null;111var msg;112var align = 'W';113var sibling = 'previousSibling';114var width = 120;115if (t.className.match(/cov-C/)) {116msg = 'Covered';117highlight_class = 'source-cov-C';118} else if (t.className.match(/cov-U/)) {119msg = 'Not Covered';120highlight_class = 'source-cov-U';121} else if (t.className.match(/cov-N/)) {122msg = 'Not Executable';123highlight_class = 'source-cov-N';124} else {125var match = /new-copy|new-move/.exec(t.className);126if (match) {127sibling = 'nextSibling';128width = 500;129msg = JX.Stratcom.getData(t).msg;130highlight_class = match[0];131}132}133134if (msg) {135JX.Tooltip.show(t, width, align, msg);136}137138if (highlight_class) {139highlighted = t[sibling];140JX.DOM.alterClass(highlighted, highlight_class, true);141}142}143144});145146147});148149150