From 7acee5186bd6b22a9ffc75593b4c95ff4926a94c Mon Sep 17 00:00:00 2001 From: Rodrigo Fernandes Date: Fri, 12 Feb 2016 23:11:59 +0000 Subject: [PATCH] Add url hashtag for file summary state override --- bower.json | 2 +- dist/diff2html-ui.js | 19 ++++++++++++++++++- dist/diff2html-ui.min.js | 2 +- package.json | 2 +- src/ui/js/diff2html-ui.js | 19 ++++++++++++++++++- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index df1428f..fbb29e1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "diff2html", - "version": "1.3.0", + "version": "1.3.2", "homepage": "http://rtfpessoa.github.io/diff2html/", "description": "Fast Diff to colorized HTML", "keywords": [ diff --git a/dist/diff2html-ui.js b/dist/diff2html-ui.js index b5ea749..607d445 100644 --- a/dist/diff2html-ui.js +++ b/dist/diff2html-ui.js @@ -80,11 +80,16 @@ Diff2HtmlUI.prototype.fileListCloseable = function(targetId, startVisible) { var $target = this._getTarget(targetId); + var hashTag = this._getHashTag(); + var $showBtn = $target.find(".d2h-show"); var $hideBtn = $target.find(".d2h-hide"); var $fileList = $target.find(".d2h-file-list"); - if (startVisible) show(); else hide(); + if (hashTag === 'files-summary-show') show(); + else if (hashTag === 'files-summary-hide') hide(); + else if (startVisible) show(); + else hide(); $showBtn.click(show); $hideBtn.click(hide); @@ -155,6 +160,18 @@ return distinctLanguages; }; + Diff2HtmlUI.prototype._getHashTag = function() { + var docUrl = document.URL; + var hashTagIndex = docUrl.indexOf('#'); + + var hashTag = null; + if (hashTagIndex != -1) { + hashTag = docUrl.substr(hashTagIndex + 1); + } + + return hashTag; + }; + module.exports.Diff2HtmlUI = Diff2HtmlUI; // Expose diff2html in the browser diff --git a/dist/diff2html-ui.min.js b/dist/diff2html-ui.min.js index 7b5adfe..2b66d2e 100644 --- a/dist/diff2html-ui.min.js +++ b/dist/diff2html-ui.min.js @@ -1 +1 @@ -!function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports){(function(global){!function(){function Diff2HtmlUI(config){var cfg=config||{};cfg.diff?diffJson=Diff2Html.getJsonFromDiff(cfg.diff):cfg.json&&(diffJson=cfg.json)}var diffJson=null,defaultTarget="body";Diff2HtmlUI.prototype.draw=function(targetId,config){var cfg=config||{},$target=this._getTarget(targetId);$target.html(Diff2Html.getPrettyHtml(diffJson,cfg))},Diff2HtmlUI.prototype.fileListCloseable=function(targetId,startVisible){function show(){$showBtn.hide(),$hideBtn.show(),$fileList.show()}function hide(){$hideBtn.hide(),$showBtn.show(),$fileList.hide()}var $target=this._getTarget(targetId),$showBtn=$target.find(".d2h-show"),$hideBtn=$target.find(".d2h-hide"),$fileList=$target.find(".d2h-file-list");startVisible?show():hide(),$showBtn.click(show),$hideBtn.click(hide)},Diff2HtmlUI.prototype.highlightCode=function(targetId){var that=this,$target=that._getTarget(targetId),languages=that._getLanguages($target);console.log(languages),hljs.configure({languages:languages});var $codeLines=$target.find(".d2h-code-line-ctn");$codeLines.map(function(i,line){hljs.highlightBlock(line)})},Diff2HtmlUI.prototype._getTarget=function(targetId){var $target;return $target=$(targetId?targetId:defaultTarget)},Diff2HtmlUI.prototype._getLanguages=function($target){var allFileLanguages=[];diffJson?allFileLanguages=diffJson.map(function(line){return line.language}):(console.log($target.find(".d2h-file-wrapper")),$target.find(".d2h-file-wrapper").map(function(i,file){allFileLanguages.push($(file).data("lang"))}));var distinctLanguages=allFileLanguages.filter(function(v,i){return allFileLanguages.indexOf(v)===i});return distinctLanguages},module.exports.Diff2HtmlUI=Diff2HtmlUI,global.Diff2HtmlUI=Diff2HtmlUI}()}).call(exports,function(){return this}())}]); \ No newline at end of file +!function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports){(function(global){!function(){function Diff2HtmlUI(config){var cfg=config||{};cfg.diff?diffJson=Diff2Html.getJsonFromDiff(cfg.diff):cfg.json&&(diffJson=cfg.json)}var diffJson=null,defaultTarget="body";Diff2HtmlUI.prototype.draw=function(targetId,config){var cfg=config||{},$target=this._getTarget(targetId);$target.html(Diff2Html.getPrettyHtml(diffJson,cfg))},Diff2HtmlUI.prototype.fileListCloseable=function(targetId,startVisible){function show(){$showBtn.hide(),$hideBtn.show(),$fileList.show()}function hide(){$hideBtn.hide(),$showBtn.show(),$fileList.hide()}var $target=this._getTarget(targetId),hashTag=this._getHashTag(),$showBtn=$target.find(".d2h-show"),$hideBtn=$target.find(".d2h-hide"),$fileList=$target.find(".d2h-file-list");"files-summary-show"===hashTag?show():"files-summary-hide"===hashTag?hide():startVisible?show():hide(),$showBtn.click(show),$hideBtn.click(hide)},Diff2HtmlUI.prototype.highlightCode=function(targetId){var that=this,$target=that._getTarget(targetId),languages=that._getLanguages($target);console.log(languages),hljs.configure({languages:languages});var $codeLines=$target.find(".d2h-code-line-ctn");$codeLines.map(function(i,line){hljs.highlightBlock(line)})},Diff2HtmlUI.prototype._getTarget=function(targetId){var $target;return $target=$(targetId?targetId:defaultTarget)},Diff2HtmlUI.prototype._getLanguages=function($target){var allFileLanguages=[];diffJson?allFileLanguages=diffJson.map(function(line){return line.language}):(console.log($target.find(".d2h-file-wrapper")),$target.find(".d2h-file-wrapper").map(function(i,file){allFileLanguages.push($(file).data("lang"))}));var distinctLanguages=allFileLanguages.filter(function(v,i){return allFileLanguages.indexOf(v)===i});return distinctLanguages},Diff2HtmlUI.prototype._getHashTag=function(){var docUrl=document.URL,hashTagIndex=docUrl.indexOf("#"),hashTag=null;return-1!=hashTagIndex&&(hashTag=docUrl.substr(hashTagIndex+1)),hashTag},module.exports.Diff2HtmlUI=Diff2HtmlUI,global.Diff2HtmlUI=Diff2HtmlUI}()}).call(exports,function(){return this}())}]); \ No newline at end of file diff --git a/package.json b/package.json index 8073fc4..116b4fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "diff2html", - "version": "1.3.1", + "version": "1.3.2", "homepage": "http://rtfpessoa.github.io/diff2html/", "description": "Fast Diff to colorized HTML", "keywords": [ diff --git a/src/ui/js/diff2html-ui.js b/src/ui/js/diff2html-ui.js index 856a9e6..f7fd75f 100644 --- a/src/ui/js/diff2html-ui.js +++ b/src/ui/js/diff2html-ui.js @@ -34,11 +34,16 @@ Diff2HtmlUI.prototype.fileListCloseable = function(targetId, startVisible) { var $target = this._getTarget(targetId); + var hashTag = this._getHashTag(); + var $showBtn = $target.find(".d2h-show"); var $hideBtn = $target.find(".d2h-hide"); var $fileList = $target.find(".d2h-file-list"); - if (startVisible) show(); else hide(); + if (hashTag === 'files-summary-show') show(); + else if (hashTag === 'files-summary-hide') hide(); + else if (startVisible) show(); + else hide(); $showBtn.click(show); $hideBtn.click(hide); @@ -109,6 +114,18 @@ return distinctLanguages; }; + Diff2HtmlUI.prototype._getHashTag = function() { + var docUrl = document.URL; + var hashTagIndex = docUrl.indexOf('#'); + + var hashTag = null; + if (hashTagIndex != -1) { + hashTag = docUrl.substr(hashTagIndex + 1); + } + + return hashTag; + }; + module.exports.Diff2HtmlUI = Diff2HtmlUI; // Expose diff2html in the browser