samedi 1 août 2020

How can I select elements in shadow dom through the parent element based on the click event on addEventListener?

I have a web component, like this:

File: download-bar.js (web component)

class DownloadBar extends HTMLElement {

    constructor() {
        super();
        this.shadowDOM = this.attachShadow({mode: 'open'});        
    }

    connectedCallback() {
        this.render();
    }

    render() {
        this.shadowDOM.innerHTML = `
            <div class="favicon">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="black" width="18px" height="18px"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"></path><path d="M0 0h24v24H0z" fill="none"></path></svg>
                <span>Download File</span>
            </div>
            <div class="dropdown">
                <a href="" id="xlsx">XLSX</a>
                <a href="" id="pdf">PDF</a>
                <a href="" id="jpeg">JPEG</a>
            </div>
        `;
    }
}

customElements.define('download-bar', DownloadBar);

and I do a selection of elements on the parent shadow element DOM and listen to the click event, like this:

File: download-bar.js

import '../component/download-bar.js';

const downloadElement = document.querySelector('download-bar');

downloadElement.addEventListener('click', (e) => {

    // I would like this:
    if (e.target.classList.contains('favicon')) {
        console.log('True')
    }
})

how can I get child elements from custom elements using shadow dom, if an event from "(e)" that is obtained has a certain class or id, for example class = "favicon"?




Error While trying to Deploy Flutter Web App on cPanel: "We're sorry, but something went wrong.."

I have followed the steps in this article to deploy flutter app as node.js app. My app directory in the server is: home/username/app/app, and here is what I entered to create node.js app:

enter image description here

and when I visit the web app url that's what I get:

enter image description here

How to solve it?




How to stream RTSP on the web?

We generate RTSP stream (MP4 with ACC codec for audio) on our server and we need to send it to web app and play it.

We could send it via websocket and play it with media extensions but they are not supported on iOS.

We could also use WebRTC with media channel but that supports only Opus audio codec and we cannot afford transcoding from ACC to Opus.

Do you have any idea how can we play RTSP data on iOS devices?

EDIT: we aim for low latency playback (<1s) HSL has latency 5s+




What are the technologies required to build an Online exam website?

I want to build an online exam website, where people's can attempt their tests and teachers can easily create the tests(MCQs and Subjective questions).

What is the procedure and technologies to use for creating website like this?

Please help!




why can't I do portforwarding?

I'm trying to do portforwarding for one of my projects. I think I did everything correctly , but just when I enter IP to watch it , I see my router setup page. And I can't see my web pages and port 80 is closed for me from my country , I can use port 21 and 445. can you help me please?




PageStorageKey not loading between navigation

I've looked at just about every piece of info I can find on this subject but none of the solutions seem to be working for me. I have a persistent top nav bar that I pass the views through using a the MaterialApp builder function as shown below. Inside that NavFrame class I simply have two buttons to switch between views. The second view has a GridView with a PageStorageKey attached to it. If you scroll and switch between views you'll see the scroll position is not loaded when going back to the grid in view 2. I'm using the latest Auto-Route package for generating my routes.

main.dart

void main() {
  runApp(MyApp());
}

final _navKey = GlobalKey<NavigatorState>();

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'PageStorageKey Debugging',
      theme: ThemeData(
        primarySwatch: Colors.green,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      initialRoute: Routes.view1,
      navigatorKey: _navKey,
      onGenerateRoute: Router().onGenerateRoute,
      builder: (context, child) => NavFrame(_navKey, child),
    );
  }
}

nav_frame.dart

class NavFrame extends StatelessWidget {
  final Widget child;
  final GlobalKey<NavigatorState> _navKey;
  const NavFrame(this._navKey, this.child, {Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Positioned(
            top: 0,
            left: 0,
            right: 0,
            child: Container(
              color: Colors.black,
              height: 100,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  RaisedButton(
                    onPressed: () {
                      _navKey.currentState.pushReplacementNamed(Routes.view1);
                    },
                    child: Text('View 1'),
                  ),
                  SizedBox(
                    width: 50,
                  ),
                  RaisedButton(
                    onPressed: () {
                      _navKey.currentState.pushReplacementNamed(Routes.view2);
                    },
                    child: Text('View 2'),
                  ),
                ],
              ),
            )),
        Positioned(
          top: 100,
          left: 0,
          right: 0,
          bottom: 0,
          child: Container(
            child: child,
          ),
        ),
      ],
    );
  }
}

view1.dart

class View1 extends StatelessWidget {
  const View1({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(
            child: Container(
          color: Colors.blue,
        ))
      ],
    );
  }
}

view2.dart

class View2 extends StatefulWidget {
  const View2({Key key}) : super(key: key);

  @override
  _View2State createState() => _View2State();
}

