olton / Metro-UI-CSS

Impressive component library for expressive web development! Build responsive projects on the web with the first front-end component library in Metro Style. And now there are even more opportunities every day!
http://metroui.org.ua/
MIT License
7.03k stars 1.96k forks source link

Version 4.3.x will be without jQuery! #1293

Closed olton closed 5 years ago

olton commented 5 years ago

Version 4.3.x will be without jQuery! At the moment I am doing a lightweight jQuery replacement. You can get acquainted with it at https://github.com/olton/m4q

olton commented 5 years ago
olton commented 5 years ago

I was asked me if will would be possible to use jQuery with Metro4 after switching over to using M4Q abstraction. Yes of course. The abstraction layer M4Q will be encapsulated inside Metro 4 and will not occupy the global $ variable!

In your code that uses jquery to access the API of Metro 4, You will not need to change anything.!

olton commented 5 years ago

If you want to use jQuery to access the API in Metro 4 (4.3.x), you need to add a meta tag <meta name="metro4:jquery" content="true"> in the page header and connect jquery. After that, you can access the API components and initialize them using jQuery:

Initialising

<div id="a1" data-one-frame="true">
...
</div>

$("#a1").accordion();

API

<div data-role="accordion" id="a1" data-one-frame="true">
...
</div>

var accordion = $("#a1").data("accordion");
olton commented 5 years ago

Hi, my friends! I'm finished a Metro 4 without jQuery (v 4.3.0). Beta 1 now available from GitHub and Metro 4 CDN

olton commented 5 years ago

Currently working Repo

https://github.com/olton/Metro4-M4Q

Javascript

https://cdn.metroui.org.ua/v4.3.0/js/metro.js

CSS

https://cdn.metroui.org.ua/v4.3.0/css/metro-all.css
shajeeck commented 5 years ago

How to get control events working with metro ui M4Q (4.3) without jQuery? By the way i am using angular2+ with M4Q, will it make a difference?

Thanx for this awesome library!

olton commented 5 years ago

@shajeeck Maybe I misunderstood the question, m4q contains methods for working with events https://github.com/olton/m4q#events $( ... ).on(event_name, callback);

$("a").on("click", function(e){
     ... your code here ...
});

or $( ... ).on(event_name, delegates, callback)

// for li > a
$("li").on("click", "a", function(e){
     ... your code here ...
});

Documentation for M4Q currently in progress.

shajeeck commented 5 years ago

thanx for your reply!

How can i subscribe to custom events of components like onUp(list, select), onItemDeselect(option) for 'select' component using m4q?

Or run a method of select component like disable(), enabled(), toggleState() etc using m4q?

using data-on-item-deselect as attribute doesn't seem to work in angular2+

olton commented 5 years ago

@shajeeck You can create service function and set it a name for required attribute name. No need interact with m4q.

<select data-role="select" data-on-item-select="itemSelect">...</select>
function itemSelect(val, option, item){
    ...
}
olton commented 5 years ago

@shajeeck Direct subscribe to special events of components currently not present. But, maybe I'll add them soon. I think about it.

shajeeck commented 5 years ago

@olton I tried this <select data-role="select" data-on-item-select="itemSelect">...</select> but it doesn't work in angular2+. The function doesn't seem to run, may be because how angular2+ works.

olton commented 5 years ago

@shajeeck to access to component API (without jquery) you must use the same method as with a jquery ;) :

<select id="sel1" data-role="select" data-on-item-select="itemSelect">...</select>
var select = $("#sel1").data("select");
select.disable();
shajeeck commented 5 years ago

@olton methods does seem to work using var select = $("#sel1").data("select"); select.disable(); in angular2+. Any work around to subscribe special events ??

olton commented 5 years ago

@shajeeck contact to https://github.com/morrisjdev/ng-metro4 author. Maybe Morris can help you.