Skip to content

Commit

Permalink
Add remove setting api
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Aug 23, 2018
1 parent d66e1de commit 548cc9b
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 97 deletions.
11 changes: 11 additions & 0 deletions doc/TOOL_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ Customization for all tools.

Clear settings.

### remove

Remove setting.

|Name|Type |Desc |
|----|------|-------------|
|cfg |object|Config object|
|name|string|Option name |

### text

Add text.
Expand Down Expand Up @@ -308,4 +317,6 @@ settings.text('Test')
.select(cfg, 'testSelect', 'Test Select', ['select1', 'select2'])
.range(cfg, 'testRange', 'Test Range', {min: 0, max: 1, step: 0.1})
.separator();

settings.remove(cfg, 'testBool')
```
38 changes: 31 additions & 7 deletions src/Console/Console.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ export default class Console extends Tool {
}
init($el, container) {
super.init($el)
this._container = container

this._appendTpl()

this._initLogger()
this._exposeLogger()
this._rejectionHandler = e => this._logger.error(e.reason)

this._initCfg(container)
this._bindEvent(container)
this._initCfg()
this._bindEvent()
}
show() {
super.show()
Expand Down Expand Up @@ -88,6 +89,7 @@ export default class Console extends Tool {
this.ignoreGlobalErr()
this.restoreConsole()
this._unregisterListener()
this._rmCfg()
}
_registerListener() {
this._scaleListener = scale => (this._scale = scale)
Expand Down Expand Up @@ -142,7 +144,8 @@ export default class Console extends Tool {
})
)
}
_bindEvent(container) {
_bindEvent() {
let container = this._container
let $input = this._$input,
$inputBtns = this._$inputBtns,
$control = this._$control,
Expand Down Expand Up @@ -202,9 +205,29 @@ export default class Console extends Tool {

this._$inputBtns.show()
}
_initCfg(container) {
let sources = container.get('sources'),
logger = this._logger
_rmCfg() {
let cfg = this.config

let settings = this._container.get('settings')
if (!settings) return

settings
.remove(cfg, 'catchGlobalErr')
.remove(cfg, 'overrideConsole')
.remove(cfg, 'displayExtraInfo')
.remove(cfg, 'displayUnenumerable')
.remove(cfg, 'displayGetterVal')
.remove(cfg, 'lazyEvaluation')
.remove(cfg, 'viewLogInSources')
.remove(cfg, 'displayIfErr')
.remove(cfg, 'useWorker')
.remove(cfg, 'maxLogNum')
.remove('Console')
}
_initCfg() {
let container = this._container
let sources = container.get('sources')
let logger = this._logger

let cfg = (this.config = Settings.createCfg('console', {
catchGlobalErr: true,
Expand Down Expand Up @@ -271,8 +294,9 @@ export default class Console extends Tool {
.switch(cfg, 'lazyEvaluation', 'Lazy Evaluation')

if (isWorkerSupported) settings.switch(cfg, 'useWorker', 'Use Web Worker')
if (sources)
if (sources) {
settings.switch(cfg, 'viewLogInSources', 'View Log In Sources Panel')
}

settings
.select(cfg, 'maxLogNum', 'Max Log Number', [
Expand Down
71 changes: 43 additions & 28 deletions src/Elements/Elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export default class Elements extends Tool {
overrideEventTarget() {
let winEventProto = getWinEventProto()

let origAddEvent = (this._origAddEvent = winEventProto.addEventListener),
origRmEvent = (this._origRmEvent = winEventProto.removeEventListener)
let origAddEvent = (this._origAddEvent = winEventProto.addEventListener)
let origRmEvent = (this._origRmEvent = winEventProto.removeEventListener)

winEventProto.addEventListener = function(type, listener, useCapture) {
addEvent(this, type, listener, useCapture)
Expand Down Expand Up @@ -108,31 +108,32 @@ export default class Elements extends Tool {
this._highlight.destroy()
this._disableObserver()
this.restoreEventTarget()
this._rmCfg()
}
_back() {
if (this._curEl === this._htmlEl) return

let parentQueue = this._curParentQueue,
parent = parentQueue.shift()
let parentQueue = this._curParentQueue
let parent = parentQueue.shift()

while (!isElExist(parent)) parent = parentQueue.shift()

this.set(parent)
}
_bindEvent() {
let self = this,
container = this._container,
select = this._select
let self = this
let container = this._container
let select = this._select

this._$el
.on('click', '.eruda-child', function() {
let idx = $(this).data('idx'),
curEl = self._curEl,
el = curEl.childNodes[idx]
let idx = $(this).data('idx')
let curEl = self._curEl
let el = curEl.childNodes[idx]

if (el && el.nodeType === 3) {
let curTagName = curEl.tagName,
type
let curTagName = curEl.tagName
let type

switch (curTagName) {
case 'SCRIPT':
Expand All @@ -158,8 +159,8 @@ export default class Elements extends Tool {
!isElExist(el) ? self._render() : self.set(el)
})
.on('click', '.eruda-listener-content', function() {
let text = $(this).text(),
sources = container.get('sources')
let text = $(this).text()
let sources = container.get('sources')

if (sources) {
sources.set('js', text)
Expand All @@ -168,9 +169,9 @@ export default class Elements extends Tool {
})
.on('click', '.eruda-breadcrumb', () => {
let data =
this._elData ||
JSON.parse(stringify(this._curEl, { getterVal: true })),
sources = container.get('sources')
this._elData ||
JSON.parse(stringify(this._curEl, { getterVal: true }))
let sources = container.get('sources')

this._elData = data

Expand All @@ -180,9 +181,9 @@ export default class Elements extends Tool {
}
})
.on('click', '.eruda-parent', function() {
let idx = $(this).data('idx'),
curEl = self._curEl,
el = curEl.parentNode
let idx = $(this).data('idx')
let curEl = self._curEl
let el = curEl.parentNode

while (idx-- && el.parentNode) el = el.parentNode

Expand Down Expand Up @@ -258,8 +259,8 @@ export default class Elements extends Tool {
_getData() {
let ret = {}

let el = this._curEl,
cssStore = this._curCssStore
let el = this._curEl
let cssStore = this._curCssStore

let { className, id, attributes, tagName } = el

Expand Down Expand Up @@ -303,8 +304,9 @@ export default class Elements extends Tool {
}
ret.boxModel = boxModel

if (this._rmDefComputedStyle)
if (this._rmDefComputedStyle) {
computedStyle = rmDefComputedStyle(computedStyle)
}
ret.rmDefComputedStyle = this._rmDefComputedStyle
processStyleRules(computedStyle)
ret.computedStyle = computedStyle
Expand Down Expand Up @@ -358,6 +360,18 @@ export default class Elements extends Tool {
}
}
}
_rmCfg() {
let cfg = this.config

let settings = this._container.get('settings')

if (!settings) return

settings
.remove(cfg, 'overrideEventTarget')
.remove(cfg, 'observeElement')
.remove('Elements')
}
_initCfg() {
let cfg = (this.config = Settings.createCfg('elements', {
overrideEventTarget: true,
Expand Down Expand Up @@ -484,9 +498,9 @@ function formatChildNodes(nodes) {
}

function getParents(el) {
let ret = [],
i = 0,
parent = el.parentNode
let ret = []
let i = 0
let parent = el.parentNode

while (parent && parent.nodeType === 1) {
ret.push({
Expand Down Expand Up @@ -566,8 +580,9 @@ function rmEvent(el, type, listener, useCapture = false) {
if (keys(events).length === 0) delete el.erudaEvents
}

let getWinEventProto = () =>
safeGet(window, 'EventTarget.prototype') || window.Node.prototype
let getWinEventProto = () => {
return safeGet(window, 'EventTarget.prototype') || window.Node.prototype
}

let wrapLink = link => `<a href="${link}" target="_blank">${link}</a>`

Expand Down
10 changes: 10 additions & 0 deletions src/Network/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ export default class Network extends Tool {
evalCss.remove(this._style)
this.restoreXhr()
this.restoreFetch()
this._rmCfg()
}
_rmCfg() {
let cfg = this.config

let settings = this._container.get('settings')

if (!settings) return

settings.remove(cfg, 'overrideFetch').remove('Network')
}
_initCfg() {
let cfg = (this.config = Settings.createCfg('network', {
Expand Down
35 changes: 24 additions & 11 deletions src/Resources/Resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default class Resources extends Tool {

this._disableObserver()
evalCss.remove(this._style)
this._rmCfg()
}
refreshScript() {
let scriptData = []
Expand Down Expand Up @@ -179,8 +180,8 @@ export default class Resources extends Tool {
})
} else {
$('img').each(function() {
let $this = $(this),
src = $this.attr('src')
let $this = $(this)
let src = $this.attr('src')

if ($this.data('exclude') === 'true') return

Expand All @@ -206,9 +207,9 @@ export default class Resources extends Tool {
return super.hide()
}
_bindEvent() {
let self = this,
$el = this._$el,
container = this._container
let self = this
let $el = this._$el
let container = this._container

$el
.on('click', '.eruda-refresh-local-storage', () =>
Expand All @@ -231,9 +232,9 @@ export default class Resources extends Tool {
)
.on('click', '.eruda-refresh-image', () => this.refreshImage()._render())
.on('click', '.eruda-delete-storage', function() {
let $this = $(this),
key = $this.data('key'),
type = $this.data('type')
let $this = $(this)
let key = $this.data('key')
let type = $this.data('type')

if (type === 'local') {
localStorage.removeItem(key)
Expand Down Expand Up @@ -267,9 +268,9 @@ export default class Resources extends Tool {
this.refreshCookie()._render()
})
.on('click', '.eruda-storage-val', function() {
let $this = $(this),
key = $this.data('key'),
type = $this.data('type')
let $this = $(this)
let key = $this.data('key')
let type = $this.data('type')

let val =
type === 'local'
Expand Down Expand Up @@ -325,6 +326,18 @@ export default class Resources extends Tool {
}
}
}
_rmCfg() {
let cfg = this.config

let settings = this._container.get('settings')

if (!settings) return

settings
.remove(cfg, 'hideErudaSetting')
.remove(cfg, 'observeElement')
.remove('Resources')
}
_initCfg() {
let cfg = (this.config = Settings.createCfg('resources', {
hideErudaSetting: true,
Expand Down
Loading

0 comments on commit 548cc9b

Please sign in to comment.