class _View2State extends State<View2>
    with AutomaticKeepAliveClientMixin<View2> {
  final bucket = PageStorageBucket();

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Column(
      children: [
        Expanded(
          child: GridView.builder(
            key: new PageStorageKey('test-key'),
            addAutomaticKeepAlives: true,
            padding: EdgeInsets.all(30),
            shrinkWrap: true,
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 1,
              childAspectRatio: 2,
              crossAxisSpacing: 30,
              mainAxisSpacing: 30,
            ),
            itemCount: 10,
            itemBuilder: (BuildContext context, int index) {
              return Container(
                  decoration: BoxDecoration(
                    border: Border.all(width: 1.5, color: Colors.black),
                    borderRadius: BorderRadius.all(Radius.circular(10.0)),
                  ),
                  child: Center(
                    child: Material(
                      child: Text(
                        index.toString(),
                        style: TextStyle(fontSize: 20),
                      ),
                    ),
                  ));
            },
          ),
        )
      ],
    );
  }

  @override
  bool get wantKeepAlive => true;
}

router.dart

@MaterialAutoRouter(
  generateNavigationHelperExtension: true,
  routes: <AutoRoute>[
    MaterialRoute(page: View1, initial: true),
    MaterialRoute(page: View2, path: "/view2"),
  ],
)
class $Router {}

pubspec.yaml

name: PageStorageKeyTest
description: Debugging PageStorageKey.

publish_to: "none"

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # Navigation
  auto_route: 0.6.6

  # Cupertino
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter

  build_runner: 1.10.1
  auto_route_generator:

flutter:
  uses-material-design: true

As mentioned I've tried many different suggested solutions I've been able to find. Currently in View2 you'll see I'm using the AutomaticKeepAliveCluentMixin with wantKeepAlive set to true. I did also make sure to call the super.build(context) as I saw suggested in one question on here. I also have tried using the PageStoreBucket in just about every place I can imagine and it doesn't seem to be doing anything. (Currently not being used in the above code). I've tried to set maintainState to true in the MaterialRoute. In my actual project where I'm running into this I'm using Stacked architecture and even tried passing the keys through the viewModel and having the viewModel builder only build once and nothing seems to be doing the trick. Running the above code should produce the exact issue I'm having. I'm also on the latest dev build I believe (1.21.0-1.0.pre). Any suggestions?




Dynamic List How to shorten the IF condition?

in future i have many if condition, any idea to shorten the if condition for (Render Badge items)?

today i just only have 4 item if in the future i have 20 or maybe 100 item, is it i need to code the if for 20 or 100 times?

i have tried many method, but i really don't know how to make it, hope someone can help me as well. Thank you very much

Render Dynamic List

const medals = productItem.goldmedal || productItem.newitem || productItem.freedelivery;
        if (medals) {
            const iconBadge = $("<ul>", { class: 'icons' });
            function createMedal(src, text) {
                const badge =
                    $("<li>", { class: 'icon' })
                        .append($('<a>', { class: 'tpsTooltip skeleton_hide', href: '###', 'data-tippy-content': text })
                            .append($('<img>', { src: src, alt: text })))
                        .append($('<div>', { class: 'pl-placeholder_skeleton pl-placeholder_liIcon' }));
                iconBadge.append(badge);
            }
            createFeatureIcon.append(iconBadge);

            //Render Badge items (Below is the if condition code)
            if (productItem.goldmedal) {
                createMedal(plSettings.goldMetalSrc, plSettings.goldMetalText)
            }
            if (productItem.newitem) {
                createMedal(plSettings.newItemSrc, plSettings.newItemText)
            }
            if (productItem.newshop) {
                createMedal(plSettings.newShopSrc, plSettings.newShopText)
            }
            if (productItem.freedelivery) {
                createMedal(plSettings.freeDeliverySrc, plSettings.freeDeliveryText)
            }
        }


Settings

//Settings
var plSettings = $.extend({
    mainClass: 'item-wrapper',
    itemWrapperClass: 'item ripple-effect ripple-joya itemShadowLight',

    goldMetalSrc: '/img/tps/gold.png',
    goldMetalText: 'Gold Medal sellers stand out from millions of sellers, bringing more trust and peace of mind to your shopping experience',

    newItemSrc: '/img/tps/new.png',
    newItemText: 'New item',

    sellermedalSrc: '/img/tps/seller.png',
    sellermedalText: 'Top Seller',
       
    newShopSrc: '/img/tps/newshop.png',
    newShopText: 'New Shop In Joyacart',

    freeDeliverySrc: '/img/tps/freedelivery.png',
    freeDeliveryText: 'Free Delivery'
});

example data is below:

var data = {
    productList: [
        {
            id: "62276197-6059-4c21-9b40-c5b1d277e85d",
            link: "javascript:void(0)",
            imgurl: "/img/upload/png/joyacart_000001_12032019.png",
            text: 'Product 001',
            goldmedal: false,
            newitem: true,
            newshop: true,
            freedelivery: true
        },
        {
            id: "59de8216-052d-4e51-9f7d-7e96642ded62",
            link: "javascript:void(0)",
            imgurl: "/img/upload/png/joyacart_000002_12032019.png",
            text: 'Product 002',
            goldmedal: true,
            newitem: false,
            newshop: true,
            freedelivery: true
        }]
}