Im trying to add this: https://developers.facebook.com/docs/messenger-platform/discovery/customer-chat-plugin
All okey , everything works but it shows error in console.
How to fix it?
Didn't find any information in google.
/* Facebook messenger plugin */
window.fbAsyncInit = function () {
FB.init({
appId: '**',
autoLogAppEvents: false,
xfbml: true,
version: 'v4.0'
});
};
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
code used.
(function(){
// ...do something...
})();
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id; js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Related
On mobile, my modals cover the whole screen. They look exactly like whole new web pages. This leads to users getting confused. They expect to be able to press the back button and have the modal close. Instead the back button takes them back what they perceive as two steps.
I'm a novice at coding, so Javascript is all I've used for this, and even saying that feels like overselling my ability. I'm hoping you guys can help me figure this out.
Here's the code I used:
// Modals
// Modal Contact
function OpenModalContact () {
document.getElementById("Modal-Contact").style.display = "block";
}
// Modal-1 to 20
{
var modal1 = document.getElementById('Modal-01');
var modal2 = document.getElementById('Modal-02');
var modal3 = document.getElementById('Modal-03');
var modal4 = document.getElementById('Modal-04');
var modal5 = document.getElementById('Modal-05');
var modal6 = document.getElementById('Modal-06');
var modal7 = document.getElementById('Modal-07');
var modal8 = document.getElementById('Modal-08');
var modal9 = document.getElementById('Modal-09');
var modal10 = document.getElementById('Modal-10');
var modal11 = document.getElementById('Modal-11');
var modal12 = document.getElementById('Modal-12');
var modal13 = document.getElementById('Modal-13');
var modal14 = document.getElementById('Modal-14');
var modal15 = document.getElementById('Modal-15');
var modal16 = document.getElementById('Modal-16');
var modal17 = document.getElementById('Modal-17');
var modal18 = document.getElementById('Modal-18');
var modal19 = document.getElementById('Modal-19');
var modal20 = document.getElementById('Modal-20');
var modalContact = document.getElementById('Modal-Contact');
// Get the button that opens the modal
var Modalbtn01 = document.getElementById("ModalBtn01");
var Modalbtn02 = document.getElementById("ModalBtn02");
var Modalbtn03 = document.getElementById("ModalBtn03");
var Modalbtn04 = document.getElementById("ModalBtn04");
var Modalbtn05 = document.getElementById("ModalBtn05");
var Modalbtn06 = document.getElementById("ModalBtn06");
var Modalbtn07 = document.getElementById("ModalBtn07");
var Modalbtn08 = document.getElementById("ModalBtn08");
var Modalbtn09 = document.getElementById("ModalBtn09");
var Modalbtn10 = document.getElementById("ModalBtn10");
var Modalbtn11 = document.getElementById("ModalBtn11");
var Modalbtn12 = document.getElementById("ModalBtn12");
var Modalbtn13 = document.getElementById("ModalBtn13");
var Modalbtn14 = document.getElementById("ModalBtn14");
var Modalbtn15 = document.getElementById("ModalBtn15");
var Modalbtn16 = document.getElementById("ModalBtn16");
var Modalbtn17 = document.getElementById("ModalBtn17");
var Modalbtn18 = document.getElementById("ModalBtn18");
var Modalbtn19 = document.getElementById("ModalBtn19");
var Modalbtn20 = document.getElementById("ModalBtn20");
// Get the <span> element that closes the modal
var span1 = document.getElementById("CloseModal-01");
var span2 = document.getElementById("CloseModal-02");
var span3 = document.getElementById("CloseModal-03");
var span4 = document.getElementById("CloseModal-04");
var span5 = document.getElementById("CloseModal-05");
var span6 = document.getElementById("CloseModal-06");
var span7 = document.getElementById("CloseModal-07");
var span8 = document.getElementById("CloseModal-08");
var span9 = document.getElementById("CloseModal-09");
var span10 = document.getElementById("CloseModal-10");
var span11 = document.getElementById("CloseModal-11");
var span12 = document.getElementById("CloseModal-12");
var span13 = document.getElementById("CloseModal-13");
var span14 = document.getElementById("CloseModal-14");
var span15 = document.getElementById("CloseModal-15");
var span16 = document.getElementById("CloseModal-16");
var span17 = document.getElementById("CloseModal-17");
var span18 = document.getElementById("CloseModal-18");
var span19 = document.getElementById("CloseModal-19");
var span20 = document.getElementById("CloseModal-20");
var spanContact = document.getElementById("CloseModalContact");
// When the user clicks on the button, open the modal
ModalBtn01.onclick = function() {
modal1.style.display = "block";
}
ModalBtn02.onclick = function() {
modal2.style.display = "block";
}
ModalBtn03.onclick = function() {
modal3.style.display = "block";
}
ModalBtn04.onclick = function() {
modal4.style.display = "block";
}
ModalBtn05.onclick = function() {
modal5.style.display = "block";
}
ModalBtn06.onclick = function() {
modal6.style.display = "block";
}
ModalBtn07.onclick = function() {
modal7.style.display = "block";
}
ModalBtn08.onclick = function() {
modal8.style.display = "block";
}
ModalBtn09.onclick = function() {
modal9.style.display = "block";
}
ModalBtn10.onclick = function() {
modal10.style.display = "block";
}
ModalBtn11.onclick = function() {
modal11.style.display = "block";
}
ModalBtn12.onclick = function() {
modal12.style.display = "block";
}
ModalBtn13.onclick = function() {
modal13.style.display = "block";
}
ModalBtn14.onclick = function() {
modal14.style.display = "block";
}
ModalBtn15.onclick = function() {
modal15.style.display = "block";
}
ModalBtn16.onclick = function() {
modal16.style.display = "block";
}
ModalBtn17.onclick = function() {
modal17.style.display = "block";
}
ModalBtn18.onclick = function() {
modal18.style.display = "block";
}
ModalBtn19.onclick = function() {
modal19.style.display = "block";
}
ModalBtn20.onclick = function() {
modal20.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
spanContact.onclick = function() {
modalContact.style.display = "none";
}
span1.onclick = function() {
modal1.style.display = "none";
}
span2.onclick = function() {
modal2.style.display = "none";
}
span3.onclick = function() {
modal3.style.display = "none";
}
span4.onclick = function() {
modal4.style.display = "none";
}
span5.onclick = function() {
modal5.style.display = "none";
}
span6.onclick = function() {
modal6.style.display = "none";
}
span7.onclick = function() {
modal7.style.display = "none";
}
span8.onclick = function() {
modal8.style.display = "none";
}
span9.onclick = function() {
modal9.style.display = "none";
}
span10.onclick = function() {
modal10.style.display = "none";
}
span11.onclick = function() {
modal11.style.display = "none";
}
span12.onclick = function() {
modal12.style.display = "none";
}
span13.onclick = function() {
modal13.style.display = "none";
}
span14.onclick = function() {
modal14.style.display = "none";
}
span15.onclick = function() {
modal15.style.display = "none";
}
span16.onclick = function() {
modal16.style.display = "none";
}
span17.onclick = function() {
modal17.style.display = "none";
}
span18.onclick = function() {
modal18.style.display = "none";
}
span19.onclick = function() {
modal19.style.display = "none";
}
span20.onclick = function() {
modal20.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modalContact) {
modalContact.style.display = "none";
}
if (event.target == modal1) {
modal1.style.display = "none";
}
if (event.target == modal2) {
modal2.style.display = "none";
}
if (event.target == modal3) {
modal3.style.display = "none";
}
if (event.target == modal4) {
modal4.style.display = "none";
}
if (event.target == modal5) {
modal5.style.display = "none";
}
if (event.target == modal6) {
modal6.style.display = "none";
}
if (event.target == modal7) {
modal7.style.display = "none";
}
if (event.target == modal8) {
modal8.style.display = "none";
}
if (event.target == modal9) {
modal9.style.display = "none";
}
if (event.target == modal10) {
modal10.style.display = "none";
}
if (event.target == modal11) {
modal11.style.display = "none";
}
if (event.target == modal12) {
modal12.style.display = "none";
}
if (event.target == modal13) {
modal13.style.display = "none";
}
if (event.target == modal14) {
modal14.style.display = "none";
}
if (event.target == modal15) {
modal15.style.display = "none";
}
if (event.target == modal16) {
modal16.style.display = "none";
}
if (event.target == modal17) {
modal17.style.display = "none";
}
if (event.target == modal18) {
modal18.style.display = "none";
}
if (event.target == modal19) {
modal19.style.display = "none";
}
if (event.target == modal20) {
modal20.style.display = "none";
}
}
}
// Close modal on ESC key press
document.addEventListener("keydown", function(event) {
if (event.keyCode === 27 &&
(document.querySelector("#Modal-Contact").style.display === "block" ||
document.querySelector("#Modal-01").style.display === "block" ||
document.querySelector("#Modal-02").style.display === "block" ||
document.querySelector("#Modal-03").style.display === "block" ||
document.querySelector("#Modal-04").style.display === "block" ||
document.querySelector("#Modal-05").style.display === "block" ||
document.querySelector("#Modal-06").style.display === "block" ||
document.querySelector("#Modal-07").style.display === "block" ||
document.querySelector("#Modal-08").style.display === "block" ||
document.querySelector("#Modal-09").style.display === "block" ||
document.querySelector("#Modal-10").style.display === "block" ||
document.querySelector("#Modal-11").style.display === "block" ||
document.querySelector("#Modal-12").style.display === "block" ||
document.querySelector("#Modal-13").style.display === "block" ||
document.querySelector("#Modal-14").style.display === "block" ||
document.querySelector("#Modal-15").style.display === "block" ||
document.querySelector("#Modal-16").style.display === "block" ||
document.querySelector("#Modal-17").style.display === "block" ||
document.querySelector("#Modal-18").style.display === "block" ||
document.querySelector("#Modal-19").style.display === "block" ||
document.querySelector("#Modal-20").style.display === "block" ))
{
document.querySelector("#Modal-Contact").style.display = "none";
document.querySelector("#Modal-01").style.display = "none";
document.querySelector("#Modal-02").style.display = "none";
document.querySelector("#Modal-03").style.display = "none";
document.querySelector("#Modal-04").style.display = "none";
document.querySelector("#Modal-05").style.display = "none";
document.querySelector("#Modal-06").style.display = "none";
document.querySelector("#Modal-07").style.display = "none";
document.querySelector("#Modal-08").style.display = "none";
document.querySelector("#Modal-09").style.display = "none";
document.querySelector("#Modal-10").style.display = "none";
document.querySelector("#Modal-11").style.display = "none";
document.querySelector("#Modal-12").style.display = "none";
document.querySelector("#Modal-13").style.display = "none";
document.querySelector("#Modal-14").style.display = "none";
document.querySelector("#Modal-15").style.display = "none";
document.querySelector("#Modal-16").style.display = "none";
document.querySelector("#Modal-17").style.display = "none";
document.querySelector("#Modal-18").style.display = "none";
document.querySelector("#Modal-19").style.display = "none";
document.querySelector("#Modal-20").style.display = "none";
}
});
// Close modal on back button for mobile
document.addEventListener("backbutton", function(event) {
if
(document.querySelector("#Modal-Contact").style.display === "block" ||
document.querySelector("#Modal-01").style.display === "block" ||
document.querySelector("#Modal-02").style.display === "block" ||
document.querySelector("#Modal-03").style.display === "block" ||
document.querySelector("#Modal-04").style.display === "block" ||
document.querySelector("#Modal-05").style.display === "block" ||
document.querySelector("#Modal-06").style.display === "block" ||
document.querySelector("#Modal-07").style.display === "block" ||
document.querySelector("#Modal-08").style.display === "block" ||
document.querySelector("#Modal-09").style.display === "block" ||
document.querySelector("#Modal-10").style.display === "block" ||
document.querySelector("#Modal-11").style.display === "block" ||
document.querySelector("#Modal-12").style.display === "block" ||
document.querySelector("#Modal-13").style.display === "block" ||
document.querySelector("#Modal-14").style.display === "block" ||
document.querySelector("#Modal-15").style.display === "block" ||
document.querySelector("#Modal-16").style.display === "block" ||
document.querySelector("#Modal-17").style.display === "block" ||
document.querySelector("#Modal-18").style.display === "block" ||
document.querySelector("#Modal-19").style.display === "block" ||
document.querySelector("#Modal-20").style.display === "block" )
{
document.querySelector("#Modal-Contact").style.display = "none";
document.querySelector("#Modal-01").style.display = "none";
document.querySelector("#Modal-02").style.display = "none";
document.querySelector("#Modal-03").style.display = "none";
document.querySelector("#Modal-04").style.display = "none";
document.querySelector("#Modal-05").style.display = "none";
document.querySelector("#Modal-06").style.display = "none";
document.querySelector("#Modal-07").style.display = "none";
document.querySelector("#Modal-08").style.display = "none";
document.querySelector("#Modal-09").style.display = "none";
document.querySelector("#Modal-10").style.display = "none";
document.querySelector("#Modal-11").style.display = "none";
document.querySelector("#Modal-12").style.display = "none";
document.querySelector("#Modal-13").style.display = "none";
document.querySelector("#Modal-14").style.display = "none";
document.querySelector("#Modal-15").style.display = "none";
document.querySelector("#Modal-16").style.display = "none";
document.querySelector("#Modal-17").style.display = "none";
document.querySelector("#Modal-18").style.display = "none";
document.querySelector("#Modal-19").style.display = "none";
document.querySelector("#Modal-20").style.display = "none";
event.preventDefault();
}
});
I've incorporated this, event.preventDefault(); but it doesn't seem to work
I hoped it would prevent the back button from doing it's default behaviour.
I've seen a post on here about something like this:
https://stackoverflow.com/a/49954532/18237477
But I'm unable to incorporate that solution into my code. Their code probably works but I don't understand it. I don't know how to merge that code into mine.
I have this view:
struct PageView: View {
var articulos : [DetallesArticulo]
var altura : CGFloat
var body: some View {
if(articulos.count > 0)
{
TabView {
ForEach(0...articulos.count-1, id: \.self) {i in
let vistaTotal = ArticulosViewMinimum()
VStack{
//Code
}.id(UUID())
}
.padding(.all, 10)
}
.frame(width: UIScreen.main.bounds.width, height: altura)
.tabViewStyle(PageTabViewStyle())
}
}
}
ArticulosViewMinimum is a view like this:
class ArticulosViewMinimum: UIView{
required init(){
super.init(frame: CGRect.zero)
self.backgroundColor = .white
setupViews()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupViews(){
self.addSubview(sampleText)
}
lazy var sampleText : UITextView = {
let text = UITextView()
text.attributedText = "sample text".htmlToAttributedString(size: 16, titulo: "")
return text
}()
}
It crashes with the following error message:
[error] precondition failure: setting value during update: 51768 dyld4
config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
AttributeGraph precondition failure: setting value during update:
51768.
And it crashes in my function (extension of string) to convert HTML string to NSAttributedString:
func htmlToAttributedString(size: CGFloat) -> NSAttributedString? {
var attributedString = NSAttributedString()
if(!self.isEmpty)
{
var htmlTemplate = """
<!doctype html>
<html>
<head>
<style>
body {
font-family: -apple-system;
font-size: \(size)px;
}
</style>
</head>
<body>
\(self)
</body>
</html>
"""
guard let data = htmlTemplate.data(using: .utf8) else { return NSAttributedString()}
do {
attributedString = try NSAttributedString(
data: data,
options: [
.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue
],
documentAttributes: nil)
} catch {}
}
return attributedString
}
Any idea of what's producing the crash?
Finally, I solved by having another thread to execute the init code. I don't really understand why it works, but it works.
I read that this problem is a swift bug, I hope that in the next update they solve it.
class ArticulosViewMinimum: UIView{
required init(){
super.init(frame: CGRect.zero)
self.backgroundColor = .white
DispatchQueue.main.async //<- Now works
{
setupViews()
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupViews(){
self.addSubview(sampleText)
}
lazy var sampleText : UITextView = {
let text = UITextView()
text.attributedText = "sample text".htmlToAttributedString(size: 16, titulo: "")
return text
}()
}
I want to update my Shared preference so that each time I update my Provider the updated List automatically gets stored in my shared preference. Here is my code.
class AlarmState extends ChangeNotifier {
var hour = 0;
var min = 0;
Set<Weekday> activeDays = Set();
bool alarmRing = false;
bool vibrate = false;
bool snooze = false;
List<AlarmObject> alarmList = [];
void update({
int? hour,
int? min,
Set<Weekday>? activeDays,
bool? alarmRing,
bool? vibrate,
bool? snooze,
List<AlarmObject>? alarmList,
}) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
this.hour = hour ?? this.hour;
this.min = min ?? this.min;
this.activeDays = activeDays ?? this.activeDays;
this.alarmRing = alarmRing ?? this.alarmRing;
this.vibrate = vibrate ?? this.vibrate;
this.snooze = snooze ?? this.snooze;
this.alarmList = alarmList ?? this.alarmList;
if (alarmList == null) {
return;
}
else{
preferences.setStringList("alarm_list",
alarmList.map((e) => jsonEncode(AlarmObject.toMap(e))).toList());
}
notifyListeners();
}
}
I'm playing around a tad with Combine and SwiftUI for a little pet project of mine, learning as I go.
Here's the LoginModel at it current state:
public class LoginModel: ObservableObject {
#Published var domain: String = ""
#Published var email: String = ""
#Published var password: String = ""
#Published var isValid: Bool = false
public var didChange = PassthroughSubject<Void, Never>()
var credentialsValidPublisher: AnyPublisher<Bool, Never> {
Publishers.CombineLatest($email, $password)
.receive(on: RunLoop.main)
.map { (email, password) in
let emailValid = String.emailValid(emailString: email) // String extension function
let passwordValid = password.count > 5
return emailValid && passwordValid
}
.breakpointOnError()
.eraseToAnyPublisher()
}
init() {
// This works just fine
_ = credentialsValidPublisher.sink { isValid in
self.isValid = isValid
}
// However this does not work at all
_ = domain
.publisher
.receive(on: RunLoop.main)
.sink { value in
print(value)
}
}
}
Now from my current understanding is that a #Published var foo: String already has a Publisher attached to it. And that one should be able to use this directly to subscribe to its changes.
Changing credentialsValidPublisher variable over to this works too:
var credentialsValidPublisher: AnyPublisher<Bool, Never> {
Publishers.CombineLatest3($domain, $email, $password)
.receive(on: RunLoop.main)
.map { (domain, email, password) in
let domainValid = URL.isValidURL(urlString: domain)
let emailValid = String.emailValid(emailString: email)
let passwordValid = password.count > 5
return domainValid && emailValid && passwordValid
}
.breakpointOnError()
.eraseToAnyPublisher()
}
But this is not what I want. In my case I need a special Publisher in order to map a valid URL string over to a network request and then ping the server at hand to see if the provided server is responding.
Also this model is then connected to a SwiftUI view with a bunch of SwiftUI TextFields.
Any help to point me in the right direction will be highly appreciated.
So I figure out the way to do it.
In the LoginModel underneath var credentialsValidPublisher: AnyPublisher<Bool, Never> I added:
var domainValidPublisher: AnyPublisher<Bool, Never> {
$domain
.debounce(for: 0.5, scheduler: DispatchQueue.main)
.removeDuplicates()
.map { domain in
URL.isValidURL(urlString: domain)
}
.eraseToAnyPublisher()
}
Then I can just subscribe to it in init.
I also added AnyCancellable properties that we call .cancel() on deinit.
Here's what the updated model looks like:
public class LoginModel: ObservableObject {
#Published var domain: String = ""
#Published var email: String = ""
#Published var password: String = ""
#Published var isValid: Bool = false
public var didChange = PassthroughSubject<Void, Never>()
private var credentialsValidPublisherCancellable: AnyCancellable!
private var domainValidCancellable: AnyCancellable!
var credentialsValidPublisher: AnyPublisher<Bool, Never> {
Publishers.CombineLatest3($domain, $email, $password)
.receive(on: RunLoop.main)
.map { (domain, email, password) in
let domainValid = URL.isValidURL(urlString: domain)
let emailValid = String.emailValid(emailString: email)
let passwordValid = password.count > 5
return domainValid && emailValid && passwordValid
}
.breakpointOnError()
.eraseToAnyPublisher()
}
var domainValidPublisher: AnyPublisher<Bool, Never> {
$domain
.debounce(for: 0.5, scheduler: DispatchQueue.main)
.removeDuplicates()
.map { domain in
URL.isValidURL(urlString: domain)
}
.eraseToAnyPublisher()
}
init() {
credentialsValidPublisherCancellable = credentialsValidPublisher.sink { isValid in
self.isValid = isValid
}
domainValidCancellable = domainValidPublisher.sink { isValid in
print("isValid: \(isValid)")
}
}
deinit {
credentialsValidPublisherCancellable.cancel()
domainValidCancellable.cancel()
}
}
Karma test case run through Istanbul.
$scope.processChkBoxes = function(listOptions){
var urlAltered = false;
$scope.myData.data = '{}';
url = URLHolder;
$scope.myData.loadDataFlg = true;
$scope.myData.noDataFlg = false;
if(listOptions[0] == true){
Iif(urlAltered == true){
url = url + "&showSubCust=true";
}else{
url = url + "?showSubCust=true";
urlAltered = true;
}
}
if(listOptions[1] == true){
Eif(urlAltered == true){
url = url + "&showSettled=true";
}else{
url = url + "?showSettled=true";
urlAltered = true;
}
}
if(listOptions[2] == true){
Eif(urlAltered == true){
url = url + "&showPendingVeh=true";
}else{
url = url + "?showPendingVeh=true";
urlAltered = true;
}
}
Iif(listOptions[3] == true){
if(urlAltered == true){
url = url + "&showActiveVeh=true";
}else{
url = url + "?showActiveVeh=true";
urlAltered = true;
}
}
VehicleListService.getVehicleList(url).then(function(data){
$scope.myData.data = data;
Iif($scope.myData.data ==undefined){
$scope.myData.noDataFlg = true;
}
$scope.myData.loadDataFlg = false;
});
};
$scope.search = function() {
$scope.gridApi.grid.refresh();
but its not showing full coverage.
Can any one help on this by writing a test case