Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable for browsers that support line-clamp #4

Open
warudin opened this issue Mar 18, 2019 · 2 comments
Open

Option to disable for browsers that support line-clamp #4

warudin opened this issue Mar 18, 2019 · 2 comments

Comments

@warudin
Copy link

warudin commented Mar 18, 2019

From all much-used browsers, currently only Firefox doesn't support line-clamp. Would it be possible to add an option to disable clampify when the browser supports line-clamp?

@artem328
Copy link
Owner

Hello, I don't have time to maintanance this plugin, I wrote it for own needs, and upload to github, in case it could be helpful to someone else. You can make a PR with this feature. I think it shouldn't be hard.

@warudin
Copy link
Author

warudin commented Mar 18, 2019

I'm not really familiar with your code so I don't know how to implement it, but something like the code below worked for me.

Lines 2-4 with the CSS.supports-check is what's important. Support for line-clamp is being checked through the CSS API and if there's support the function is cancelled.

function clampifyText() {
	if (CSS.supports("(line-clamp: 1)") || CSS.supports("(-webkit-line-clamp: 1)")) {
		return;
	}

	jQuery('.clamp').each(function() {
		var clamp = 2;

		if (jQuery(this).data('clamp') !== 'undefined') {
			clamp = jQuery(this).data('clamp');
		}

		jQuery(this).clampify({
			maxLines: clamp,
			autoUpdate: true,
		});
	});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants