(view)
| 285 | |
| 286 | // dynamic event or object binding here |
| 287 | export function finishView (view) { |
| 288 | // todo list |
| 289 | const lis = view.find('li.raw').removeClass('raw').sortByDepth().toArray() |
| 290 | |
| 291 | for (let li of lis) { |
| 292 | let html = $(li).clone()[0].innerHTML |
| 293 | const p = $(li).children('p') |
| 294 | if (p.length === 1) { |
| 295 | html = p.html() |
| 296 | li = p[0] |
| 297 | } |
| 298 | html = replaceExtraTags(html) |
| 299 | li.innerHTML = html |
| 300 | let disabled = 'disabled' |
| 301 | if (typeof editor !== 'undefined' && window.havePermission()) { disabled = '' } |
| 302 | if (/^\s*\[[x ]]\s*/.test(html)) { |
| 303 | li.innerHTML = html.replace(/^\s*\[ ]\s*/, `<input type="checkbox" class="task-list-item-checkbox "${disabled}><label></label>`) |
| 304 | .replace(/^\s*\[x]\s*/, `<input type="checkbox" class="task-list-item-checkbox" checked ${disabled}><label></label>`) |
| 305 | if (li.tagName.toLowerCase() !== 'li') { |
| 306 | li.parentElement.setAttribute('class', 'task-list-item') |
| 307 | } else { |
| 308 | li.setAttribute('class', 'task-list-item') |
| 309 | } |
| 310 | } |
| 311 | if (typeof editor !== 'undefined' && window.havePermission()) { $(li).find('input').change(toggleTodoEvent) } |
| 312 | // color tag in list will convert it to tag icon with color |
| 313 | const tagColor = $(li).closest('ul').find('.color') |
| 314 | tagColor.each((key, value) => { |
| 315 | $(value).addClass('fa fa-tag').css('color', $(value).attr('data-color')) |
| 316 | }) |
| 317 | } |
| 318 | |
| 319 | // youtube |
| 320 | view.find('div.youtube.raw').removeClass('raw') |
| 321 | .click(function () { |
| 322 | imgPlayiframe(this, '//www.youtube.com/embed/') |
| 323 | }) |
| 324 | // vimeo |
| 325 | view.find('div.vimeo.raw').removeClass('raw') |
| 326 | .click(function () { |
| 327 | imgPlayiframe(this, '//player.vimeo.com/video/') |
| 328 | }) |
| 329 | .each((key, value) => { |
| 330 | const videoId = $(value).attr('data-videoid') |
| 331 | let urlForJsonp = '' |
| 332 | try { |
| 333 | const url = new URL(`https://vimeo.com/api/v2/video/${videoId}.json`) |
| 334 | if (!url.pathname.startsWith('/api/v2/video/')) { |
| 335 | throw new Error(`Invalid vimeo video id: ${videoId}`) |
| 336 | } |
| 337 | urlForJsonp = `//${url.origin}${url.pathname}` |
| 338 | } catch (err) { |
| 339 | console.error(err) |
| 340 | return |
| 341 | } |
| 342 | jsonp(urlForJsonp, function (data) { |
| 343 | const thumbnailSrc = data[0].thumbnail_large |
| 344 | const image = `<img src="${thumbnailSrc}" />` |
no test coverage detected