diff2html
Advanced tools
Comparing version 2.0.0-beta16 to 2.0.0-beta17
@@ -19,2 +19,3 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var defaultTarget = "body"; | ||
var currentSelectionColumnId = -1; | ||
@@ -29,2 +30,4 @@ function Diff2HtmlUI(config) { | ||
} | ||
this._initSelection(); | ||
} | ||
@@ -137,2 +140,50 @@ | ||
Diff2HtmlUI.prototype._initSelection = function() { | ||
var body = $('body'); | ||
var that = this; | ||
body.on('mousedown', '.d2h-diff-table', function(event) { | ||
var target = $(event.target); | ||
var table = target.closest('.d2h-diff-table'); | ||
if (target.closest('.d2h-code-line,.d2h-code-side-line').length) { | ||
table.removeClass('selecting-left'); | ||
table.addClass('selecting-right'); | ||
currentSelectionColumnId = 1; | ||
} else if (target.closest('.d2h-code-linenumber,.d2h-code-side-linenumber').length) { | ||
table.removeClass('selecting-right'); | ||
table.addClass('selecting-left'); | ||
currentSelectionColumnId = 0; | ||
} | ||
}); | ||
body.on('copy', '.d2h-diff-table', function(event) { | ||
var clipboardData = event.originalEvent.clipboardData; | ||
var text = that._getSelectedText(); | ||
clipboardData.setData('text', text); | ||
event.preventDefault(); | ||
}); | ||
}; | ||
Diff2HtmlUI.prototype._getSelectedText = function() { | ||
var sel = window.getSelection(); | ||
var range = sel.getRangeAt(0); | ||
var doc = range.cloneContents(); | ||
var nodes = doc.querySelectorAll('tr'); | ||
var text = ''; | ||
var idx = currentSelectionColumnId; | ||
if (nodes.length === 0) { | ||
text = doc.textContent; | ||
} else { | ||
[].forEach.call(nodes, function(tr, i) { | ||
var td = tr.cells[tr.cells.length === 1 ? 0 : idx]; | ||
text += (i ? '\n' : '') + td.textContent.replace(/(?:\r\n|\r|\n)/g, ''); | ||
}); | ||
} | ||
return text; | ||
}; | ||
module.exports.Diff2HtmlUI = Diff2HtmlUI; | ||
@@ -139,0 +190,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module){(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);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"object"==typeof targetId&&targetId instanceof jQuery?$target=targetId:"string"==typeof targetId?$target=$(targetId):(console.error("Wrong target provided! Falling back to default value 'body'."),console.log("Please provide a jQuery object or a valid DOM query string."),$target=$(defaultTarget)),$target},Diff2HtmlUI.prototype._getLanguages=function($target){var allFileLanguages=[];return diffJson?allFileLanguages=diffJson.map(function(line){return line.language}):$target.find(".d2h-file-wrapper").map(function(i,file){allFileLanguages.push($(file).data("lang"))}),this._distinct(allFileLanguages)},Diff2HtmlUI.prototype._getHashTag=function(){var docUrl=document.URL,hashTagIndex=docUrl.indexOf("#"),hashTag=null;return-1!==hashTagIndex&&(hashTag=docUrl.substr(hashTagIndex+1)),hashTag},Diff2HtmlUI.prototype._distinct=function(collection){return collection.filter(function(v,i){return collection.indexOf(v)===i})},module.exports.Diff2HtmlUI=Diff2HtmlUI,global.Diff2HtmlUI=Diff2HtmlUI}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1]); | ||
!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module){(function(global){!function(){function Diff2HtmlUI(config){var cfg=config||{};cfg.diff?diffJson=Diff2Html.getJsonFromDiff(cfg.diff):cfg.json&&(diffJson=cfg.json),this._initSelection()}var diffJson=null,defaultTarget="body",currentSelectionColumnId=-1;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);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"object"==typeof targetId&&targetId instanceof jQuery?$target=targetId:"string"==typeof targetId?$target=$(targetId):(console.error("Wrong target provided! Falling back to default value 'body'."),console.log("Please provide a jQuery object or a valid DOM query string."),$target=$(defaultTarget)),$target},Diff2HtmlUI.prototype._getLanguages=function($target){var allFileLanguages=[];return diffJson?allFileLanguages=diffJson.map(function(line){return line.language}):$target.find(".d2h-file-wrapper").map(function(i,file){allFileLanguages.push($(file).data("lang"))}),this._distinct(allFileLanguages)},Diff2HtmlUI.prototype._getHashTag=function(){var docUrl=document.URL,hashTagIndex=docUrl.indexOf("#"),hashTag=null;return-1!==hashTagIndex&&(hashTag=docUrl.substr(hashTagIndex+1)),hashTag},Diff2HtmlUI.prototype._distinct=function(collection){return collection.filter(function(v,i){return collection.indexOf(v)===i})},Diff2HtmlUI.prototype._initSelection=function(){var body=$("body"),that=this;body.on("mousedown",".d2h-diff-table",function(event){var target=$(event.target),table=target.closest(".d2h-diff-table");target.closest(".d2h-code-line,.d2h-code-side-line").length?(table.removeClass("selecting-left"),table.addClass("selecting-right"),currentSelectionColumnId=1):target.closest(".d2h-code-linenumber,.d2h-code-side-linenumber").length&&(table.removeClass("selecting-right"),table.addClass("selecting-left"),currentSelectionColumnId=0)}),body.on("copy",".d2h-diff-table",function(event){var clipboardData=event.originalEvent.clipboardData,text=that._getSelectedText();clipboardData.setData("text",text),event.preventDefault()})},Diff2HtmlUI.prototype._getSelectedText=function(){var sel=window.getSelection(),range=sel.getRangeAt(0),doc=range.cloneContents(),nodes=doc.querySelectorAll("tr"),text="",idx=currentSelectionColumnId;return 0===nodes.length?text=doc.textContent:[].forEach.call(nodes,function(tr,i){var td=tr.cells[1===tr.cells.length?0:idx];text+=(i?"\n":"")+td.textContent.replace(/(?:\r\n|\r|\n)/g,"")}),text},module.exports.Diff2HtmlUI=Diff2HtmlUI,global.Diff2HtmlUI=Diff2HtmlUI}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1]); |
{ | ||
"name": "diff2html", | ||
"version": "2.0.0-beta16", | ||
"version": "2.0.0-beta17", | ||
"homepage": "http://rtfpessoa.github.io/diff2html/", | ||
@@ -5,0 +5,0 @@ "description": "Fast Diff to colorized HTML", |
@@ -22,7 +22,7 @@ # diff2html | ||
* `line-by-line` and `side-by-side` diff | ||
* Line by line and Side by side diff | ||
* new and old line numbers | ||
* New and old line numbers | ||
* inserted and removed lines | ||
* Inserted and removed lines | ||
@@ -35,2 +35,4 @@ * GitHub like style | ||
* Easy code selection | ||
## Online Example | ||
@@ -37,0 +39,0 @@ |
@@ -17,2 +17,3 @@ /* | ||
var defaultTarget = "body"; | ||
var currentSelectionColumnId = -1; | ||
@@ -27,2 +28,4 @@ function Diff2HtmlUI(config) { | ||
} | ||
this._initSelection(); | ||
} | ||
@@ -135,2 +138,50 @@ | ||
Diff2HtmlUI.prototype._initSelection = function() { | ||
var body = $('body'); | ||
var that = this; | ||
body.on('mousedown', '.d2h-diff-table', function(event) { | ||
var target = $(event.target); | ||
var table = target.closest('.d2h-diff-table'); | ||
if (target.closest('.d2h-code-line,.d2h-code-side-line').length) { | ||
table.removeClass('selecting-left'); | ||
table.addClass('selecting-right'); | ||
currentSelectionColumnId = 1; | ||
} else if (target.closest('.d2h-code-linenumber,.d2h-code-side-linenumber').length) { | ||
table.removeClass('selecting-right'); | ||
table.addClass('selecting-left'); | ||
currentSelectionColumnId = 0; | ||
} | ||
}); | ||
body.on('copy', '.d2h-diff-table', function(event) { | ||
var clipboardData = event.originalEvent.clipboardData; | ||
var text = that._getSelectedText(); | ||
clipboardData.setData('text', text); | ||
event.preventDefault(); | ||
}); | ||
}; | ||
Diff2HtmlUI.prototype._getSelectedText = function() { | ||
var sel = window.getSelection(); | ||
var range = sel.getRangeAt(0); | ||
var doc = range.cloneContents(); | ||
var nodes = doc.querySelectorAll('tr'); | ||
var text = ''; | ||
var idx = currentSelectionColumnId; | ||
if (nodes.length === 0) { | ||
text = doc.textContent; | ||
} else { | ||
[].forEach.call(nodes, function(tr, i) { | ||
var td = tr.cells[tr.cells.length === 1 ? 0 : idx]; | ||
text += (i ? '\n' : '') + td.textContent.replace(/(?:\r\n|\r|\n)/g, ''); | ||
}); | ||
} | ||
return text; | ||
}; | ||
module.exports.Diff2HtmlUI = Diff2HtmlUI; | ||
@@ -137,0 +188,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
276786
5240
179