-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joel Hughes
committed
Apr 29, 2015
1 parent
be06710
commit 39526f4
Showing
7 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,50 @@ | ||
(function () { | ||
'use strict'; | ||
var textBox, btn, out, savedRange; | ||
|
||
function getContent() { | ||
var innerHTML = toStaticHTML(textBox.innerHTML) | ||
.replace(/(\<|\<\/)div\>/g, '') | ||
.replace(/\<br\>/g, '<br></br>'); | ||
out.innerHTML = innerHTML; | ||
} | ||
|
||
WinJS.Namespace.define('textBox', { | ||
setUp: function () { | ||
textBox = document.getElementById('textBoxIn'); | ||
btn = document.getElementById('textBoxGo'); | ||
out = document.getElementById('textBoxOut'); | ||
|
||
textBox.onbeforepaste = function () { | ||
savedRange = window.getSelection().getRangeAt(0); | ||
|
||
}; | ||
textBox.onpaste = function (e) { | ||
console.log('paste'); | ||
e.preventDefault(); | ||
e.returnValue = false; | ||
var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.getContent(); | ||
if (dataPackageView.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) { | ||
dataPackageView.getTextAsync().done(function (text) { | ||
//var caretPos = getCaretPosition(ti); | ||
//textBox.innerText = textBox.innerText.slice(0, caretPos) + text + ti.innerText.slice(caretPos); | ||
//var caretPos = getCaretPosition(); | ||
console.log(savedRange); | ||
var first = textBox.innerHTML.slice(0, savedRange.startOffset); | ||
first = first.replace(/\<br\>/g, '\n'); | ||
first = first.replace(/\ /g, ' '); | ||
var last = textBox.innerHTML.slice(savedRange.endOffset); | ||
last = last.replace(/\<br\>/g, '\n'); | ||
last = last.replace(/\ \;/g, ' '); | ||
textBox.innerText = first + text + last; | ||
|
||
}, function (e) { | ||
console.error('paste error', e); | ||
}); | ||
} | ||
}; | ||
|
||
btn.addEventListener('pointerdown', getContent, false); | ||
} | ||
}); | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,50 @@ | ||
(function () { | ||
'use strict'; | ||
var textBox, btn, out, savedRange; | ||
|
||
function getContent() { | ||
var innerHTML = toStaticHTML(textBox.innerHTML) | ||
.replace(/(\<|\<\/)div\>/g, '') | ||
.replace(/\<br\>/g, '<br></br>'); | ||
out.innerHTML = innerHTML; | ||
} | ||
|
||
WinJS.Namespace.define('textBox', { | ||
setUp: function () { | ||
textBox = document.getElementById('textBoxIn'); | ||
btn = document.getElementById('textBoxGo'); | ||
out = document.getElementById('textBoxOut'); | ||
|
||
textBox.onbeforepaste = function () { | ||
savedRange = window.getSelection().getRangeAt(0); | ||
|
||
}; | ||
textBox.onpaste = function (e) { | ||
console.log('paste'); | ||
e.preventDefault(); | ||
e.returnValue = false; | ||
var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.getContent(); | ||
if (dataPackageView.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) { | ||
dataPackageView.getTextAsync().done(function (text) { | ||
//var caretPos = getCaretPosition(ti); | ||
//textBox.innerText = textBox.innerText.slice(0, caretPos) + text + ti.innerText.slice(caretPos); | ||
//var caretPos = getCaretPosition(); | ||
console.log(savedRange); | ||
var first = textBox.innerHTML.slice(0, savedRange.startOffset); | ||
first = first.replace(/\<br\>/g, '\n'); | ||
first = first.replace(/\ /g, ' '); | ||
var last = textBox.innerHTML.slice(savedRange.endOffset); | ||
last = last.replace(/\<br\>/g, '\n'); | ||
last = last.replace(/\ \;/g, ' '); | ||
textBox.innerText = first + text + last; | ||
|
||
}, function (e) { | ||
console.error('paste error', e); | ||
}); | ||
} | ||
}; | ||
|
||
btn.addEventListener('pointerdown', getContent, false); | ||
} | ||
}); | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters