Repository navigation
Expand file tree
/
Copy pathwallpaper.js
More file actions
81 lines (70 loc) · 2.53 KB
/
Copy pathwallpaper.js
File metadata and controls
81 lines (70 loc) · 2.53 KB
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
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
var Wallpaper = {
getAllElements: function wallpaper_getAllElements() {
this.preview = document.getElementById('wallpaper-preview');
this.button = document.getElementById('wallpaper-button');
},
init: function wallpaper_init() {
this.wallpaperURL = new SettingsURL();
this.getAllElements();
this.loadCurrentWallpaper();
this.bindEvent();
},
loadCurrentWallpaper: function wallpaper_loadCurrentWallpaper() {
var self = this;
var settings = navigator.mozSettings;
settings.addObserver('wallpaper.image',
function onHomescreenChange(event) {
self.preview.src = self.wallpaperURL.set(event.settingValue);
});
var lock = settings.createLock();
var reqWallpaper = lock.get('wallpaper.image');
reqWallpaper. wallpaper_getWallpaperSuccess() {
self.preview.src = self.wallpaperURL.set(this.result['wallpaper.image']);
};
},
bindEvent: function wallpaper_bindEvent() {
var self = this;
var settings = navigator.mozSettings;
var wallpaper_onWallpaperClick() {
ForwardLock.getKey(function(secret) {
var a = new MozActivity({
name: 'pick',
data: {
type: ['wallpaper', 'image/*'],
includeLocked: (secret !== null),
// XXX: This will not work with Desktop Fx / Simulator.
width: window.screen.width * window.devicePixelRatio,
height: window.screen.height * window.devicePixelRatio
}
});
a. onPickSuccess() {
var blob = a.result.blob;
if (!blob)
return;
if (blob.type.split('/')[1] === ForwardLock.mimeSubtype) {
// If this is a locked image from the locked content app, unlock it
ForwardLock.unlockBlob(secret, blob, function(unlocked) {
setWallpaper(unlocked);
});
} else {
setWallpaper(blob);
}
function setWallpaper(blob) {
navigator.mozSettings.createLock().set({
'wallpaper.image': blob
});
}
};
a. onPickError() {
console.warn('pick failed!');
};
});
};
this.preview.addEventListener('click', onWallpaperClick);
this.button.addEventListener('click', onWallpaperClick);
}
};
Wallpaper.init();