You are not logged in.

1

Friday, January 26th 2018, 4:48pm

xml-fileload plugin

As I write and load notes from tours I developed as small xml-fileload plugin (xmlfileinput.js):

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var krpanoplugin = function()
{
	var local = this;
	var krpano = null;
	var plugin = null;

	var inputelement = null;

	local.registerplugin = function(krpanointerface, pluginpath, pluginobject)
	{
		krpano = krpanointerface;
		plugin = pluginobject;

		inputelement = document.createElement("input");
		inputelement.id = "filedialog";
		inputelement.type = "file";
		inputelement.accept = "text/xml";
		inputelement.style.width = "100%";
		inputelement.style.height = "100%";
		inputelement.style.visibility = "hidden";
		inputelement.filename = "";
		inputelement.text = "";

		labelelement = document.createElement("label");
		labelelement.setAttribute("for","filedialog");
		labelelement.innerHTML = "Select xml-notesfile";
		labelelement.style.color = "black";
		labelelement.style.backgroundColor = "white";
		labelelement.style.padding = "16px";
		labelelement.style.borderRadius = "5px";
		labelelement.style.borderStyle = "outset";

		plugin.registerattribute("filename", "", filename_set, filename_get);
		plugin.registerattribute("text", "", text_set, text_get);
		plugin.registerattribute("onchanged", null); // to be defined by user

		function readText(evt) {
			var reader;
			var fileInput = evt.target;

			if(fileInput.files[0].type.match('text/xml')) {
				reader = new FileReader();
				reader.onload = function (e) {
					fileInput.filename = fileInput.value;
					fileInput.text = e.target.result;
					krpano.call(plugin.onchanged, plugin);
				};
				reader.readAsText(fileInput.files[0]);
			}
		}

		inputelement.addEventListener("change", readText, false);
		plugin.sprite.appendChild(labelelement);
		plugin.sprite.appendChild(inputelement);
	}

	local.unloadplugin = function()
	{
		plugin = null;
		krpano = null;
	}

	function filename_set(newtext)
	{
		inputelement.filename = newtext;
	}

	function filename_get()
	{
		return inputelement.filename;
	}

	function text_set(newtext)
	{
		inputelement.text = newtext;
	}

	function text_get()
	{
		return inputelement.text;
	}
};




Usage Example:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<plugin name="xmlload" devices="html5"
	url="%SWFPATH%/plugins/xmlfileinput.js"
	align="center" x="0" y="0" width="400" height="32"
	visible="false"
	keep="true"
/>

<action name="load_notes">
	set(curOnchanged, "getxmltext();");
	copy(plugin[xmlload].onchanged, curOnchanged);
	set(plugin[xmlload].visible, true);
	tween(plugin[xmlload].alpha,0,7,easeInExpo,set(plugin[xmlload].visible,false);set(plugin[xmlload].alpha,1););
</action>

<action name="getxmltext">
	copy(curNotestext, plugin[xmlload].text);
...
</action>

Be careful as it is an asynchronous process therefore only when the onchanged routine was called as event (in the example "getxmltext") the resulting text input is ready.

This post has been edited 5 times, last edit by "Tester 17" (Feb 17th 2018, 11:59pm)


jordi

Intermediate

Posts: 465

Location: Barcelona

Occupation: creating ideas & coding them

  • Send private message

2

Monday, February 19th 2018, 10:40am

Thanks for sharing nice one
everpano.com step beyond 360

Similar threads