summaryrefslogtreecommitdiff
path: root/src/frontend_blog/index.html
blob: 5815038ebf803ca7ce85bf7945665dac4533774c (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Blog site demonstration</title>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body onload="signal_taler_wallet_onload()">
  <header>
    <div id="logo">
      <svg height="100" width="100">
        <circle cx="50" cy="50" r="40" stroke="darkcyan" stroke-width="6" fill="white" />
        <text x="19" y="82" font-family="Verdana" font-size="90" fill="darkcyan">B</text>
      </svg>
    </div>

    <h1>Blog site demonstration</h1>
  </header>

  <aside class="sidebar" id="left">
  </aside>

  <section id="main">
    <article>
      <h1>Welcome to the Taler blog</h1>
      <p>This blog simulates how a website selling articles which integrates
         Taler should work. If you don't have a Taler wallet installed,
	 please visit <a href="https://demo.taler.net">demo.taler.net</a>.
         By clicking on some article below, you get its teaser shown, but the
	 actual purchase happens once you will click on the 'read more' link
	 associated with that teaser.
      </p>
    </article>
    <section>

      <article>
        <h2>Articles list</h2>
      </article>

      <article class="articles">
        <ul style="list-style-type:none">
	  <li>
	    <a href="/cc_payment.php?article=fs-essay" class="read-more" id="fs-essay">
	      <div class="teasers_item">
	        <h3>What is Free Software</h3>
	        <p>
	  The free software definition presents the criteria for whether a
          particular software program qualifies as free software.  From time to
          time we revise this definition, to clarify it or to resolve questions
          about subtle issues.
		</p>
	      </div>
	    </a>
	    </li>
	</ul>
      </article>
    </section>
  </section>
</body>
<script type="text/javascript">
/* @licstart  The following is the entire license notice for the
  JavaScript code in this page.

  Copyright (C) 2015 GNUnet e.V.

  The JavaScript code in this page is free software: you can
  redistribute it and/or modify it under the terms of the GNU
  Lesser General Public License (GNU LGPL) as published by the Free Software
  Foundation, either version 2.1 of the License, or (at your option)
  any later version.  The code is distributed WITHOUT ANY WARRANTY;
  without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU LGPL for more details.

  As additional permission under GNU LGPL version 2.1 section 7, you
  may distribute non-source (e.g., minimized or compacted) forms of
  that code without the copy of the GNU LGPL normally required by
  section 4, provided you include this license notice and a URL
  through which recipients can access the Corresponding Source.

  @licend  The above is the entire license notice
  for the JavaScript code in this page.
  */

/* This function is called from "taler_pay" after
   we downloaded the JSON contract from the merchant.
   We now need to pass it to the extension. */
function handle_contract(json_contract)
{
  var cEvent = new CustomEvent('taler-contract', { detail: json_contract });

  document.dispatchEvent(cEvent);
};

function taler_pay(article)
{
  var contract_request = new XMLHttpRequest();

  /* Note that the URL we give here is specific to the Demo-shop
     and not required by the protocol: each web shop can
     have its own way of generating and transmitting the
     contract, there just must be a way to get the contract
     and to pass it to the wallet when the user selects 'Pay'. */
  contract_request.open("GET", "essay_contract.php?article=" + article, true);
  contract_request.onload = function (e)
  {
    if (contract_request.readyState == 4)
    {
      if (contract_request.status == 200)
      {
        /* display contract_requestificate (i.e. it sends the JSON string
          to the extension) alert (contract_request.responseText); */
	console.log("contract here");
        console.log("response text:", contract_request.responseText);
        handle_contract(contract_request.responseText);
      }
      else
      {
        /* There was an error obtaining the contract from the merchant,
           obviously this should not happen. To keep it simple, we just
           alert the user to the error. */
        alert("Failure to download contract from merchant " +
              "(" + contract_request.status + "):\n" +
              contract_request.responseText);
      }
    }
  };
  contract_request.onerror = function (e)
  {
    /* There was an error obtaining the contract from the merchant,
       obviously this should not happen. To keep it simple, we just
       alert the user to the error. */
    alert("Failure requesting the contract:\n" + contract_request.statusText);
  };
  contract_request.send(null);
}

/* The following event gets fired whenever a customer has a Taler
   wallet installed in his browser. In that case, the webmaster can decide
   whether or not to display/enable Taler as a payment option in the dialog. */
function has_taler_wallet_cb(aEvent)
{
  console.log("has taler wallet");
  // make "read more" trigger Taler payment
  var articles_links = document.getElementsByClassName("read-more");
  for(var i=0; i < articles_links.length; i++)
    //console.log(link);
    articles_links[i].setAttribute("href", "/essay_offer.php?article=" + articles_links[i].id);
};

/* Function called when the Taler extension was unloaded;
   here we disable the Taler option and check "Lisa", as
   some "valid" option should always be selected. */
function taler_wallet_unload_cb(aEvent)
{
  var rm = document.getElementById("read-more");
  rm.setAttribute("href", "cc_payment.html");
};


/* The merchant signals its taler-friendlyness to the wallet,
   thereby causing the wallet to make itself more visible in the menu.
   This function should be called both when the page is loaded
   (i.e. via body's onload) and when we receive a "taler-load" signal
   (as the extension may be loaded/enabled after the page was loaded) */
function signal_taler_wallet_onload()
{
  var eve = new Event('taler-probe');
  document.dispatchEvent(eve);
};


// function included to be run to test the page despite a
// wallet not being present in the browser.  Enables the
// Taler option. NOT needed in real deployments.
function test_without_wallet(){
  var tbutton = document.getElementById("taler-radio-button-id");
  tbutton.removeAttribute("disabled");
};


// /////////////// Main logic run first ////////////////////////

// Register event to be triggered by the wallet as a response to our
// first event
document.addEventListener("taler-wallet-present",
                          has_taler_wallet_cb,
			  false);

// Register event to be triggered by the wallet when it gets enabled while
// the user is on the payment page
document.addEventListener("taler-load",
                          signal_taler_wallet_onload,
			  false);

// Register event to be triggered by the wallet when it is unloaded
document.addEventListener("taler-unload",
                          taler_wallet_unload_cb,
	                  false);
</script>
</html>