- This topic has 11 replies, 2 voices, and was last updated 5 years, 2 months ago by Yuri Kovelenov.
-
AuthorPosts
-
2019-09-04 at 1:39 pm #18410hoodyParticipant
Hey guys Im using the “open file” puzzle to replace a texture on an object.
Is there a way to use another file uploader in the parent document to replace the texture.
I´ve got a basic file uploader from wordpress on a woocommere product page and want the user to be able to use this uploader (located in parent document) to change the texture on the object.
Thanks
2019-09-04 at 2:07 pm #18411Yuri KovelenovStaff2019-09-04 at 2:40 pm #18414hoodyParticipantyes thanks for your answer. i understand but thats not what im trying to achive.
I need the image to be fetched from the original wp uploader (located in parent document on a Woocommerce Product page) – because the image is also used for the woocommerce checkout after clicking the add to cart button.
If I use your uploader there will be no connection to woocommerce, when clicking add to cart.
do you get what i mean?
2019-09-04 at 2:43 pm #18416Yuri KovelenovStaff2019-09-06 at 11:24 am #18476hoodyParticipantIm not sure about that, if it actually exists. Basicly what you suggested first was “triggering” the “open file puzzle” from verge by clicking on an element in the parent document.
But what I need is: triggering an uploader (not the one from verge) that comes from woocommerce and is located in the parent document. Basically its the same file-upload like the one frome verge, but its provided by the woocommerce product itself.
So what i need is a puzzle or a piece of code that can get the image from an “external” (aor any) uploader located in the parent document. Is there a way to detect if any image was uploaded , not only through the open file puzzle?
I attached a screenshot for better understanding and also heres the link: http://brudastan.de/produkt/jajaja
I need to use the file upload from woocommerce, or the image will not be saved wo Cart or checkout page.
I hope you can now better understand what i meant.
Greets
2019-09-06 at 1:16 pm #18478Yuri KovelenovStaffThanks for the details, now I see what you want.
The open file puzzle creates an input element, “clicks” on it, waits until the image is loaded and then saves the loaded image data to a global variable. You can check the generated code in the visual_logic.js file. It looks like this:
function openFile(callback) { _pGlob.openedFile = ''; var input = document.createElement('input'); input.type = 'file'; input.style = 'display: none'; // NOTE: fixes iOS event issue document.body.appendChild(input); input.addEventListener('change', function(event) { var file = event.target.files[0]; var reader = new FileReader(); reader.addEventListener('load', function () { _pGlob.openedFile = reader.result; callback(); document.body.removeChild(input); }, false); reader.readAsDataURL(file); }); if (appInstance.controls) { appInstance.controls.dispose(); appInstance.enableControls(); } input.click(); }
So, instead of that temporary input element, you need to use an existing one provided by Woocommerce. To do that, replace
var input = document.createElement('input');
with
var input = parent.document.getElementsByClassName('wc-pao-addon-file-upload input-text wc-pao-addon-field');
and remove other lines related to input creation and deletion so that it looks like
function openFile(callback) { _pGlob.openedFile = ''; var input = parent.document.getElementsByClassName('wc-pao-addon-file-upload input-text wc-pao-addon-field'); input.addEventListener('change', function(event) { var file = event.target.files[0]; var reader = new FileReader(); reader.addEventListener('load', function () { _pGlob.openedFile = reader.result; callback(); }, false); reader.readAsDataURL(file); }); if (appInstance.controls) { appInstance.controls.dispose(); appInstance.enableControls(); } input.click(); }
The changes in visual_logic.js will be dropped once you save Puzzles again, but at least give this a try.
2019-09-06 at 3:03 pm #18480hoodyParticipantThank you for your answer! When I try your code , i get an error in my console.
v3d.js:1 TypeError: input.addEventListener is not a function (its reffering to line 8 in your code)
2019-09-06 at 3:18 pm #18482Yuri KovelenovStaff2019-09-07 at 1:14 pm #18496hoodyParticipantHi Thanks. now the error is gone, but the fuction is not executed.
maybe you could take a look at my code (click event):
eventHTMLElem(‘click’, ‘wc-pao-addon-file-upload input-text wc-pao-addon-field’, true, function(event) {
console.log(“trigger”)
openFile(function() {
replaceTexture(‘vladmaterial’, ‘vlad.jpg’, _pGlob.openedFile, function() {});
});
});2019-09-09 at 7:58 am #18517Yuri KovelenovStaff2019-09-10 at 2:37 pm #18542hoodyParticipantI seem to have fixed it! Thank you very much for your kind support!
2019-09-10 at 2:58 pm #18544Yuri KovelenovStaff -
AuthorPosts
- You must be logged in to reply to this topic.