This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathElementHrchyBreadcrumbHandler.js
60 lines (46 loc) · 1.72 KB
/
ElementHrchyBreadcrumbHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @author Swagatam Mitra
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, document, console, brackets, $, Mustache */
define(function (require, exports, module) {
"use strict";
var lastselectedElement = null;
var breadCrumbItem = '<li><a href="#">{{selector}}</a></li>';
var AppInit = brackets.getModule("utils/AppInit");
function _bindClickHandler(target){
var selector = '';
if(target.id){
selector = "#"+target.id;
}
var base = $(breadCrumbItem.replace("{{selector}}",target.tagName+selector)).prependTo('#breadcrumb');
base.on('click',function(){
$("#html-design-editor").trigger("select.element",[target]);
});
}
function _showBreadcrumb(){
var hrchy = [];
var element = lastselectedElement;
if(lastselectedElement){
$("#breadcrumb").html("");
while(element!==null && element.tagName!== 'HTML'){
_bindClickHandler(element);
element = element.parentElement;
}
}
}
$(document).on("element.selected","#html-design-editor",function(event,element){
lastselectedElement = element;
_showBreadcrumb();
});
$(document).on("refresh.element.selection","#html-design-editor",function(event,element){
_showBreadcrumb();
});
$(document).on("deselect.all","#html-design-editor",function(event){
lastselectedElement = null;
$("#breadcrumb").html("");
});
AppInit.appReady(function () {
$('<ul id="breadcrumb"></ul>').insertAfter("#status-file");
});
});