Repository: 2gis/mapsapi
Branch: master
Commit: f7ce5f1182c6
Files: 487
Total size: 3.5 MB
Directory structure:
gitextract_whh8pbvz/
├── .csscomb.json
├── .editorconfig
├── .eslintrc
├── .github/
│ └── workflows/
│ └── test.yml
├── .gitignore
├── .npmignore
├── CONTRIBUTING.md
├── LICENSE
├── LICENSE_EN
├── README.md
├── app/
│ ├── config.js
│ ├── index.html
│ ├── index.js
│ └── loader.js
├── assets/
│ ├── cluster_realworld.js
│ └── heat_realworld.js
├── config.main.json
├── functional-tests/
│ ├── .gitignore
│ ├── README.md
│ ├── classes/
│ │ ├── WAPI/
│ │ │ ├── __init__.py
│ │ │ ├── dataWorker.py
│ │ │ └── request.py
│ │ ├── __init__.py
│ │ ├── components/
│ │ │ ├── __init__.py
│ │ │ ├── balloon.py
│ │ │ ├── callout.py
│ │ │ ├── component.py
│ │ │ ├── map.py
│ │ │ ├── mapsapi_sources.py
│ │ │ ├── marker.py
│ │ │ ├── page.py
│ │ │ └── zoom_control.py
│ │ ├── exceptions/
│ │ │ ├── __init__.py
│ │ │ └── exceptions.py
│ │ ├── mapsapi_base_test.py
│ │ └── util/
│ │ ├── __init__.py
│ │ ├── decorators.py
│ │ ├── geo_types_map.py
│ │ ├── link_generator.py
│ │ ├── misc.py
│ │ ├── scripts.py
│ │ ├── transport_types_map.py
│ │ └── unescape.py
│ ├── config/
│ │ ├── __init__.py
│ │ ├── config.ini
│ │ └── config.my.ini
│ ├── pep8
│ ├── pep8-hook.sh
│ ├── prepare.sh
│ ├── run.sh
│ ├── template_render.sh
│ ├── templates/
│ │ ├── __init__.py
│ │ ├── base.html
│ │ └── content.py
│ └── tests/
│ ├── __init__.py
│ ├── balloon_test.py
│ ├── bounds_test.py
│ ├── event_test.py
│ ├── firm_callout_test.py
│ ├── geo_clicker_test.py
│ ├── loader_test.py
│ ├── marker_test.py
│ ├── ruler_test.py
│ └── zoom_test.py
├── gulp/
│ ├── deps/
│ │ ├── build.html
│ │ ├── deps.js
│ │ ├── index.js
│ │ └── packs.js
│ ├── sprite-template.mustache
│ ├── tasks/
│ │ ├── build.js
│ │ ├── buildLeaflet.js
│ │ ├── buildScripts.js
│ │ ├── buildStyles.js
│ │ ├── buildTest.js
│ │ ├── clean.js
│ │ ├── collectImagesStats.js
│ │ ├── collectImagesUsageStats.js
│ │ ├── concatScripts.js
│ │ ├── copyAssets.js
│ │ ├── copyImg.js
│ │ ├── copyIndexPage.js
│ │ ├── dev.js
│ │ ├── doc.js
│ │ ├── generateSprites.js
│ │ ├── imageMinify.js
│ │ ├── lint.js
│ │ ├── lintCSS.js
│ │ ├── lintJS.js
│ │ ├── loadProjectList.js
│ │ ├── loader.js
│ │ ├── rebuildStyles.js
│ │ ├── server.js
│ │ ├── test.js
│ │ └── watch.js
│ └── util/
│ ├── buildCSS.js
│ ├── buildEnd.js
│ ├── csslint/
│ │ ├── gulp-csslint.js
│ │ └── lib/
│ │ ├── csslint.js
│ │ └── parserlib.js
│ ├── destCSS.js
│ ├── error.js
│ ├── gendoc.js
│ ├── projectList.js
│ ├── stat.js
│ └── templateStream.js
├── gulpfile.js
├── package.json
├── src/
│ ├── DGAjax/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── src/
│ │ │ └── DGAjax.js
│ │ └── test/
│ │ └── DGAjaxSpec.js
│ ├── DGAttribution/
│ │ ├── lang/
│ │ │ ├── ar.js
│ │ │ ├── cs.js
│ │ │ ├── en.js
│ │ │ ├── es.js
│ │ │ ├── it.js
│ │ │ └── ru.js
│ │ ├── skin/
│ │ │ └── basic/
│ │ │ └── less/
│ │ │ └── dg-mapcopyright.less
│ │ ├── src/
│ │ │ └── DGAttribution.js
│ │ ├── templates/
│ │ │ └── copyright.dust
│ │ └── test/
│ │ └── DGAttributionSpec.js
│ ├── DGCore/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── skin/
│ │ │ └── basic/
│ │ │ └── less/
│ │ │ └── dg-core.less
│ │ └── src/
│ │ ├── DGCore.js
│ │ ├── DGplugin.js
│ │ └── DGthen.js
│ ├── DGCustomization/
│ │ ├── skin/
│ │ │ └── basic/
│ │ │ ├── less/
│ │ │ │ ├── dg-customization.less
│ │ │ │ ├── leaflet.ie.less
│ │ │ │ └── leaflet.less
│ │ │ └── skin.config.js
│ │ ├── src/
│ │ │ ├── DGCustomization.js
│ │ │ ├── DGMap.ApiKeyValidator.js
│ │ │ ├── DGMap.BaseLayer.js
│ │ │ ├── DGMap.Drag.js
│ │ │ ├── DGMap.TilesCheck.js
│ │ │ ├── DGMap.js
│ │ │ ├── DGMobileImprove.js
│ │ │ └── DGPolyUtil.js
│ │ └── test/
│ │ ├── CanvasSpec.js
│ │ ├── DGCustomizationSpec.js
│ │ ├── DGMap.BaseLayerSpec.js
│ │ ├── DGMapSpec.js
│ │ ├── GridLayerSpec.js
│ │ ├── Map.DragSpec.js
│ │ ├── MapSpec.js
│ │ ├── PathSpec.js
│ │ ├── PopupSpec.js
│ │ ├── UtilSpec.js
│ │ └── ValidatorApiKeySpec.js
│ ├── DGDust/
│ │ ├── doc/
│ │ │ └── DGDust.md
│ │ ├── src/
│ │ │ └── DGDust.js
│ │ └── test/
│ │ └── DGDustSpec.js
│ ├── DGEntrance/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── src/
│ │ │ ├── DGAnimation.js
│ │ │ ├── DGArrowPathTransform.js
│ │ │ ├── DGArrowTipTransform.js
│ │ │ ├── DGBezierCurves.js
│ │ │ ├── DGComplexPath.js
│ │ │ ├── DGEntrance.js
│ │ │ ├── DGEntranceArrow.js
│ │ │ ├── DGEntranceArrowShape.js
│ │ │ ├── DGMetric.js
│ │ │ ├── DGRenderer.js
│ │ │ └── DGVertexTransform.js
│ │ └── test/
│ │ ├── DGArrowShapeSpec.js
│ │ ├── DGBezierSpec.js
│ │ ├── DGMetricSpec.js
│ │ ├── DGTransformSpec.js
│ │ └── EntranceSpec.js
│ ├── DGFullScreen/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── lang/
│ │ │ ├── ar.js
│ │ │ ├── cs.js
│ │ │ ├── en.js
│ │ │ ├── es.js
│ │ │ ├── it.js
│ │ │ └── ru.js
│ │ ├── skin/
│ │ │ ├── basic/
│ │ │ │ └── less/
│ │ │ │ ├── dg-control-round.less
│ │ │ │ └── dg-fullscreen.ie.less
│ │ │ ├── dark/
│ │ │ │ └── less/
│ │ │ │ └── dg-control-round.less
│ │ │ └── light/
│ │ │ └── less/
│ │ │ └── dg-control-round.less
│ │ ├── src/
│ │ │ ├── DGFullScreen.js
│ │ │ ├── DGScreenfull.js
│ │ │ └── LegacyFullScreen.js
│ │ └── test/
│ │ └── DGFullScreenSpec.js
│ ├── DGGeoclicker/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── lang/
│ │ │ ├── cs.js
│ │ │ ├── en.js
│ │ │ ├── es.js
│ │ │ ├── it.js
│ │ │ └── ru.js
│ │ ├── skin/
│ │ │ ├── basic/
│ │ │ │ └── less/
│ │ │ │ ├── dg-building-callout.less
│ │ │ │ ├── dg-firm-card.less
│ │ │ │ ├── dg-link.less
│ │ │ │ ├── dg-map-geoclicker.less
│ │ │ │ ├── dg-popup.ie.less
│ │ │ │ ├── dg-popup.less
│ │ │ │ ├── dg-preloader.less
│ │ │ │ ├── dg-schedule.ie.less
│ │ │ │ └── dg-schedule.less
│ │ │ ├── dark/
│ │ │ │ └── less/
│ │ │ │ ├── dg-building-callout.less
│ │ │ │ ├── dg-firm-card.less
│ │ │ │ ├── dg-map-geoclicker.less
│ │ │ │ ├── dg-popup.ie.less
│ │ │ │ ├── dg-popup.less
│ │ │ │ ├── dg-schedule.ie.less
│ │ │ │ └── dg-schedule.less
│ │ │ └── light/
│ │ │ └── less/
│ │ │ ├── dg-building-callout.less
│ │ │ ├── dg-firm-card.less
│ │ │ ├── dg-map-geoclicker.less
│ │ │ ├── dg-popup.less
│ │ │ ├── dg-schedule.ie.less
│ │ │ └── dg-schedule.less
│ │ ├── src/
│ │ │ ├── ClampHelper.js
│ │ │ ├── Controller.js
│ │ │ ├── DGGeoclicker.js
│ │ │ ├── View.js
│ │ │ ├── handler/
│ │ │ │ ├── ApiError.js
│ │ │ │ ├── CityArea.js
│ │ │ │ ├── Default.js
│ │ │ │ ├── Handler.js
│ │ │ │ ├── House.View.js
│ │ │ │ ├── House.js
│ │ │ │ ├── POI.js
│ │ │ │ └── Sight.js
│ │ │ └── provider/
│ │ │ ├── CatalogApi.js
│ │ │ └── Provider.js
│ │ ├── templates/
│ │ │ ├── cityarea.dust
│ │ │ ├── firmCardAddr.dust
│ │ │ ├── firmCardContacts.dust
│ │ │ ├── firmCardHeader.dust
│ │ │ ├── firmCardRubric.dust
│ │ │ ├── firmCardSchedule.dust
│ │ │ ├── firmlistItem.dust
│ │ │ ├── frimCardPayments.dust
│ │ │ ├── house.dust
│ │ │ ├── loader.dust
│ │ │ ├── popupFooter.dust
│ │ │ ├── popupFooterBtns.dust
│ │ │ ├── popupHeader.dust
│ │ │ └── sight.dust
│ │ └── test/
│ │ ├── CatalogApiSpec.js
│ │ ├── ControllerSpec.js
│ │ └── GeoclickerSpec.js
│ ├── DGLabel/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── skin/
│ │ │ ├── basic/
│ │ │ │ └── less/
│ │ │ │ └── dg-label.less
│ │ │ ├── dark/
│ │ │ │ └── less/
│ │ │ │ └── dg-label.less
│ │ │ └── light/
│ │ │ └── less/
│ │ │ └── dg-label.less
│ │ ├── src/
│ │ │ ├── DGLabel.Layer.js
│ │ │ ├── DGLabel.js
│ │ │ ├── Entrance.DGLabel.js
│ │ │ ├── Marker.DGLabel.js
│ │ │ └── Path.DGLabel.js
│ │ └── test/
│ │ └── DGLabelSpec.js
│ ├── DGLocale/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── src/
│ │ │ ├── DGDictionary.js
│ │ │ └── DGLocale.js
│ │ └── test/
│ │ └── DGLocaleSpec.js
│ ├── DGLocation/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── lang/
│ │ │ ├── ar.js
│ │ │ ├── cs.js
│ │ │ ├── en.js
│ │ │ ├── es.js
│ │ │ ├── it.js
│ │ │ └── ru.js
│ │ ├── skin/
│ │ │ ├── basic/
│ │ │ │ └── less/
│ │ │ │ ├── dg-control-round.less
│ │ │ │ └── dg-location.less
│ │ │ ├── dark/
│ │ │ │ └── less/
│ │ │ │ └── dg-control-round.less
│ │ │ └── light/
│ │ │ └── less/
│ │ │ └── dg-control-round.less
│ │ ├── src/
│ │ │ └── DGLocation.js
│ │ └── test/
│ │ └── DGLocationSpec.js
│ ├── DGMeta/
│ │ ├── src/
│ │ │ ├── DGMeta.Layer.js
│ │ │ └── DGMeta.Origin.js
│ │ └── test/
│ │ ├── DGMetaSpec.js
│ │ └── PolyUtilContainsSpec.js
│ ├── DGMuseum/
│ │ ├── skin/
│ │ │ └── basic/
│ │ │ └── less/
│ │ │ └── dg-museum.less
│ │ └── src/
│ │ └── DGMuseum.js
│ ├── DGPoi/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── src/
│ │ │ └── DGPoi.js
│ │ └── test/
│ │ └── DGPoiSpec.js
│ ├── DGPopup/
│ │ ├── skin/
│ │ │ ├── basic/
│ │ │ │ ├── less/
│ │ │ │ │ ├── dg-popup.less
│ │ │ │ │ ├── leaflet.ie.less
│ │ │ │ │ ├── leaflet.less
│ │ │ │ │ └── scroller.less
│ │ │ │ └── skin.config.js
│ │ │ ├── dark/
│ │ │ │ └── less/
│ │ │ │ ├── dg-popup.less
│ │ │ │ ├── leaflet.ie.less
│ │ │ │ ├── leaflet.less
│ │ │ │ └── scroller.less
│ │ │ └── light/
│ │ │ └── less/
│ │ │ ├── dg-popup.less
│ │ │ ├── leaflet.ie.less
│ │ │ ├── leaflet.less
│ │ │ └── scroller.less
│ │ ├── src/
│ │ │ └── DGPopup.js
│ │ └── test/
│ │ └── DGPopupSpec.js
│ ├── DGProjectDetector/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── src/
│ │ │ └── DGProjectDetector.js
│ │ └── test/
│ │ ├── ProjectDetectorInSpec.js
│ │ ├── ProjectDetectorInitSpec.js
│ │ ├── ProjectDetectorOutOfWorldSpec.js
│ │ └── ProjectDetectorUnderSpec.js
│ ├── DGRoundControl/
│ │ ├── skin/
│ │ │ ├── basic/
│ │ │ │ └── less/
│ │ │ │ └── dg-control-round.less
│ │ │ ├── dark/
│ │ │ │ └── less/
│ │ │ │ └── dg-control-round.less
│ │ │ └── light/
│ │ │ └── less/
│ │ │ └── dg-control-round.less
│ │ ├── src/
│ │ │ └── DGRoundControl.js
│ │ └── test/
│ │ └── DGRoundControlSpec.js
│ ├── DGRuler/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── lang/
│ │ │ ├── ar.js
│ │ │ ├── cs.js
│ │ │ ├── en.js
│ │ │ ├── es.js
│ │ │ ├── it.js
│ │ │ └── ru.js
│ │ ├── skin/
│ │ │ └── basic/
│ │ │ └── less/
│ │ │ ├── dg-ruler.ie.less
│ │ │ └── dg-ruler.less
│ │ ├── src/
│ │ │ ├── GeometryStyles.js
│ │ │ ├── LayeredMarker.js
│ │ │ └── Ruler.js
│ │ └── test/
│ │ └── RulerSpec.js
│ ├── DGRulerControl/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── lang/
│ │ │ ├── ar.js
│ │ │ ├── cs.js
│ │ │ ├── en.js
│ │ │ ├── es.js
│ │ │ ├── it.js
│ │ │ └── ru.js
│ │ ├── skin/
│ │ │ └── basic/
│ │ │ └── less/
│ │ │ └── dg-control-round.less
│ │ ├── src/
│ │ │ └── Control.Ruler.js
│ │ └── test/
│ │ └── DGRulerControlSpec.js
│ ├── DGTraffic/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── lang/
│ │ │ ├── ar.js
│ │ │ ├── cs.js
│ │ │ ├── en.js
│ │ │ ├── es.js
│ │ │ ├── it.js
│ │ │ └── ru.js
│ │ ├── src/
│ │ │ └── DGTraffic.js
│ │ └── test/
│ │ └── DGTrafficSpec.js
│ ├── DGTrafficControl/
│ │ ├── demo/
│ │ │ └── index.html
│ │ ├── lang/
│ │ │ ├── ar.js
│ │ │ ├── cs.js
│ │ │ ├── en.js
│ │ │ ├── es.js
│ │ │ ├── it.js
│ │ │ └── ru.js
│ │ ├── skin/
│ │ │ └── basic/
│ │ │ └── less/
│ │ │ ├── dg-control-round.less
│ │ │ ├── dg-traffic-control.ie.less
│ │ │ └── dg-traffic-control.less
│ │ ├── src/
│ │ │ └── Control.Traffic.js
│ │ └── test/
│ │ └── TrafficControlSpec.js
│ ├── DGWkt/
│ │ ├── DGWkt.js
│ │ ├── demo/
│ │ │ └── index.html
│ │ └── test/
│ │ ├── DGWktSpec.js
│ │ ├── DGWktToGeoJSONSpec.js
│ │ └── DGWktToLatLngsSpec.js
│ ├── DGZoomControl/
│ │ ├── lang/
│ │ │ ├── ar.js
│ │ │ ├── cs.js
│ │ │ ├── en.js
│ │ │ ├── es.js
│ │ │ ├── it.js
│ │ │ └── ru.js
│ │ ├── skin/
│ │ │ ├── basic/
│ │ │ │ └── less/
│ │ │ │ └── dg-zoom-control.less
│ │ │ ├── dark/
│ │ │ │ └── less/
│ │ │ │ └── dg-zoom-control.less
│ │ │ └── light/
│ │ │ └── less/
│ │ │ └── dg-zoom-control.less
│ │ ├── src/
│ │ │ └── DGZoomControl.js
│ │ └── test/
│ │ └── DGZoomControlSpec.js
│ ├── copyright.js
│ ├── doc/
│ │ ├── en/
│ │ │ ├── examples/
│ │ │ │ ├── base.md
│ │ │ │ ├── bounds.md
│ │ │ │ ├── controls.md
│ │ │ │ ├── events.md
│ │ │ │ ├── external-modules.md
│ │ │ │ ├── geojson.md
│ │ │ │ ├── markers.md
│ │ │ │ ├── popups.md
│ │ │ │ ├── vector-layers.md
│ │ │ │ └── wkt.md
│ │ │ ├── manual/
│ │ │ │ ├── base-classes.md
│ │ │ │ ├── basic-types.md
│ │ │ │ ├── controls.md
│ │ │ │ ├── dg-ajax.md
│ │ │ │ ├── dg-entrance.md
│ │ │ │ ├── dg-external-modules.md
│ │ │ │ ├── dg-label.md
│ │ │ │ ├── dg-loading.md
│ │ │ │ ├── dg-locale.md
│ │ │ │ ├── dg-metalayers.md
│ │ │ │ ├── dg-project-detector.md
│ │ │ │ ├── dg-ruler.md
│ │ │ │ ├── dg-traffic.md
│ │ │ │ ├── dg-wkt.md
│ │ │ │ ├── dom-utils.md
│ │ │ │ ├── map.md
│ │ │ │ ├── markers.md
│ │ │ │ ├── other-layers.md
│ │ │ │ ├── popup.md
│ │ │ │ ├── raster-layers.md
│ │ │ │ ├── utils.md
│ │ │ │ └── vector-layers.md
│ │ │ └── quickstart/
│ │ │ └── quickstart.md
│ │ └── ru/
│ │ ├── examples/
│ │ │ ├── base.md
│ │ │ ├── bounds.md
│ │ │ ├── controls.md
│ │ │ ├── events.md
│ │ │ ├── external-modules.md
│ │ │ ├── geojson.md
│ │ │ ├── markers.md
│ │ │ ├── popups.md
│ │ │ ├── vector-layers.md
│ │ │ └── wkt.md
│ │ ├── manual/
│ │ │ ├── base-classes.md
│ │ │ ├── basic-types.md
│ │ │ ├── controls.md
│ │ │ ├── dg-ajax.md
│ │ │ ├── dg-entrance.md
│ │ │ ├── dg-external-modules.md
│ │ │ ├── dg-label.md
│ │ │ ├── dg-loading.md
│ │ │ ├── dg-locale.md
│ │ │ ├── dg-metalayers.md
│ │ │ ├── dg-migration.md
│ │ │ ├── dg-project-detector.md
│ │ │ ├── dg-ruler.md
│ │ │ ├── dg-traffic.md
│ │ │ ├── dg-wkt.md
│ │ │ ├── dom-utils.md
│ │ │ ├── map.md
│ │ │ ├── markers.md
│ │ │ ├── other-layers.md
│ │ │ ├── popup.md
│ │ │ ├── raster-layers.md
│ │ │ ├── utils.md
│ │ │ └── vector-layers.md
│ │ └── quickstart/
│ │ └── quickstart.md
│ ├── less/
│ │ ├── images-usage-statistics.less
│ │ ├── mixins.ie8.less
│ │ ├── mixins.images-usage-statistics.less
│ │ └── mixins.less
│ └── menu.json
├── test/
│ ├── after.js
│ ├── excludedTests.js
│ ├── karma.conf.js
│ └── test.js
└── vendors/
├── baron/
│ ├── Gruntfile.js
│ ├── baron.css
│ ├── baron.js
│ ├── changelog.md
│ ├── demo/
│ │ ├── baron.full.js
│ │ ├── index.html
│ │ ├── script.js
│ │ └── style.css
│ ├── js/
│ │ ├── bean.js
│ │ ├── bonzo.js
│ │ ├── jquery-1.9.0.js
│ │ └── qwery.js
│ ├── package.json
│ ├── readme.md
│ ├── src/
│ │ ├── controls.js
│ │ ├── core.js
│ │ ├── fix.js
│ │ ├── pull.js
│ │ └── test.js
│ ├── tasks/
│ │ └── mocha-phantomjs.js
│ └── test/
│ ├── core.auto.html
│ ├── index.html
│ ├── script.js
│ ├── style.css
│ └── tests.js
├── firmcard/
│ ├── doc/
│ │ └── Schedule.md
│ ├── src/
│ │ ├── Dictionary.js
│ │ ├── FirmCard.DataHelper.js
│ │ ├── FirmCard.js
│ │ ├── FirmList.js
│ │ ├── Schedule.js
│ │ └── vendors/
│ │ ├── momentjs/
│ │ │ └── lang/
│ │ │ ├── moment.cs.js
│ │ │ ├── moment.it.js
│ │ │ └── moment.ru.js
│ │ └── underscore1.5.1.js
│ └── test/
│ ├── FirmCardSpec.html
│ ├── FirmCardSpec.js
│ ├── FirmListSpec.html
│ ├── FirmListSpec.js
│ ├── demoData.js
│ ├── expect.js
│ ├── mocha.css
│ ├── mocha.js
│ └── sinon.js
└── polyfills/
├── es5.js
└── promise.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .csscomb.json
================================================
{
"always-semicolon": true,
"block-indent": false,
"color-case": "lower",
"color-shorthand": true,
"element-case": false,
"eof-newline": false,
"leading-zero": false,
"quotes": "single",
"space-after-colon": false,
"space-after-combinator": " ",
"space-after-opening-brace": false,
"space-after-selector-delimiter": false,
"space-before-closing-brace": false,
"space-before-colon": "",
"space-before-combinator": " ",
"space-before-opening-brace": false,
"space-before-selector-delimiter": "",
"space-between-declarations": false,
"strip-spaces": true,
"unitless-zero": true,
"vendor-prefix-align": false,
"sort-order": [[
"position",
"top",
"right",
"bottom",
"left",
"z-index",
"display",
"visibility",
"-webkit-flex-direction",
"-moz-flex-direction",
"-ms-flex-direction",
"-o-flex-direction",
"flex-direction",
"-webkit-flex-order",
"-moz-flex-order",
"-ms-flex-order",
"-o-flex-order",
"flex-order",
"-webkit-flex-pack",
"-moz-flex-pack",
"-ms-flex-pack",
"-o-flex-pack",
"flex-pack",
"float",
"clear",
"-webkit-flex-align",
"-moz-flex-align",
"-ms-flex-align",
"-o-flex-align",
"flex-align",
"overflow",
"-ms-overflow-x",
"-ms-overflow-y",
"overflow-x",
"overflow-y",
"-webkit-overflow-scrolling",
"clip",
"-webkit-box-sizing",
"-moz-box-sizing",
"box-sizing",
"margin",
"margin-top",
"margin-right",
"margin-bottom",
"margin-left",
"padding",
"padding-top",
"padding-right",
"padding-bottom",
"padding-left",
"min-width",
"min-height",
"max-width",
"max-height",
"width",
"height",
"outline",
"outline-width",
"outline-style",
"outline-color",
"outline-offset",
"border",
"border-spacing",
"border-collapse",
"border-width",
"border-style",
"border-color",
"border-top",
"border-top-width",
"border-top-style",
"border-top-color",
"border-right",
"border-right-width",
"border-right-style",
"border-right-color",
"border-bottom",
"border-bottom-width",
"border-bottom-style",
"border-bottom-color",
"border-left",
"border-left-width",
"border-left-style",
"border-left-color",
"-webkit-border-radius",
"-moz-border-radius",
"border-radius",
"-webkit-border-top-left-radius",
"-moz-border-radius-topleft",
"border-top-left-radius",
"-webkit-border-top-right-radius",
"-moz-border-radius-topright",
"border-top-right-radius",
"-webkit-border-bottom-right-radius",
"-moz-border-radius-bottomright",
"border-bottom-right-radius",
"-webkit-border-bottom-left-radius",
"-moz-border-radius-bottomleft",
"border-bottom-left-radius",
"-webkit-border-image",
"-moz-border-image",
"-o-border-image",
"border-image",
"-webkit-border-image-source",
"-moz-border-image-source",
"-o-border-image-source",
"border-image-source",
"-webkit-border-image-slice",
"-moz-border-image-slice",
"-o-border-image-slice",
"border-image-slice",
"-webkit-border-image-width",
"-moz-border-image-width",
"-o-border-image-width",
"border-image-width",
"-webkit-border-image-outset",
"-moz-border-image-outset",
"-o-border-image-outset",
"border-image-outset",
"-webkit-border-image-repeat",
"-moz-border-image-repeat",
"-o-border-image-repeat",
"border-image-repeat",
"-webkit-border-top-image",
"-moz-border-top-image",
"-o-border-top-image",
"border-top-image",
"-webkit-border-right-image",
"-moz-border-right-image",
"-o-border-right-image",
"border-right-image",
"-webkit-border-bottom-image",
"-moz-border-bottom-image",
"-o-border-bottom-image",
"border-bottom-image",
"-webkit-border-left-image",
"-moz-border-left-image",
"-o-border-left-image",
"border-left-image",
"-webkit-border-corner-image",
"-moz-border-corner-image",
"-o-border-corner-image",
"border-corner-image",
"-webkit-border-top-left-image",
"-moz-border-top-left-image",
"-o-border-top-left-image",
"border-top-left-image",
"-webkit-border-top-right-image",
"-moz-border-top-right-image",
"-o-border-top-right-image",
"border-top-right-image",
"-webkit-border-bottom-right-image",
"-moz-border-bottom-right-image",
"-o-border-bottom-right-image",
"border-bottom-right-image",
"-webkit-border-bottom-left-image",
"-moz-border-bottom-left-image",
"-o-border-bottom-left-image",
"border-bottom-left-image",
"background",
"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader",
"background-color",
"background-image",
"background-attachment",
"background-position",
"-ms-background-position-x",
"-ms-background-position-y",
"background-position-x",
"background-position-y",
"-webkit-background-clip",
"-moz-background-clip",
"background-clip",
"background-origin",
"-webkit-background-size",
"-moz-background-size",
"-o-background-size",
"background-size",
"background-repeat",
"box-decoration-break",
"-webkit-box-shadow",
"-moz-box-shadow",
"box-shadow",
"color",
"table-layout",
"caption-side",
"empty-cells",
"list-style",
"list-style-position",
"list-style-type",
"list-style-image",
"quotes",
"content",
"counter-increment",
"counter-reset",
"-ms-writing-mode",
"vertical-align",
"text-align",
"-webkit-text-align-last",
"-moz-text-align-last",
"-ms-text-align-last",
"text-align-last",
"text-decoration",
"text-emphasis",
"text-emphasis-position",
"text-emphasis-style",
"text-emphasis-color",
"text-indent",
"-ms-text-justify",
"text-justify",
"text-outline",
"text-transform",
"text-wrap",
"-ms-text-overflow",
"text-overflow",
"text-overflow-ellipsis",
"text-overflow-mode",
"text-shadow",
"white-space",
"word-spacing",
"-ms-word-wrap",
"word-wrap",
"-ms-word-break",
"word-break",
"-moz-tab-size",
"-o-tab-size",
"tab-size",
"-webkit-hyphens",
"-moz-hyphens",
"hyphens",
"letter-spacing",
"font",
"font-weight",
"font-style",
"font-variant",
"font-size-adjust",
"font-stretch",
"font-size",
"font-family",
"src",
"line-height",
"opacity",
"-ms-filter:\\'progid:DXImageTransform.Microsoft.Alpha",
"filter:progid:DXImageTransform.Microsoft.Alpha(Opacity",
"-ms-interpolation-mode",
"-webkit-filter",
"-ms-filter",
"filter",
"resize",
"cursor",
"nav-index",
"nav-up",
"nav-right",
"nav-down",
"nav-left",
"-webkit-transition",
"-moz-transition",
"-ms-transition",
"-o-transition",
"transition",
"-webkit-transition-delay",
"-moz-transition-delay",
"-ms-transition-delay",
"-o-transition-delay",
"transition-delay",
"-webkit-transition-timing-function",
"-moz-transition-timing-function",
"-ms-transition-timing-function",
"-o-transition-timing-function",
"transition-timing-function",
"-webkit-transition-duration",
"-moz-transition-duration",
"-ms-transition-duration",
"-o-transition-duration",
"transition-duration",
"-webkit-transition-property",
"-moz-transition-property",
"-ms-transition-property",
"-o-transition-property",
"transition-property",
"-webkit-transform",
"-moz-transform",
"-ms-transform",
"-o-transform",
"transform",
"-webkit-transform-origin",
"-moz-transform-origin",
"-ms-transform-origin",
"-o-transform-origin",
"transform-origin",
"-webkit-animation",
"-moz-animation",
"-ms-animation",
"-o-animation",
"animation",
"-webkit-animation-name",
"-moz-animation-name",
"-ms-animation-name",
"-o-animation-name",
"animation-name",
"-webkit-animation-duration",
"-moz-animation-duration",
"-ms-animation-duration",
"-o-animation-duration",
"animation-duration",
"-webkit-animation-play-state",
"-moz-animation-play-state",
"-ms-animation-play-state",
"-o-animation-play-state",
"animation-play-state",
"-webkit-animation-timing-function",
"-moz-animation-timing-function",
"-ms-animation-timing-function",
"-o-animation-timing-function",
"animation-timing-function",
"-webkit-animation-delay",
"-moz-animation-delay",
"-ms-animation-delay",
"-o-animation-delay",
"animation-delay",
"-webkit-animation-iteration-count",
"-moz-animation-iteration-count",
"-ms-animation-iteration-count",
"-o-animation-iteration-count",
"animation-iteration-count",
"-webkit-animation-direction",
"-moz-animation-direction",
"-ms-animation-direction",
"-o-animation-direction",
"animation-direction",
"pointer-events",
"unicode-bidi",
"direction",
"-webkit-columns",
"-moz-columns",
"columns",
"-webkit-column-span",
"-moz-column-span",
"column-span",
"-webkit-column-width",
"-moz-column-width",
"column-width",
"-webkit-column-count",
"-moz-column-count",
"column-count",
"-webkit-column-fill",
"-moz-column-fill",
"column-fill",
"-webkit-column-gap",
"-moz-column-gap",
"column-gap",
"-webkit-column-rule",
"-moz-column-rule",
"column-rule",
"-webkit-column-rule-width",
"-moz-column-rule-width",
"column-rule-width",
"-webkit-column-rule-style",
"-moz-column-rule-style",
"column-rule-style",
"-webkit-column-rule-color",
"-moz-column-rule-color",
"column-rule-color",
"break-before",
"break-inside",
"break-after",
"page-break-before",
"page-break-inside",
"page-break-after",
"orphans",
"widows",
"-ms-zoom",
"zoom",
"max-zoom",
"min-zoom",
"user-zoom",
"orientation",
"..."
]]
}
================================================
FILE: .editorconfig
================================================
# EditorConfig: https://EditorConfig.org
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.{js,ts,jsx,tsx,json,html,css,md,yml}]
charset = utf-8
[*.{js,ts,jsx,tsx,json,html,css}]
indent_style = space
indent_size = 4
[*.yml]
indent_style = space
indent_size = 2
================================================
FILE: .eslintrc
================================================
{
"extends": "eslint:recommended",
"rules": {
"eqeqeq": 0,
"camelcase": 2,
"quotes": [2, "single"],
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"space-before-function-paren": [2, "never"],
"space-in-parens": 2,
"object-curly-spacing": 2,
"array-bracket-spacing": 2,
"computed-property-spacing": 2,
"space-before-blocks": 2,
"keyword-spacing": 2,
"no-lonely-if": 2,
"comma-style": 2,
"indent": [2, 4, {"SwitchCase": 1}],
"no-underscore-dangle": 0,
"no-use-before-define": 0,
"no-constant-condition": 0,
"no-multi-spaces": 0,
"strict": 0,
"key-spacing": 0,
"no-shadow": 0,
"no-console": 1,
"no-useless-escape": 0,
"no-prototype-builtins": 0
},
"globals": {
"DG": true,
"L": true,
"baron": true,
"Promise": true
},
"env": {
"browser": true,
"node": true
}
}
================================================
FILE: .github/workflows/test.yml
================================================
name: Test
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
- name: Set env var to fix the PhantomJS error
run: |
echo "OPENSSL_CONF=/tmp/openssl.cnf" >> "$GITHUB_ENV"
- name: Setup node 🔧
uses: actions/setup-node@v2
with:
node-version: 12
- name: Downgrade the Python version to fix the install errors
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Test ✔️
env:
TEST_SECRET_KEY: ${{ secrets.TEST_SECRET_KEY }}
run: |
npm ci
npm test
================================================
FILE: .gitignore
================================================
.DS_Store
.idea
node_modules
npm-debug.log
dist
gulp/tmp
.tern-port
config.local.json
nohup.out
vendors/leaflet/dist/leaflet-src.js
coverage
jsconfig.json
.vscode
yarn.lock
================================================
FILE: .npmignore
================================================
.DS_Store
.idea
node_modules
npm-debug.log
gulp/tmp
.tern-port
config.local.json
nohup.out
vendors/leaflet/dist/leaflet-src.js
coverage
jsconfig.json
.vscode
yarn.lock
================================================
FILE: CONTRIBUTING.md
================================================
## Содержание
1. [Как принять участие в развитии API карт](#Как-принять-участие-в-развитии-api-карт)
* [Расскажите о нас](#Расскажите-о-нас)
* [Сообщайте об ошибках](#Сообщайте-об-ошибках)
* [Разрабатывайте собственные модули](#Разрабатывайте-собственные-модули)
* [Участвуйте в исправлении ошибок](#Участвуйте-в-исправлении-ошибок)
* [Участвуйте в улучшении документации](#Участвуйте-в-улучшении-документации)
2. [Как разработать собственный модуль](#Как-разработать-собственный-модуль)
* [Инициализация](#Инициализация)
* [Код модуля](#Код-модуля)
* [Минификация и подключение](#Минификация-и-подключение)
* [Прочие рекомендации](#Прочие-рекомендации)
3. [Как внести изменения в исходный код](#Как-внести-изменения-в-исходный-код)
4. [Установка локальной сборки API карт](#Установка-локальной-сборки-api-карт)
5. [Стандарты кодирования](#Стандарты-кодирования)
* [JavaScript](#javascript)
* [HTML и CSS](#html-и-css)
## Как принять участие в развитии API карт
Каждый из вас может повлиять на качество API карт и сделать продукт еще лучше. Ниже перечислено несколько способов того, как вы можете это сделать.
### Расскажите о нас
Реализовали качественный проект на API 2ГИС? Напишите об этом в своем блоге или социальной сети, поделитесь своим опытом использования API с другими разработчиками.
### Сообщайте об ошибках
Если вы нашли ошибку в работе API карт или столкнулись с проблемой, сообщите об этом на [форуме обратной связи](https://api2gis.uservoice.com) и мы обязательно поможем вам разобраться с проблемой. Как правило, хорошо локализованная ошибка — это уже половина работы по её исправлению, потому постарайтесь сделать максимально простой пример, на котором воспроизводится ошибка и разместите его в публичном доступе (например, используя [JSFiddle](http://jsfiddle.net/)), также не забудьте указать версию браузера и ОС, чтобы мы смогли воспроизвести ошибку.
### Разрабатывайте собственные модули
Вы можете расширять функциональность API карт под свои потребности при помощи модулей. Прочтите [небольшую инструкцию](#Как-разработать-собственный-модуль), которая поможет написать ваш первый модуль. Если считаете, что модуль будет полезен другим разработчикам, обязательно сообщите нам об этом по адресу api@2gis.ru, мы разместим информацию о нем на официальном сайте 2ГИС, а возможно и включим в базовую поставку API карт.
### Участвуйте в исправлении ошибок
Вы можете самостоятельно исправить найденные ошибки в работе API карт, для этого необходимо ознакомиться с [процессом внесения изменений в исходный код](#Как-внести-изменения-в-исходный-код) и прислать нам [pull request](https://help.github.com/articles/using-pull-requests).
### Участвуйте в улучшении документации
Если какой-то из разделов документации показался недостаточно полным и вы считаете, что его можно улучшить, вы можете сделать это самостоятельно. Для внесения изменений в документацию необходимо:
* найти интересующий вас раздел документации в папке [src/doc/](https://github.com/2gis/maps-api-2.0/tree/master/src/doc/manual) и открыть его содержимое;
* нажать кнопку Edit, отредактировать текст документации и нажать кнопку Propose File Change.
Мы рассмотрим ваш pull request с изменениями и при следующем релизе после их принятия они появятся на сайте API 2ГИС.
## Как разработать собственный модуль
Ниже приведен пример разработки простого модуля. С помощью этого модуля мы покажем, как расширить функционал API карт таким образом, чтобы у пользователей появилась возможность кликнуть в любой дом на карте и увидеть вокруг него магазины в радиусе 500 метров.
Перед началом разработки рекомендуется ознакомиться со [стандартами кодирования](#Стандарты-кодирования) и [документацией](http://api.2gis.ru/doc/maps/manual/loading/) API карт.
### Инициализация
Первое, что необходимо сделать — это создать отдельный [Github-репозиторий для нашего модуля](https://github.com/2gis/maps-api-2.0-plugin-demo).
И сформировать файловую структуру:
/src - исходные JS файлы
/demo - HTML файлы с примерами использования
/dist - минифицированные JS и CSS файлы, а также изображения
README.md
LICENSE.md
### Код модуля
Так как наш модуль довольно простой, он будет состоять всего из одного исходного JS файла, назовем его DGDemoPlugin.js и напишем в нем необходимый для работы код:
```javascript
DG.DemoPlugin = DG.Handler.extend({
_lastFirms: DG.layerGroup(),
addHooks: function() {
this._map.on('click', this._searchFirms, this);
},
removeHooks: function() {
this._map.off('click', this._searchFirms, this);
},
_searchFirms: function(e) { // (MouseEvent)
var latlng = e.latlng.wrap();
DG.ajax({
url: 'http://catalog.api.2gis.ru/2.0/search',
data: {
what: 'магазин',
point: latlng.lng + ',' + latlng.lat,
radius: 500,
page_size: 50,
type: 'filial',
key: '12345678'
},
success: DG.bind(this._showFirms, this),
error: DG.bind(this._logError, this)
});
},
_showFirms: function(data) { // (Object)
var firms, marker;
if (data.response.code > 200) {
this._logError(data);
return;
}
this._lastFirms.clearLayers();
firms = data.result.data;
firms.forEach(function(firmInfo) {
marker = DG.marker([firmInfo.geo.lat, firmInfo.geo.lon]);
marker.bindPopup(firmInfo.firm.name);
marker.addTo(this._lastFirms);
}, this);
this._lastFirms.addTo(this._map);
},
_logError: function(data) {
console.log('Error: ', data);
}
});
DG.Map.addInitHook('addHandler', 'demoPlugin', DG.DemoPlugin);
```
Наш модуль предполагает взаимодействие пользователя с картой, потому мы его отнаследовали от класса `DG.Handler`. Благодаря этому можно будет контролировать его поведение в процессе исполнения приложения (например, у разработчика будет возможность включить или выключить модуль).
Свойство `_lastFirms` представляет собой группу, в которую мы добавляем маркеры. В нашем случае это необходимо для того, чтоб можно было одной командой удалить с карты маркеры всех магазинов, которые были добавлены после предыдущего клика пользователя, и отобразить новые.
Методы `addHooks` и `removeHooks` срабатывает в тот момент, когда разработчик конечного приложения включает или отключает наш модуль.
Метод `_searchFirms` отправляет AJAX-запрос к [REST API справочника 2ГИС](http://catalog.api.2gis.ru/doc/2.0/catalog/filial/search-by-what-and-radius) и в случае успешного ответа вызывает метод `_showFirms`.
Метод `_showFirms` удаляет с карты все предыдущие маркеры и показывает новые.
Метод `_logError` при возникновении ошибки печатает в консоль браузера данные о ней.
Конструкция `DG.Map.addInitHook('addHandler', 'demoPlugin', DG.DemoPlugin)` позволяет карте зарегистрировать написанный нами обработчик пользовательских действий, после чего к нему можно будет обратиться по соответствующему имени, например:
map.demoPlugin.enable();
### Минификация и подключение
Для минификации JS файлов существует множество популярных инструментов, вы можете воспользоваться любым из них, напрмиер [YUI Compressor](http://yui.github.io/yuicompressor/). Минифицированный JS файл необходимо положить в папку `dist` и предоставить к нему публичный доступ, после чего любой разработчик сможет подключить и использовать его вместе с API карт. Пример подключения модуля:
DG.then(function() {
//загрузка модуля
return DG.plugin('https://raw.github.com/2gis/maps-api-2.0-plugin-demo/master/dist/DGDemoPlugin.js');
})
.then(function() {
//инициализация карты
var map = new DG.Map('map', {
'center': new DG.LatLng(54.980206086231, 82.898068362003),
'zoom': 15,
'geoclicker': false
});
// включение модуля
map.demoPlugin.enable();
});
### Прочие рекомендации
Выше мы привели пример очень простого модуля, но модули могут быть более сложные, ниже перечислены некоторые рекомендации по их разработке.
Рекомендуемая файловая структура модуля:
/src — исходные JS файлы
/doc — документация
/lang — языковые файлы
/skin — изображения и CSS файлы разных тем API карт
/templates — шаблоны
/test — тесты
/demo — HTML файлы с примерами использования
/dist — минифицированные JS и CSS файлы, а также изображения
README.md
LICENSE.md
В качестве примера модуля с описанной выше файловой структурой можно изучить [DGGeoclicker](https://github.com/2gis/maps-api-2.0/tree/master/src/DGGeoclicker).
Не забывайте снабжать модули тестами, это позволит упростить их поддержку в будущем. В качестве тестового фреймворка в API карт используется [Mocha](http://visionmedia.github.io/mocha/).
Делайте демонстрационные примеры. Как правило, это первое на что обращают внимание пользователи модуля при ознакомлении с его возможностями.
Составьте и положите в корневую папку модуля файл `README.md`, в котором будут описаны возможности модуля и примеры его использования.
Выберите лицензию для своего модуля, ведь это неотъемлемая часть любого open-source проекта. Такие ресурсы, как [tldrlegal.com](http://www.tldrlegal.com/) и [opensource.org](http://opensource.org/licenses) могут вам в этом помочь.
## Как внести изменения в исходный код
Для внесения изменений в существующий исходный код API карт (например, для исправления ошибки) вам потребуется:
* сделать [форк](https://help.github.com/articles/fork-a-repo) репозитория API карт;
* [установить API карт локально](#Установка-локальной-сборки-api-карт) на своем компьютере;
* сделать ветку, название которой будет соответствовать сути вашего изменения (ветку необходимо унаследовать от ветки `master`, так как в ней находится последняя стабильная версия API карт);
* внести свои изменения в код (рекомендуется следовать принятым [стандартам кодирования](#Стандарты-кодирования));
* прислать нам pull request.
После изучения и тестирования pull request-а мы его примем (возможно с некоторыми доработками), после чего они попадут в релиз и станут доступны всем пользователям API карт.
Пожалуйста, не забывайте покрывать и проверять измененный код тестами.
Для запуска тестов в PhantomJS (по умолчанию) необходимо из консоли выполнить команду:
gulp test
Для запуска тестов в браузерах вашей операционной системы укажите названия браузеров с помощью параметров:
gulp test --ff --chrome
Список доступных параметров:
(default) PhantomJS
--chrome Chrome
--ff Firefox
--opera Opera
--safari Safari
--ie IE (только для Windows)
Если вам необходимо выполнить тесты за несколько запусков браузера, то вы можете использовать параметр:
--multiple-chunks
По умолчанию при каждом запуске браузера будут выполняться тесты из 10ти модулей.
Изменить это число можно параметром:
--items-in-chunk
Также вы можете проверить код на наличие синтаксических ошибок, для этого необходимо выполнить команду:
gulp lint
## Установка локальной сборки API карт
Ниже перечислены шаги, которые необходимо выполнить для установки API карт локально на своем компьютере.
* Склонируйте репозиторий:
git clone git@github.com:2gis/mapsapi.git
Примечание: если вы устанавливаете API карт не с текущего репозитория, а с его форка, тогда не забудьте указать первым параметром команды `clone` адрес форка вместо адреса репозитория 2ГИС.
* Установите [Node.js](https://nodejs.org/)
* Установите зависимости:
cd ~/mapsapi-folder
npm install
* В файле `config.main.json` замените параметр `baseUrl` на пустую строку: `"baseUrl": ""`.
* Выполните сборку API карт и запуск сервера:
npm run dev
После выполнения описанных выше действий вы сможете открыть в браузере карту по адресу http://127.0.0.1:3000/2.0/
## Стандарты кодирования
### JavaScript
Основные требования к JavaScript коду обеспечиваются синтаксическим анализатором и описаны в конфигурационом файле [ESLint](https://github.com/2gis/maps-api-2.0/blob/master/.eslintrc). В процессе разработки мы стараемся придерживаться соглашений, схожими с [Airbnb style guide](https://github.com/airbnb/javascript), за исключением соглашений о [пробелах](https://github.com/airbnb/javascript#whitespace) и [комментариях](https://github.com/airbnb/javascript#comments).
### HTML и CSS
#### Определения
Данные соглашения — набор правил разной степени обязательности исполнения. Используется три степени:
* обязательно — нарушение правила не имеет смысла либо полностью запрещено. Нарушение должно обсуждаться заранее с командой;
* должно — нарушение правила возможно при достаточном обосновании. Нарушение можно обсудить постфактум или оставить комментарий в коде;
* рекомендуется — при прочих равных лучше использовать рекомендованный вариант.
Соглашения являются расширением методологии [БЭМ](http://ru.bem.info/method/definitions/), поэтому используются следующие термины:
* блок — синоним понятий «плагин», «модуль» — неразрывная независимая часть ветки DOM-дерева (или ветка целиком), и связанных с ней CSS-правил, которая может быть переиспользована на любом проекте, в любом контексте. Блоком так же называется корневой тег такой структуры;
* элемент — структурная единица блока. Элемент всегда принадлежит одной копии блока. Элемент не имеет смысла вне блока. Элемент не может принадлежать одновременно нескольким блокам, или нескольким копиям одного блока. При движении от элемента вверх по DOM дереву можно встретить любое число других элементов того же блока, либо сам блок. Нельзя встретить элементы других блоков или другие блоки;
* модификатор — синоним понятия «состояние». Модификатор реализует наследование блоков — когда нам нужен второй блок, очень похожий на первый. Модификатор всегда относится к какому-то конкретному блоку или элементу. У любого блока и элемента может быть несколько модификаторов, по несколько значений у каждого.
#### Область применения
Данное соглашение применяется для вновь создаваемых блоков (модулей). Сюда относится замена блока при рефакторинге. Соглашение имеет слабое влияние при небольших работах со старым кодом, а также при переиспользовании сторонних модулей.
#### HTML
* вёрстка должна быть [валидным](http://validator.w3.org/#validate_by_input+with_options) html5 кодом;
* код должен быть максимально семантичным;
* код должен быть в нижнем регистре;
* рекомендуется не указывать типы для тегов `script` и `link`;
* рекомендуется пропускать строку перед блоками, списками, таблицами и т.д.;
* должны использоваться двойные кавычки в атрибутах HTML.
##### Рекомендуется использовать теги html5
* `article` — выделение смысловой самостоятельной единицы (обычно блока);
* `address` — тег для адреса;
* `aside` — тег для сопутствующей информации, например «конкуренты»;
* `time` — тег для любого времени или даты;
* `header` и `footer` для явно выраженной шапки и футера блока, если такие есть;
* а также: `summary`, `nav` и другие.
Существующие теги и их назначение: http://www.w3.org/TR/html-markup/elements.html#elements
* рекомендуется использовать атрибуты [schema.org](http://schema.org/docs/gs.html#microdata_how);
* запрещено использовать «табличные» теги: `table`, `thead`, `tbody`, `tfoot`, `tr`, `th`, `td` кроме как по их прямому назначению — т.е. для отображения табличных данных;
* запрещено использование устаревших тегов: `font`, `blink` и прочее;
* у каждого тега, который будет иметь визуальное представление на странице, должен быть CSS-класс (полное покрытие тегов классами).
##### Структура
* должна использоваться методология БЭМ;
* любая визуальная HTML нода должна быть покрыта CSS-классом;
* структура HTML должна быть семантичной и минимально зависеть от дизайна. Иными словами, по HTML-коду должно быть всё понятно о содержимом страницы, но ничего не понятно о её дизайне.
Плохо:
Какой-то текст
Хорошо:
Школа №176
Красный проспект, д. 348
Приветствуется минимизация DOM-дерева (исключение различных оберток, оболочек, разделителей, однопиксельных GIF-файлов и т.п.).
##### Общий пример
""",
'style': u"""width: 300px; height: 150px;"""
},
scrollBarBaloon={
'title': u'scrollBarBalloon',
'mapInit':
u"""
DG.then(function () {
latLng = DG.latLng([54.98, 82.89]);
map = DG.map('map', {
center: latLng,
zoom: 13,
fullscreenControl: false,
zoomControl: false,
zoomAnimation: false
});
document.getElementById('scrollBar').onclick = function () {
DG.popup({
maxHeight: 300,
})
.setLatLng(latLng)
.setContent('Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ducimus ipsam itaque velit aut error ipsa sunt neque, ut molestiae. Omnis officia architecto similique, enim et voluptates sunt doloremque error repudiandae, iure est a quisquam, nulla voluptatibus quis nostrum voluptas vel ipsa consequatur ipsum velit. Nam laudantium, nemo iste enim ut soluta et explicabo amet nulla impedit sequi animi consectetur alias repellendus, laboriosam dolor dolorum tenetur quod modi sunt sapiente recusandae, pariatur! Delectus nihil provident hic perferendis veniam atque id, ad ipsum error laudantium, quo praesentium qui! Odit saepe distinctio aperiam autem dolor beatae nam, nostrum voluptate, reprehenderit tenetur quidem aspernatur!')
.openOn(map);
};
document.getElementById('noMaxHeight').onclick = function () {
DG.popup()
.setLatLng(latLng)
.setContent('Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facere, perspiciatis corrupti? Minima beatae sed delectus obcaecati, officia eos! Sint, excepturi facere iusto, sapiente facilis repellat. Eum facere, illo necessitatibus voluptatibus, illum quas. Cumque nisi incidunt, facere laboriosam asperiores nihil fugiat dolor dolorum sequi soluta consectetur non nulla vel praesentium omnis.')
.openOn(map);
};
document.getElementById('noScrollBar').onclick = function () {
DG.popup({
maxHeight: 300
})
.setLatLng(latLng)
.setContent('Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptas numquam distinctio impedit, quod totam eveniet dolorum qui? Corporis praesentium ipsum officiis impedit quas, inventore laboriosam ipsam nobis soluta maxime delectus quasi voluptatem, tenetur obcaecati laudantium error. Velit expedita, reprehenderit natus nihil cupiditate doloribus quis? In obcaecati cupiditate vero laudantium maiores.')
.openOn(map);
};
});
""",
'controls':
u"""
""",
'style': u"""width: 300px; height: 500px;"""
},
boundsNsk={
'title': u'boundsNsk',
'mapInit':
u"""
DG.then(function() {
map = DG.map('map', {
center: [54.98, 82.89],
zoom: 10,
maxBounds: [
[54.8220, 82.4304],
[55.1372, 83.3505]
],
minZoom: 10,
maxZoom: 15,
zoomAnimation: false
});
});
""",
'style': 'width: 670px; height: 400px;'
},
clickEvent={
'title': u'clickEvent',
'mapInit':
u"""
DG.then(function() {
var clickedElement = document.getElementById('info'),
coords = [
[54.99, 82.88],
[54.985, 82.94],
[54.984, 82.925],
[54.981, 82.928]
];
map = DG.map('map', {
center: [54.98, 82.89],
zoom: 13,
zoomAnimation: false
});
map.on('click', function(e) {
clickedElement.innerHTML = 'map ' + e.latlng.lat + ', ' + e.latlng.lng;
});
DG.marker([54.98, 82.89])
.on('click', function() {
clickedElement.innerHTML = 'marker';
})
.addTo(map);
DG.polygon(coords)
.on('click', function() {
clickedElement.innerHTML = 'polygon';
})
.addTo(map);
});
""",
'style': u"width: 100%; height: 400px;"
},
lazyLoad={
'title': u'lazyLoad',
'getParams': u'?lazy=true'
},
notLazyLoad={
'title': u'notLazyLoad',
'getParams': u'?lazy=false'
}
)
defaults = dict(
style='width: 1000px; height: 600px;',
loaderPath='..',
dgLoader='data-id="dgLoader"'
)
return extend(defaults, parts)
================================================
FILE: functional-tests/tests/__init__.py
================================================
# -*- coding: utf-8 -*-
import os
import contesto
from contesto import config as cfg
contesto.config.add_config_file(os.path.abspath(os.path.dirname(__file__)) + "/config.ini")
contesto.config.add_config_file(os.path.abspath(os.path.dirname(__file__)) + "/config.my.ini")
config = cfg
================================================
FILE: functional-tests/tests/balloon_test.py
================================================
# -*- coding: utf-8 -*-
from classes.mapsapi_base_test import MapsAPIBaseTest
from config import config
from lode_runner.dataprovider import dataprovider
class Balloons(MapsAPIBaseTest):
"""
Тесты балунов
"""
@dataprovider([
config.aut['local'] + u'/demo.html'
])
def balloon_to_marker_test(self, url):
"""
:param url: Адрес страницы
Проверка появления маркера при закрытии балуна
1.Кликаем в контрол закрытия балуна
2.Проверяем видимость маркера
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.balloon_crossed.wait_present()
self.page.balloon_crossed.close()
self.assertTrue(self.page.marker.is_visible)
@dataprovider([
config.aut['local'] + u'/openBalloons.html'
])
def balloon_default_open_test(self, url):
"""
:param url: Адрес страницы
Проверка програмного открытия балуна.
1.Проверяем что открыт балун по умолчанию
"""
self.driver.get(url)
self.page.map.wait_init()
balloon_text = self.page.balloon.get_content().text
self.assertEqual('default', balloon_text)
@dataprovider([
config.aut['local'] + u'/openBalloons.html'
])
def balloon_program_open_test(self, url):
"""
:param url: Адрес страницы
Проверка програмного открытия балуна.
1.Проверяем что открыт балун по умолчанию
2.Кликаем по кнопке "Открыть балун"
3.Проверяем что открыт один новый балун
"""
self.driver.get(url)
self.page.map.wait_init()
self.driver.find_element_by_css_selector('#showPopup').click()
self.page.balloon.wait_close()
self.page.balloon.wait_present()
balloon = self.page.balloon.get_content()
self.assertEqual(1, self.page.balloon.count())
self.assertEqual('request', balloon.text)
@dataprovider([
config.aut['local'] + u'/groupBalloon.html'
])
def balloon_group_open_test(self, url):
"""
:param url:
Проверка открытия группы балунов
1.Проверяем количество открытых балунов на карте
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.balloon.wait_present()
self.assertEqual(10, self.page.balloon.count())
@dataprovider([
(config.aut['local'] + u'/sprawlingBalloon.html', 'large', '350px'),
(config.aut['local'] + u'/sprawlingBalloon.html', 'mid', '290px'),
(config.aut['local'] + u'/sprawlingBalloon.html', 'small', '190px'),
])
def balloon_sprawling_test(self, url, size, width):
"""
:param url: Адрес страницы
:param size: Размер карты(large - 500px, mid - 300px, small - 200px)
:param width: Ширина балуна
Проверка размера балуна с параметром sprawling на карте
1.Выставляем размер карты
2.Кликаем в создать балун
3.Проверяем ширину
"""
self.driver.get(url)
self.page.map.wait_init()
self.driver.find_element_by_css_selector("input#%s" % size).click()
self.driver.find_element_by_css_selector('input#sprawling').click()
balloon_width = self.page.balloon.width
self.assertEqual(balloon_width, width)
@dataprovider([
(config.aut['local'] + u'/sprawlingBalloon.html', 'small', 'large', '350px'),
(config.aut['local'] + u'/sprawlingBalloon.html', 'small', 'mid', '290px'),
(config.aut['local'] + u'/sprawlingBalloon.html', 'large', 'small', '190px'),
])
def balloon_sprawling_resize_test(self, url, start, end, width):
"""
:param url: Адрес страницы
:param start: С какого размера переключаемся (размеры в описаны balloon_sprawling_test)
:param end: На какой переключаемся
:param width: Какой размер должен принять балун
Проверка размера балуна с параметром sprawling на большой карте
1.Выставляем ширину карты
2.Создаем балун
3.Меняем ширину карты
4.Приверяем ширину балуна
"""
self.driver.get(url)
self.page.map.wait_init()
self.driver.find_element_by_css_selector("input#%s" % start).click()
self.driver.find_element_by_css_selector('input#sprawling').click()
self.driver.find_element_by_css_selector("input#%s" % end).click()
balloon_width = self.page.balloon.width
self.assertEqual(balloon_width, width)
@dataprovider([
(config.aut['local'] + u'/scrollBarBalloon.html', 'scrollBar', True),
(config.aut['local'] + u'/scrollBarBalloon.html', 'noMaxHeight', False),
(config.aut['local'] + u'/scrollBarBalloon.html', 'noScrollBar', False),
])
def balloon_scroll_bar_test(self, url, type_, scroll_bar):
"""
Проверка скроллбара
:param url: Адрес страницы
:param type_: Какой балун
:param scroll_bar: Есть ли скролбар
1.Кликаем в создать балун
2.Проверяем наличие скролбара
"""
self.driver.get(url)
self.page.map.wait_init()
self.driver.find_element_by_css_selector("input#%s" % type_).click()
self.assertEqual(bool(self.page.balloon.scroll), scroll_bar)
@dataprovider([
(config.aut['local'] + u'/scrollBarBalloon.html', 'scrollBar', 300),
(config.aut['local'] + u'/scrollBarBalloon.html', 'noScrollBar', 240),
])
def balloon_max_height_test(self, url, type_, height):
"""
Проверка скроллбара
:param url: Адрес страницы
:param type_: Какой балун
:param height: Высота
1.Кликаем в создать балун
2.Проверяем высоту балуна
"""
self.driver.get(url)
self.page.map.wait_init()
self.driver.find_element_by_css_selector("input#%s" % type_).click()
balloon_height = self.page.balloon.height
self.assertEqual(balloon_height, "%dpx" % height)
================================================
FILE: functional-tests/tests/bounds_test.py
================================================
# -*- coding: utf-8 -*-
from classes.mapsapi_base_test import MapsAPIBaseTest
from config import config
from lode_runner.dataprovider import dataprovider
from classes.util import scripts
class Bounds(MapsAPIBaseTest):
"""
Тесты на ограничение зума и границ
"""
@dataprovider([
config.aut['local'] + u'/boundsNsk.html'
])
def bound_min_zoom_script_test(self, url):
"""
:param url: Адрес страницы
Проверка ограничения минимального зума
1.Выставляем зум меньше ограничения
2.Проверяем что зум равен ограничению
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(scripts.SetScripts.set_zoom(9))
zoom = self.page.console(scripts.GetScripts.getZoom)
self.assertEqual(10, zoom)
@dataprovider([
config.aut['local'] + u'/boundsNsk.html'
])
def bound_max_zoom_script_test(self, url):
"""
:param url: Адрес страницы
Проверка ограничения максимального зума
1.Выставляем зум больше ограничения
2.Проверяем что зум равен ограничению
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(scripts.SetScripts.set_zoom(16))
zoom = self.page.console(scripts.GetScripts.getZoom)
self.assertEqual(15, zoom)
@dataprovider([
config.aut['local'] + u'/boundsNsk.html'
])
def bound_max_zoom_control_test(self, url):
"""
:param url: Адрес страницы
Проверка ограничения максимального зума
1.Выставляем зум равный ограничению
2.Кликаем в контрол zoom in
3.Проверяем что зум равен ограничению
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(scripts.SetScripts.set_zoom(15))
self.page.zoom_control_in.zoom_in_click()
zoom = self.page.console(scripts.GetScripts.getZoom)
self.assertEqual(15, zoom)
@dataprovider([
config.aut['local'] + u'/boundsNsk.html'
])
def bound_min_zoom_control_test(self, url):
"""
:param url: Адрес страницы
Проверка ограничения минимального зума
1.Выставляем зум равный ограничения
2.Кликаем
3.Проверяем что зум равен ограничению
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(scripts.SetScripts.set_zoom(10))
self.page.zoom_control_out.zoom_out_click()
zoom = self.page.console(scripts.GetScripts.getZoom)
self.assertEqual(10, zoom)
================================================
FILE: functional-tests/tests/event_test.py
================================================
# -*- coding: utf-8 -*-
from classes.mapsapi_base_test import MapsAPIBaseTest
from config import config
from lode_runner.dataprovider import dataprovider
from classes.util.scripts import SetScripts
from classes.util import misc
class EventHandlers(MapsAPIBaseTest):
@dataprovider([
(config.aut['local'] + u'/clickEvent.html')
])
def click_marker_test(self, url):
"""
Проверка события click для маркера
:param url: Адрес страницы
1.Открываем страницу
2.Кликаем в маркер
3.Проверяем содержимое info
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.marker.click()
info = self.page.map.info_elem()
self.assertEqual(info.text, 'marker')
@dataprovider([
(config.aut['local'] + u'/clickEvent.html', {'lat': 54.99, 'lng': 82.73})
])
def click_map_test(self, url, point):
"""
Проверка события click для карты
:param url: Адрес страницы
:param point: Координаты на карте
1.Открываем страницу
2.Кликаем в координаты
3.Проверяем содержимое info
"""
self.driver.get(url)
self.page.map.wait_init()
info = self.page.map.info_elem()
self.page.console(SetScripts.set_zoom(17))
self.page.console(SetScripts.pan_to(point['lat'], point['lng']))
self.page.map.center_click()
self.assertEqual(info.text.split(' ')[0], 'map')
coords = misc.coord_string_to_dict(info.text[4:])
self.assertTrue(misc.coord_equals(point, coords, 2))
@dataprovider([
(config.aut['local'] + u'/clickEvent.html', {'lat': 54.985, 'lng': 82.911})
])
def click_polygon_test(self, url, point):
"""
Проверка события click для карты
:param url: Адрес страницы
:param point: Координаты на карте внутри полигона
1.Открываем страницу
2.Кликаем в координаты
3.Проверяем содержимое info
"""
self.driver.get(url)
self.page.map.wait_init()
info = self.page.map.info_elem()
self.page.console(SetScripts.set_zoom(17))
self.page.console(SetScripts.pan_to(point['lat'], point['lng']))
self.page.map.center_click()
self.assertEqual(info.text, 'polygon')
================================================
FILE: functional-tests/tests/firm_callout_test.py
================================================
# -*- coding: utf-8 -*-
from classes.mapsapi_base_test import MapsAPIBaseTest
from config import config
from lode_runner.dataprovider import dataprovider
from classes.util import scripts
from classes.WAPI.dataWorker import FirmData
import classes.util.misc as misc
import classes.util.link_generator as links
class FirmCallout(MapsAPIBaseTest):
"""
Тесты на сallout фирмы
"""
@dataprovider([(
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254,
141265770417218
)
])
def firm_name_test(self, url, lat, lng, firm_id):
"""
Проверка заголовка фирмы
1.Открываем калаут фирмы
2.Проверяем заголовок
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(scripts.SetScripts.pan_to(lat, lng))
self.page.console(scripts.SetScripts.set_zoom(17))
self.page.map.center_click()
self.page.build_callout.wait_present()
self.page.build_callout.open_firm_list()
self.page.build_callout.open_firm_by_id(firm_id)
callout_text = self.page.firm_callout.header
f = FirmData(firm_id)
self.assertEqual(f.firm_name, callout_text)
@dataprovider([(
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254
)
])
def firm_back_list_test(self, url, lat, lng):
"""
Проверка кнопки назад (в здании с мн. организаций)
1.Открываем калаут фирмы
2.Нажимаем назад
3.Проверяем наличие списка организаций
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(scripts.SetScripts.pan_to(lat, lng))
self.page.console(scripts.SetScripts.set_zoom(17))
self.page.map.center_click()
self.page.build_callout.wait_present()
self.page.build_callout.open_firm_list()
self.page.build_callout.open_firm_by_index(1)
self.page.firm_callout.back()
self.assertTrue(self.page.firm_list.list_present())
@dataprovider([(
config.aut['local'] + u'/base.html',
54.987722587459736,
82.88787066936494
)
])
def firm_back_build_test(self, url, lat, lng):
"""
Проверка кнопки назад (к зданию)
1.Открываем калаут фирмы
2.Нажимаем назад
3.Проверяем наличие колаута здания
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(scripts.SetScripts.pan_to(lat, lng))
self.page.console(scripts.SetScripts.set_zoom(17))
self.page.map.center_click()
self.page.build_callout.wait_present()
self.page.build_callout.open_firm_by_index(1)
self.page.firm_callout.back()
self.assertTrue(self.page.build_callout.is_visible)
@dataprovider([(
config.aut['local'] + u'/base.html',
54.987722587459736,
82.88787066936494,
17,
['2gis.ru', 'novosibirsk', 'center', 82.89, 54.99, 'zoom', '17',
'routeTab', 'rsType', 'bus', 'to', 82.89, 54.99, 'Новосибирск, Ватутина, 16']
), (
config.aut['local'] + u'/base.html',
-33.44449709158904,
-70.6516680121422,
18,
['2gis.cl', 'santiago', 'center', -70.65, -33.44, 'zoom', '18',
'routeTab', 'rsType', 'bus', 'to', -70.65, -33.44, 'Santiago, Avenida Libertador Bernardo O\'Higgins, 1112']
)
])
def firm_route_to(self, url, lat, lng, zoom, parts):
"""
Проверка ссылки на проехать до
1.Открываем калаут фирмы
2.Проверяем атирибут ссылки "Проехать сюда"
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(scripts.SetScripts.pan_to(lat, lng))
self.page.console(scripts.SetScripts.set_zoom(zoom))
self.page.map.center_click()
self.page.build_callout.wait_present()
self.page.build_callout.open_firm_by_index(1)
route = self.page.firm_callout.route_link
self.assertTrue(misc.check_route(route.get_attribute('href'), parts))
@dataprovider([(
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254,
141265770417218
)
])
def firm_photo_test(self, url, lat, lng, firm_id):
"""
Проверка наличия фото у фирмы
1.Открыть фирму с фото
2.Проверить наличие ссылки
3.Проверить url ссылки
4.Проверить количество фото
"""
self._open_firm(url, lat, lng, firm_id)
photo = self.page.firm_callout.photo
self.assertTrue(photo.is_displayed())
f = FirmData(firm_id)
num = misc.to_int(photo.text)
self.assertEqual(f.photo_count(), num)
link = links.photo_link(firm_id)
self.assertEqual(link, photo.get_attribute('href'))
@dataprovider([(
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254,
141265771060872
)
])
def firm_rating_test(self, url, lat, lng, firm_id):
"""
Проверка наличия рейтинга у фирмы
1.Открыть фирму с рейтингом
2.Проверить наличие рейтинга
3.Проверить url ссылки
4.Проверить количество отзывов
"""
self._open_firm(url, lat, lng, firm_id)
stars = self.page.firm_callout.stars
reviews = self.page.firm_callout.reviews
f = FirmData(firm_id)
self.assertTrue(stars.is_displayed())
self.assertEqual(reviews.get_attribute('href'), links.reviews_link(firm_id))
reviews_count = misc.to_int(reviews.text)
self.assertEqual(reviews_count, f.review_count)
@dataprovider([(
config.aut['local'] + u'/base.html',
54.97883,
82.872775,
141265769707278
)
])
def firm_address_test(self, url, lat, lng, firm_id):
"""
Проверка наличия адреса
1.Открыть фирму
2.Проверить наличие адреса
3.Проверить адрес
"""
self._open_firm(url, lat, lng, firm_id)
f = FirmData(firm_id)
self.assertTrue(self.page.firm_callout.address.is_displayed())
self.assertEqual(self.page.firm_callout.address.text, f.address_name)
@dataprovider([(
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254,
141265771060872
)
])
def firm_address_comment_test(self, url, lat, lng, firm_id):
"""
Проверка наличия комментария к адресу
1.Открыть фирму с комментарием
2.Праверить наличие комментария
"""
self._open_firm(url, lat, lng, firm_id)
f = FirmData(firm_id)
self.assertTrue(self.page.firm_callout.address.is_displayed())
full_adress = misc.address_and_comment(f.address_name, f.address_comment)
self.assertEqual(self.page.firm_callout.address.text, full_adress)
@dataprovider([(
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254,
141265771060872
), (
config.aut['local'] + u'/base.html',
54.9810307939813,
82.87442207336427,
141265769728580
)
])
def firm_telephone_count_test(self, url, lat, lng, firm_id):
"""
Проверка наличия и количества телефонов
1.Открывем фирму
2.Получаем количество телефонов (из API)
3.Проверяем количество телефонов
"""
self._open_firm(url, lat, lng, firm_id)
f = FirmData(firm_id)
phones_wapi = f.get_phones()
phones_num = len(phones_wapi)
phones_callout = self.page.firm_callout.phones()
self.assertEqual(phones_num, len(phones_callout))
@dataprovider([(
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254,
141265771060872
)
])
def firm_telephone_comment_test(self, url, lat, lng, firm_id):
"""
Проверка наличия комментария к телефону
1.Открываем фирму
2.Проверяем наличия комментария к телефону
"""
self._open_firm(url, lat, lng, firm_id)
f = FirmData(firm_id)
phones_wapi = f.get_phones()
phones_callout = self.page.firm_callout.phones()
phone_and_comment = misc.phone_and_comment(phones_wapi[0]['text'], phones_wapi[0]['comment'])
self.assertEqual(phones_callout[0].text, phone_and_comment)
@dataprovider([(
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254,
141265770417218
), (
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254,
141265770847007
)
])
def firm_website_count_test(self, url, lat, lng, firm_id):
"""
Проверка наличия ссылки на вебсайт
1.Открываем фирму
2.Проверяем наличие ссылки на вебсайт
3.Проверяем количество ссылок
"""
self._open_firm(url, lat, lng, firm_id)
f = FirmData(firm_id)
websites_wapi = f.get_websites()
websites_callout = self.page.firm_callout.websites()
self.assertEqual(len(websites_callout), len(websites_wapi))
self.assertEqual(websites_callout[0].text, websites_wapi[0]['text'])
@dataprovider([(
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254,
141265771881838
)])
def firm_email_test(self, url, lat, lng, firm_id):
"""
Проверка наличия email
1.Открываем фирму
2.Проверяем наличие email
3.Проверяем ссыль на мейл
"""
self._open_firm(url, lat, lng, firm_id)
f = FirmData(firm_id)
email = self.page.firm_callout.email
self.assertEqual(email.text, f.get_emails()[0]['text'])
self.assertEqual(email.get_attribute('href'), "mailto:%s" % f.get_emails()[0]['value'])
# для простого, списка и таблицы
def firm_schedule(self):
"""
Проверка наличия расписания
1.Открываем фирму
2.Проверяем наличие расписания
3.Проверяем наличие подсказки
"""
pass
def firm_schedule_wrapper_list(self):
"""
Проверка расписания-списка
1.Открываем фирму
2.Проверяем расписание на сегодня (для всех языков)
3.Кликаем в врапер
4.Проверяем наличие списка
5.Отсутсвие посдсказки на сегодня
"""
pass
def firm_schedule_wrapper_table(self):
"""
Проверка расписания-таблицы
1.Открываем фирму
2.Проверяем расписание на сегодня (для всех языков)
3.Кликаем в врапер
4.Проверяем наличие таблицы
5.Отсутсвие посдсказки на сегодня
"""
pass
@dataprovider([(
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254,
141265771060872
)
])
def firm_rubrics_test(self, url, lat, lng, firm_id):
"""
Проверка рубрик
1.Открываем фирму
2.Проверяем количество рубрик
3.Проверяем порядок(первая, последняя, в сеередине с учетом primary)
"""
self._open_firm(url, lat, lng, firm_id)
f = FirmData(firm_id)
primary = self.page.firm_callout.primary_rubrics
self.assertEqual(primary[0].text, f.get_rubrics_primary()[0]['name'])
primary_last = len(f.get_rubrics_primary()) - 1
self.assertEqual(primary[primary_last].text, f.get_rubrics_primary()[primary_last]['name'])
additional = self.page.firm_callout.additional_rubrics
self.assertEqual(additional[0].text, f.get_rubrics_additional()[0]['name'])
additional_last = len(f.get_rubrics_additional()) - 1
self.assertEqual(additional[additional_last].text,
f.get_rubrics_additional()[additional_last]['name'])
@dataprovider([(
config.aut['local'] + u'/base.html',
54.980678320392336,
82.89860486984254,
141265771060872
)
])
def firm_scroll_bar_test(self, url, lat, lng, firm_id):
"""
Проверка наличия скролл-бара
1.Открываем фирму со скроллбаром
2.Проверяем его наличия
"""
self._open_firm(url, lat, lng, firm_id)
self.assertTrue(self.page.firm_callout.scroll.is_displayed())
def _open_firm(self, url, lat, lng, firm_id):
self.driver.get(url)
self.page.map.wait_init()
self.page.console(scripts.SetScripts.pan_to(lat, lng))
self.page.console(scripts.SetScripts.set_zoom(17))
self.page.map.center_click()
self.page.build_callout.wait_present()
self.page.build_callout.open_firm_list()
self.page.build_callout.open_firm_by_id(firm_id)
================================================
FILE: functional-tests/tests/geo_clicker_test.py
================================================
# -*- coding: utf-8 -*-
from classes.mapsapi_base_test import MapsAPIBaseTest
from config import config
from lode_runner.dataprovider import dataprovider
from classes.util.scripts import SetScripts
from classes.util.scripts import GetScripts
from classes.WAPI.dataWorker import GeoData
from classes.WAPI.dataWorker import FirmData
from classes.WAPI.dataWorker import GalleryData
class GeoClicker(MapsAPIBaseTest):
"""
Тесты геокликера.
В данных тестах проверяется открытие нужных колаутов в соответствии с координатами и зумом.
Кроме того для описания переводов используются словари с ключами языков.
"""
not_found = {
'ru': u"Это место мы ещё не успели изучить",
'en': u"We haven't collected info about this place yet",
'cs': u"O tomto místě zatím nemáme informace",
'es': u"Todavía no hemos recopilado la información sobre este lugar",
'it': u"Non disponiamo ancora di informazioni su questo posto"
}
city = {
'ru': u"Город",
'en': u"City",
'cs': u"Město",
'es': u"Ciudad",
'it': u"Сittà"
}
district = {
'ru': u"Район",
'en': u"District",
'cs': u"Městská část",
'es': u"Comuna",
'it': u"Municipalità"
}
street = {
'ru': u"Улица",
'en': u"Street",
'cs': u"Ulice",
'es': u"Calle",
'it': u"Via"
}
@dataprovider([
(config.aut['local'] + u'/base.html', 54.98, 82.32)
])
def callout_unknown_place_test(self, url, lat, lng):
"""
:param url: Адрес страницы
:param lat: Широта
:param lng: Долгота
Тест на проверку колаута неизвестного места.
1.Перемещаемся к координатам
2.Кликаем в центр
3.Проверяем открытие калаута
4.Проверяем содержимое колаута для всех языков
"""
self.driver.get(url)
self.page.map.wait_init()
self.driver.execute_script(SetScripts.pan_to(lat, lng))
self.page.map.center_click()
self.page.unkown_place.wait_present()
self.assertTrue(self.page.unkown_place.is_visible)
for lang in self.not_found:
self.driver.execute_script(SetScripts.set_lang(lang))
header = self.page.unkown_place.header
self.assertEqual(self.not_found[lang], header)
@dataprovider([
config.aut['local'] + u'/base.html'
])
def callout_city_place_test(self, url):
"""
:param url: Адрес страницы
Тест на проверку колаута города.
1.Изменяем изначальный зум к 8
2.Кликаем в центр
3.Проверяем открытие калаута
4.Проверяем название города
5.Проверяем информацию о геообъекте на всех языках
"""
self.driver.get(url)
self.page.map.wait_init()
self.driver.execute_script(SetScripts.set_zoom(8))
center = self.driver.execute_script(GetScripts.getCenter)
g = GeoData(center, 8)
self.page.map.center_click()
self.page.place_callout.wait_present()
self.assertEqual(self.page.place_callout.header, g.city_name)
for lang in self.city:
self.driver.execute_script(SetScripts.set_lang(lang))
purpose = self.page.place_callout.purpose
self.assertEqual(self.city[lang], purpose)
@dataprovider([
config.aut['local'] + u'/base.html'
])
def callout_district_place_test(self, url):
"""
:param url: Адрес страницы
Тест на проверку колаута района.
1.Кликаем в центр
2.Проверяем открытие калаута
3.Проверяем название района
4.Проверяем адрес района
5.Проверяем информацию о геообъекте на всех языках
"""
self.driver.get(url)
self.page.map.wait_init()
center = self.driver.execute_script(GetScripts.getCenter)
self.page.map.center_click()
self.page.addresed_place_callout.wait_present()
zoom = self.driver.execute_script(GetScripts.getZoom)
g = GeoData(center, zoom)
district_addr = g.place_address
callout_addr = self.page.addresed_place_callout.drilldown
self.assertEqual(self.page.addresed_place_callout.header, g.district_name)
self.assertEqual(callout_addr, district_addr)
for lang in self.district:
self.driver.execute_script(SetScripts.set_lang(lang))
purpose = self.page.addresed_place_callout.purpose
self.assertEqual(self.district[lang], purpose)
@dataprovider([
(config.aut['local'] + u'/base.html', 54.9802611969944, 82.89837956428528)
])
def callout_building_name_test(self, url, lat, lng):
"""
:param url: Адрес страницы
:param lat: Широта
:param lng: Долгота
Проверка здания с названием.
1.Перемещаемся к координатам
2.Изменяем изначальный зум к 18
3.Кликаем в центр
4.Проверяем наличие названия в заголовке
"""
self.driver.get(url)
self.page.map.wait_init()
self.driver.execute_script(SetScripts.pan_to(lat, lng))
self.driver.execute_script(SetScripts.set_zoom(18))
self.page.map.center_click()
center = self.driver.execute_script(GetScripts.getCenter)
self.page.build_callout.wait_present()
g = GeoData(center, 18)
self.assertEqual(g.build_name, self.page.build_callout.header)
@dataprovider([
(config.aut['local'] + u'/base.html', 54.98511556781472, 82.85259425640108)
])
def callout_building_without_name_test(self, url, lat, lng):
"""
:param url: Адрес страницы
:param lat: Широта
:param lng: Долгота
Проверка здания без названия.
1.Перемещаемся к координатам
2.Изменяем изначальный зум к 18
3.Кликаем в центр
4.Проверяем наличие адреса в заголовке
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(SetScripts.set_zoom(18))
self.page.console(SetScripts.pan_to(lat, lng))
self.page.map.center_click()
center = self.page.console(GetScripts.getCenter)
g = GeoData(center, 18)
self.page.build_callout.wait_present()
self.assertEqual(g.build_name, self.page.build_callout.header)
@dataprovider([
(config.aut['local'] + u'/base.html', 54.98127706190138, 82.88240969181062)
])
def callout_attraction_test(self, url, lat, lng):
"""
:param url: Адрес страницы
:param lat: Широта
:param lng: Долгота
Проверка калаута достопремичательности.
1.Перемещаемся к координатам
2.Изменяем изначальный зум к 18
3.Кликаем в центр
4.Проверяем наличие калаута
6.Проверяем заголовок калаута
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(SetScripts.pan_to(lat, lng))
self.page.console(SetScripts.set_zoom(18))
self.page.map.center_click()
self.page.attraction_callout.wait_present()
center = self.page.console(GetScripts.getCenter)
g = GeoData(center, 18)
self.assertTrue(self.page.attraction_callout.is_visible)
self.assertEqual(g.attraction_name, self.page.attraction_callout.header)
@dataprovider([
(config.aut['local'] + u'/base.html', 54.9833825909448, 82.89679169654848)
])
def callout_street_test(self, url, lat, lng):
"""
:param url: Адрес страницы
:param lat: Широта
:param lng: Долгота
Проверка калаута улицы.
1.Перемещаемся к координатам
2.Изменяем изначальный зум к 18
3.Кликаем в центр
4.Проверяем наличие калаута
5.Проверяем название улицы
6.Проверяем расположение улицы
7.Проверяем информацию о геообъекте на всех языках
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(SetScripts.pan_to(lat, lng))
self.page.console(SetScripts.set_zoom(18))
self.page.map.center_click()
center = self.page.console(GetScripts.getCenter)
g = GeoData(center, 18)
self.page.addresed_place_callout.wait_present()
self.assertTrue(self.page.addresed_place_callout.is_visible)
self.assertEqual(g.street_name, self.page.addresed_place_callout.header)
self.assertEqual(self.page.addresed_place_callout.drilldown, g.street_address)
for lang in self.street:
self.page.console(SetScripts.set_lang(lang))
self.assertEqual(self.page.addresed_place_callout.purpose, self.street[lang])
@dataprovider([
(config.aut['local'] + u'/base.html', '54.986870015252265', '82.8704744636')
])
def callout_attraction_text_test(self, url, lat, lng):
"""
:param url: Адрес страницы
:param lat: Широта
:param lng: Долгота
Проверка калаута памятника с текстом.
1.Перемещаемся к координатам
2.Изменяем изначальный зум к 18
3.Кликаем в центр
4.Проверяем наличие калаута
6.Проверяем заголовок калаута
7.Проверяем наличие враппера
8.Проверяем текст
9.Кликаем во враппер
10.Проверяем отсутствие враппера
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(SetScripts.set_zoom(18))
self.page.console(SetScripts.pan_to(lat, lng))
self.page.map.center_click()
self.page.attraction_callout_wrapped.wait_present()
center = self.page.console(GetScripts.getCenter)
g = GeoData(center, 18)
self.assertTrue(self.page.attraction_callout_wrapped.is_visible)
self.assertEqual(g.attraction_name, self.page.attraction_callout.header)
self.assertTrue(self.page.attraction_callout_wrapped.wrapper())
self.assertEqual(g.attraction_description, self.page.attraction_callout_wrapped.text)
self.page.attraction_callout_wrapped.unwrap()
self.assertFalse(self.page.attraction_callout_wrapped.wrapper())
@dataprovider([
(config.aut['local'] + u'/base.html', '54.98088611087379', '82.89719912975313', 141265770417218)
])
def callout_poi_test(self, url, lat, lng, firm_id):
"""
:param url: Адрес страницы
:param lat: Широта
:param lng: Долгота
:param firm_id:
Проверка калаута POI.
1.Перемещаемся к координатам
2.Изменяем изначальный зум к 18
3.Кликаем в центр
4.Проверяем наличие калаута
6.Проверяем заголовок калаута
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(SetScripts.set_zoom(18))
self.page.console(SetScripts.pan_to(lat, lng))
self.page.map.center_click()
self.page.firm_callout.wait_present()
f = FirmData(firm_id)
self.assertEqual(self.page.firm_callout.header, f.firm_name)
@dataprovider([
(config.aut['local'] + u'/base.html', '-33.44692090822703', '-70.65750718116762', 14215121979385186)
])
def callout_poi_gallery_test(self, url, lat, lng, firm_id):
"""
:param url: Адрес страницы
:param lat: Широта
:param lng: Долгота
:param firm_id:
Проверка калаута памятника с текстом.
1.Перемещаемся к координатам
2.Изменяем изначальный зум к 18
3.Кликаем в центр
4.Проверяем наличие калаута
6.Проверяем заголовок калаута
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.console(SetScripts.pan_to(lat, lng))
self.page.console(SetScripts.set_zoom(19))
self.page.map.center_click()
self.page.build_callout.wait_present()
g = GalleryData(firm_id)
self.assertEqual(self.page.build_callout.header, g.gallery_name)
================================================
FILE: functional-tests/tests/loader_test.py
================================================
# -*- coding: utf-8 -*-
from classes.mapsapi_base_test import MapsAPIBaseTest
from config import config
from lode_runner.dataprovider import dataprovider
from classes.util.scripts import SetScripts
class LoaderTest(MapsAPIBaseTest):
"""
Тесты параметров лоадера mapsapi
"""
@dataprovider([
(config.aut['local'] + u'/lazyLoad.html')
])
def loader_dg_then_add_app_test(self, url):
"""
:param url: Адрес страницы
Тест на проверку ленивой загрузки
1.Открываем страницу
2.Проверяем отсутсвие скрипта
3.Выполняем DG.then
4.Проверяем наличие скрипта
"""
self.driver.get(url)
self.assertTrue(not self.page.sources.app_js_present)
self.driver.execute_script(SetScripts.dg_then())
self.assertTrue(self.page.sources.app_js_present)
@dataprovider([
(config.aut['local'] + u'/notLazyLoad.html')
])
def loader_lazy_false_add_app_test(self, url):
"""
:param url: Адрес страницы
Тест на проверку ленивой загрузки
1.Открываем страницу
4.Проверяем наличие скрипта
"""
self.driver.get(url)
self.assertTrue(self.page.sources.app_js_present)
================================================
FILE: functional-tests/tests/marker_test.py
================================================
# -*- coding: utf-8 -*-
from classes.mapsapi_base_test import MapsAPIBaseTest
from config import config
from lode_runner.dataprovider import dataprovider
from classes.util.scripts import SetScripts
from classes.util.scripts import GetScripts
class Marker(MapsAPIBaseTest):
@dataprovider([
config.aut['local'] + u'/demo.html'
])
def marker_to_balloon_test(self, url):
"""
:param url: Адрес страницы
Проверка появления балуна при клике в маркер
1.Кликаем в контрол закрытия балуна
2.Кликаем в маркер
3.Проверяем наличие балуна
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.balloon_crossed.wait_present()
self.page.balloon_crossed.close()
self.page.marker.wait_present()
self.page.marker.click()
self.page.balloon_crossed.wait_present()
self.assertTrue(self.page.balloon_crossed.is_visible)
@dataprovider([
config.aut['local'] + u'/draggableMarker.html'
])
def marker_drag_test(self, url):
"""
:param url: Адрес страницы
Проверка изменения координат маркера
1.Драгаем маркер на 10px вниз и вправо
2.Проверяем значение абзацев с координатами
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.marker.drag_marker(10, 10)
lat = self.page.marker.get_lat()
lng = self.page.marker.get_lng()
self.assertEqual(lat, '54.981')
self.assertEqual(lng, '82.891')
@dataprovider([
config.aut['local'] + u'/markerLabels.html'
])
def marker_static_label_test(self, url):
"""
:param url: Адрес страницы
Проверка наличия статического лэйбла у маркера
1.Проверяем наличие лейбла у маркера
"""
self.driver.get(url)
self.page.map.wait_init()
self.assertEqual(self.page.marker.get_labels()[0].text, u'static')
@dataprovider([
config.aut['local'] + u'/markerLabels.html'
])
def marker_dynamic_label_test(self, url):
"""
:param url: Адрес страницы
Проверка наличия стандартного лейбла у маркера
1.Наводим мышь на маркер
2.Проверяем наличие лейбла
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.marker.hover_marker(1)
text = self.page.marker.get_labels()[1].text
self.assertEqual(text, u'default')
@dataprovider([
config.aut['local'] + u'/demo.html'
])
def marker_program_open_test(self, url):
"""
:param url: Адрес страницы
Проверка возможности програмного открытия маркеров
1.Закрываем колаут
2.Открываем его программно
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.balloon_crossed.close()
self.page.console(SetScripts.open_marker())
self.assertTrue(self.page.balloon_crossed.is_visible)
@dataprovider([
config.aut['local'] + u'/groupMarkerEvent.html'
])
def marker_group_events_test(self, url):
"""
:param url: Адрес страницы
Проверка обработки событиев у маркеров
1.Кликаем в маркер 3
2.Проверяем изменение координат карты
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.marker.click(2)
center = self.page.console(GetScripts.getCenter)
lat = '%.3f' % center['lat']
lng = '%.3f' % center['lng']
self.assertEqual(lat, self.page.marker.get_lat('marker3'))
self.assertEqual(lng, self.page.marker.get_lng('marker3'))
@dataprovider([
config.aut['local'] + u'/groupMarkerEvent.html'
])
def marker_group_bounds_test(self, url):
"""
:param url: Адрес страницы
Проверка подстройки границ под положение маркеров
1.Выставляем большой зум
2.Выполняем fitBounds по маркерам
2.Проверяем изменение координат карты и зума
"""
self.driver.get(url)
self.page.map.wait_init()
self.page.map.set_zoom(17)
self.page.console('map.fitBounds(group.getBounds())')
center = self.page.console(GetScripts.getCenter)
lat = '%.3f' % center['lat']
lng = '%.3f' % center['lng']
self.assertEqual(lat, '54.914')
self.assertEqual(lng, '82.976')
================================================
FILE: functional-tests/tests/ruler_test.py
================================================
# -*- coding: utf-8 -*-
from classes.mapsapi_base_test import MapsAPIBaseTest
from config import config
from lode_runner.dataprovider import dataprovider
from classes.util import scripts
class Ruler(MapsAPIBaseTest):
"""
Тесты на линейку
"""
def ruler_control(self):
"""
Проверка контрола линеки
1.Кликаем в контрол линейки
2.Кликаем в центр карты
3.Проверяем наличие вершин линейки
4.Кликаем в контрол линейки
5.Проверяем отсутсвие вершин линейки
"""
pass
def ruler_two_vertexes(self):
"""
Проверка появления ребер линейки
1.Кликаем в контрол
2.Кликаем в центр карты
3.Кликаем левее на 150px
4.Проверяем наличие 2х вершин
5.Проверяем расстояние
5.Проверяем наличие ребра
"""
pass
def ruler_vertex_in_middle(self):
"""
Проверка добаления не крайних вершин
1.Кликаем в контрол линейки
2.Кликаем в центр карты
3.Кликаем на 300px левее
4.Кликаем на 150px правее
5.Проверяем наличие 3х вершин
6.Проверяем что узел добавился в середину
"""
pass
def ruler_vertex_in_end(self):
"""
Проверка добаления точки в конце
1.Кликаем в контрол линейки
2.Кликаем в центр карты
3.Кликаем на 150px левее
4.Кликаем на 150px левее
5.Проверяем наличие 3х вершин
6.Проверяем что узел добавился в конец
"""
pass
def ruler_hover_vertex(self):
"""
Проверка ховера не полседнего узла
1.Кликаем в контрол линейки
2.Кликаем в центр карты
3.Кликаем на 150px левее
4.Кликаем на 150px левее
5.Перемещаем курсор на 150px правее
6.Проверяем появление маркера
7.Проверяем расстояние
8.Перемещаем на 150px правее
9.Провяем наличие маркера
10.Проверяем расстояние на 0
"""
pass
def ruler_hover_line(self):
"""
Проверка ховера линии
1.Кликаем в контрол линейки
2.Кликаем в центр карты
3.Кликаем на 300px левее
4.Перемещаем на 150px правее
5.Проверяем наличе маркера
"""
pass
def ruler_delete_last(self):
"""
Проверка удаления единственного узла
1.Кликаем в контрол линейки
2.Кликаем в центр карты
3.Ховерим узел
4.Кликаем в крест в маркере
5.Проверяем отсутствие узлов
"""
pass
def ruler_delete_first_in_two(self):
"""
Проверка удаления первого в случае двух узлов
1.Кликаем в контрол линейки
2.Кликаем в центр карты
3.Кликам на 150px левее
4.Удаляем первый узел
5.Проверяем что остался только один узел
6.Проверяем что узел остался на месте 2го
7.Проверяем наличие маркера и значение в '0м'
"""
pass
def ruler_delete_last_in_two(self):
"""
Проверка удаления первого в случае двух узлов
1.Кликаем в контрол линейки
2.Кликаем в центр карты
3.Кликам на 150px левее
4.Удаляем второй узел
5.Проверяем что остался только один узел
6.Проверяем что узел остался на месте 1го
7.Проверяем наличие маркера и значение в '0м'
"""
pass
def ruler_delete_last_in_many(self):
"""
Проверка удаления последнего (3 и более узла)
1.Кликам в контрол линейки
2.Кликаем в центр карты
3.Кликам на 150px левее
4.Кликам на 150px левее
5.Удаляем последний
6.Проверяем что маркер появился на втором
"""
pass
def ruler_delete_first_in_many(self):
"""
Проверка удаления первого (3 и более узла)
1.Кликам в контрол линейки
2.Кликаем в центр карты
3.Кликам на 150px левее
4.Кликам на 150px левее
5.Удаляем первый
6.Ховерим второй
7.Проверяем маркер и '0м'
"""
pass
def ruler_delete_middle_in_many(self):
"""
Проверка удаления среднего
1.Кликаем в контрол линейки
2.Кликаем в центр карты
3.Кликаем на 150px левее и 150px выше
4.Кликаем на 150px левее и 150px ниже
5.Удаляем второй узел
6.Проверяем что вершины 2
7.Проверяем что ребро 1
8.Проверяем расстояние в маркере последней вершины
"""
pass
def ruler_drag_last(self):
"""
Проверка драга последнего
1.Кликам в контрол линейки
2.Кликаем в центр карты
3.Кликам на 150px левее
4.Кликам на 150px левее
5.Перемещаем последний узел на 100px
6.Проверяем что переместился нужный узел
7.Проверяем значения расстояния в последнем маркере
"""
pass
def ruler_drag_first(self):
"""
Проверка драга первого
1.Кликам в контрол линейки
2.Кликаем в центр карты
3.Кликам на 150px левее
4.Кликам на 150px левее
5.Перемещаем первий узел на 100px
6.Проверяем что переместился нужный узел
7.Проверяем значения расстояния в последнем
8.Проверяем значение расстояния в первом на 0
"""
pass
def ruler_drag_middle(self):
"""
Проверка драга среднего
1.Кликам в контрол линейки
2.Кликаем в центр карты
3.Кликам на 150px левее
4.Кликам на 150px левее
5.Перемещаем средний узел на 100px вверх
6.Проверяем что переместился нужный узел
7.Проверяем значения расстояния
"""
pass
================================================
FILE: functional-tests/tests/zoom_test.py
================================================
# -*- coding: utf-8 -*-
from classes.mapsapi_base_test import MapsAPIBaseTest
from config import config
from lode_runner.dataprovider import dataprovider
from classes.util.scripts import GetScripts
class Zoom(MapsAPIBaseTest):
@dataprovider([
config.aut['local'] + u'/base.html'
])
def zoomIn_click_test(self, url):
"""
:param url: Адрес страницы
Проверка контрола зума +.
1.Получаем зум страницы
2.Кликаем в контрол +
3.Проверяем что зум стал на единицу больше
"""
self.driver.get(url)
self.page.map.wait_init()
zoom_start = self.page.console(GetScripts.getZoom)
self.page.zoom_control_in.zoom_in_click()
zoom_end = self.page.console(GetScripts.getZoom)
self.assertEqual(zoom_end - zoom_start, 1)
@dataprovider([
config.aut['local'] + u'/base.html'
])
def zoomOut_click_test(self, url):
"""
:param url: Адрес страницы
Проерка контрола зума -.
1.Получаем зум страницы
2.Кликаем в контрол -
3.Проверяем что зум стал на единицу меньше
"""
self.driver.get(url)
self.page.map.wait_init()
zoom_start = self.page.console(GetScripts.getZoom)
self.page.zoom_control_out.zoom_out_click()
zoom_end = self.page.console(GetScripts.getZoom)
self.assertEqual(zoom_end - zoom_start, -1)
@dataprovider([
config.aut['local'] + u'/base.html'
])
def zoomIn_dbclick_test(self, url):
"""
:param url: Адрес страницы
Проверка зума даблкликом.
1.Получаем зум страницы
2.Кликаем в контрол -
3.Проверяем что зум стал на единицу меньше
"""
self.driver.get(url)
self.page.map.wait_init()
zoom_start = self.page.console(GetScripts.getZoom)
self.page.map.center_dbclick()
zoom_end = self.page.console(GetScripts.getZoom)
self.assertEqual(zoom_end - zoom_start, 1)
@dataprovider([
config.aut['local'] + u'/base.html'
])
def zoomIn_shift_select_test(self, url):
"""
:param url: Адрес страницы
Проверка зума селектом с shift.
1.Получаем зум страницы
2.Выделяем облость с зажатым shift и отпускаем
3.Проверяем изменение зума
"""
self.driver.get(url)
self.page.map.wait_init()
zoom_start = self.page.console(GetScripts.getZoom)
self.page.map.zoom_selection()
zoom_end = self.page.console(GetScripts.getZoom)
self.assertEqual(zoom_end - zoom_start, 1)
================================================
FILE: gulp/deps/build.html
================================================
Maps API 2.0 Build Helper
================================================
FILE: gulp/deps/deps.js
================================================
var deps = {
DGCore: {
desc: 'Main module',
src: [
'../vendors/polyfills/es5.js',
'../vendors/polyfills/promise.js',
'DGCore/src/DGCore.js',
'DGCore/src/DGthen.js',
'DGCore/src/DGplugin.js'
],
less: {
all: [
'../node_modules/leaflet/dist/leaflet.css',
'DGCore/skin/basic/less/dg-core.less'
]
},
heading: '2GIS modules'
},
DGAjax: {
desc: '2GIS Ajax module',
src: ['DGAjax/src/DGAjax.js'],
deps: ['DGCore']
},
DGLabel: {
desc: '2GIS Label module',
src: [
'DGLabel/src/DGLabel.js',
'DGLabel/src/Marker.DGLabel.js',
'DGLabel/src/Path.DGLabel.js',
'DGLabel/src/Entrance.DGLabel.js'
],
less: {
all: ['DGLabel/skin/{skin}/less/dg-label.less']
},
deps: ['DGCore', 'DGEntrance']
},
DGWkt: {
desc: 'WKT parser module',
src: [
'DGWkt/DGWkt.js'
],
deps: ['DGCore']
},
DGPopup: {
desc: '2GIS Popup module',
src: [
'DGPopup/skin/basic/skin.config.js',
'DGPopup/src/DGPopup.js'
],
less: {
all: [
'DGPopup/skin/{skin}/less/leaflet.less',
'../vendors/baron/baron.css',
'DGPopup/skin/{skin}/less/scroller.less',
'DGPopup/skin/{skin}/less/dg-popup.less'
],
ie: [
'DGPopup/skin/{skin}/less/leaflet.ie.less',
'DGPopup/skin/{skin}/less/dg-popup.ie.less'
]
},
deps: ['DGCore']
},
DGCustomization: {
desc: 'LeafLet customization module',
src: [
'DGCustomization/skin/basic/skin.config.js',
'DGCustomization/src/DGCustomization.js',
'DGCustomization/src/DGMap.js',
'DGCustomization/src/DGMap.BaseLayer.js',
'DGCustomization/src/DGMap.ApiKeyValidator.js',
'DGCustomization/src/DGMap.TilesCheck.js',
'DGCustomization/src/DGMap.Drag.js',
'DGCustomization/src/DGPolyUtil.js',
'DGCustomization/src/DGMobileImprove.js'
],
less: {
all: [
'DGCustomization/skin/{skin}/less/leaflet.less',
'../vendors/baron/baron.css',
'DGCustomization/skin/{skin}/less/scroller.less',
'DGCustomization/skin/{skin}/less/dg-customization.less'
],
ie: [
'DGCustomization/skin/{skin}/less/leaflet.ie.less',
'DGCustomization/skin/{skin}/less/dg-customization.ie.less'
]
},
deps: ['DGCore', 'DGLocale', 'DGRoundControl', 'DGProjectDetector', 'DGMuseum']
},
DGZoomControl: {
desc: '2GIS zoom control module',
src: [
'DGZoomControl/src/DGZoomControl.js',
'DGZoomControl/lang/ru.js',
'DGZoomControl/lang/it.js',
'DGZoomControl/lang/cs.js',
'DGZoomControl/lang/en.js',
'DGZoomControl/lang/es.js',
'DGZoomControl/lang/ar.js'
],
less: {
all: [
'DGZoomControl/skin/{skin}/less/dg-zoom-control.less'
]
},
deps: ['DGCore', 'DGLocale', 'DGRoundControl']
},
DGAttribution: {
desc: '2GIS copyright',
src: [
'DGAttribution/src/DGAttribution.js',
'DGAttribution/lang/ru.js',
'DGAttribution/lang/it.js',
'DGAttribution/lang/cs.js',
'DGAttribution/lang/en.js',
'DGAttribution/lang/es.js',
'DGAttribution/lang/ar.js'
],
less: {
all: [
'DGAttribution/skin/{skin}/less/dg-mapcopyright.less'
]
},
deps: ['DGCore', 'DGDust', 'DGLocale']
},
DGLocale: {
desc: 'Localization module',
src: [
'DGLocale/src/DGDictionary.js',
'DGLocale/src/DGLocale.js'
],
deps: ['DGCore', 'DGProjectDetector']
},
DGLocation: {
desc: 'Location control module',
src: [
'DGLocation/src/DGLocation.js',
'DGLocation/lang/ru.js',
'DGLocation/lang/it.js',
'DGLocation/lang/cs.js',
'DGLocation/lang/en.js',
'DGLocation/lang/es.js',
'DGLocation/lang/ar.js'
],
less: {
all: [
'DGLocation/skin/{skin}/less/dg-location.less',
'DGLocation/skin/{skin}/less/dg-control-round.less'
]
},
deps: ['DGCore', 'DGLocale', 'DGLabel', 'DGRoundControl']
},
DGFullScreen: {
desc: 'Full screen module',
src: [
'DGFullScreen/src/DGScreenfull.js',
'DGFullScreen/src/DGFullScreen.js',
'DGFullScreen/lang/ru.js',
'DGFullScreen/lang/it.js',
'DGFullScreen/lang/cs.js',
'DGFullScreen/lang/en.js',
'DGFullScreen/lang/es.js',
'DGFullScreen/lang/ar.js'
],
less: {
all: [
'DGFullScreen/skin/{skin}/less/dg-fullscreen.less',
'DGFullScreen/skin/{skin}/less/dg-control-round.less'
],
ie: ['DGFullScreen/skin/{skin}/less/dg-fullscreen.ie.less']
},
deps: ['DGCore', 'DGLocale', 'DGRoundControl']
},
DGProjectDetector: {
desc: '2GIS project detector module',
src: ['DGProjectDetector/src/DGProjectDetector.js'],
deps: ['DGCore', 'DGWkt']
},
DGMeta: {
desc: '2GIS additional metalayers support',
src: [
'DGMeta/src/DGMeta.Layer.js',
'DGMeta/src/DGMeta.Origin.js'
],
deps: ['DGAjax', 'DGCore', 'DGCustomization', 'DGWkt', 'DGProjectDetector']
},
DGPoi: {
desc: '2GIS POI module',
src: ['DGPoi/src/DGPoi.js'],
deps: ['DGMeta', 'DGLabel']
},
DGGeoclicker: {
desc: '2GIS Geoclicker',
less: {
all: [
'DGGeoclicker/skin/{skin}/less/dg-building-callout.less',
'DGGeoclicker/skin/{skin}/less/dg-map-geoclicker.less',
'DGGeoclicker/skin/{skin}/less/dg-preloader.less',
'DGGeoclicker/skin/{skin}/less/dg-popup.less',
'DGGeoclicker/skin/{skin}/less/dg-firm-card.less',
'DGGeoclicker/skin/{skin}/less/dg-schedule.less',
'DGGeoclicker/skin/{skin}/less/dg-link.less'
],
ie: [
'DGGeoclicker/skin/{skin}/less/dg-popup.ie.less',
'DGGeoclicker/skin/{skin}/less/dg-schedule.ie.less'
]
},
src: [
'DGGeoclicker/src/DGGeoclicker.js',
'DGGeoclicker/src/ClampHelper.js',
'DGGeoclicker/src/provider/Provider.js',
'DGGeoclicker/src/provider/CatalogApi.js',
'DGGeoclicker/src/handler/Handler.js',
'DGGeoclicker/src/handler/Default.js',
'DGGeoclicker/src/handler/ApiError.js',
'DGGeoclicker/src/handler/CityArea.js',
'DGGeoclicker/src/handler/House.js',
'DGGeoclicker/src/handler/House.View.js',
'DGGeoclicker/src/handler/POI.js',
'DGGeoclicker/src/handler/Sight.js',
'DGGeoclicker/src/View.js',
'DGGeoclicker/src/Controller.js',
'DGGeoclicker/lang/it.js',
'DGGeoclicker/lang/ru.js',
'DGGeoclicker/lang/en.js',
'DGGeoclicker/lang/cs.js',
'DGGeoclicker/lang/es.js',
'../vendors/firmcard/src/FirmCard.js',
'../vendors/firmcard/src/FirmCard.DataHelper.js',
'../vendors/firmcard/src/FirmList.js',
'../vendors/firmcard/src/Schedule.js',
'../vendors/firmcard/src/Dictionary.js'
],
deps: ['DGAjax', 'DGCore', 'DGDust', 'DGLocale', 'DGPoi', 'DGEntrance', 'DGProjectDetector', 'DGPopup']
},
DGDust: {
desc: '2GIS Template',
src: [
'DGDust/src/DGDust.js'
],
deps: ['DGCore']
},
DGEntrance: {
desc: '2GIS Entrances',
src: [
'DGEntrance/src/DGMetric.js',
'DGEntrance/src/DGVertexTransform.js',
'DGEntrance/src/DGArrowPathTransform.js',
'DGEntrance/src/DGArrowTipTransform.js',
'DGEntrance/src/DGComplexPath.js',
'DGEntrance/src/DGRenderer.js',
'DGEntrance/src/DGBezierCurves.js',
'DGEntrance/src/DGAnimation.js',
'DGEntrance/src/DGEntrance.js',
'DGEntrance/src/DGEntranceArrow.js',
'DGEntrance/src/DGEntranceArrowShape.js'
],
deps: ['DGCore', 'DGWkt', 'DGProjectDetector']
},
DGRoundControl: {
desc: 'Control helper',
src: ['DGRoundControl/src/DGRoundControl.js'],
less: {
all: ['DGRoundControl/skin/{skin}/less/dg-control-round.less']
},
deps: ['DGCore', 'DGLocale']
},
DGTraffic: {
desc: 'Traffic',
src: [
'DGTraffic/src/DGTraffic.js',
'DGTraffic/lang/ru.js',
'DGTraffic/lang/it.js',
'DGTraffic/lang/cs.js',
'DGTraffic/lang/es.js',
'DGTraffic/lang/en.js',
'DGTraffic/lang/ar.js'
],
deps: ['DGMeta', 'DGLabel', 'DGLocale']
},
DGTrafficControl: {
desc: 'Traffic control module',
src: [
'DGTrafficControl/src/Control.Traffic.js',
'DGTrafficControl/lang/ru.js',
'DGTrafficControl/lang/it.js',
'DGTrafficControl/lang/cs.js',
'DGTrafficControl/lang/es.js',
'DGTrafficControl/lang/en.js',
'DGTrafficControl/lang/ar.js'
],
less: {
all: [
'DGTrafficControl/skin/{skin}/less/dg-control-round.less',
'DGTrafficControl/skin/{skin}/less/dg-traffic-control.less'
],
ie: ['DGTrafficControl/skin/{skin}/less/dg-traffic-control.ie.less']
},
deps: ['DGTraffic', 'DGRoundControl']
},
DGRuler: {
desc: 'Ruler module',
src: [
'DGRuler/src/Ruler.js',
'DGRuler/src/LayeredMarker.js',
'DGRuler/src/GeometryStyles.js',
'DGRuler/lang/ru.js',
'DGRuler/lang/it.js',
'DGRuler/lang/cs.js',
'DGRuler/lang/es.js',
'DGRuler/lang/en.js',
'DGRuler/lang/ar.js'
],
less: {
all: ['DGRuler/skin/{skin}/less/dg-ruler.less'],
ie: ['DGRuler/skin/{skin}/less/dg-ruler.ie.less']
},
deps: ['DGCore', 'DGLocale']
},
DGRulerControl: {
desc: 'Ruler control module',
src: [
'DGRulerControl/src/Control.Ruler.js',
'DGRulerControl/lang/ru.js',
'DGRulerControl/lang/it.js',
'DGRulerControl/lang/cs.js',
'DGRulerControl/lang/es.js',
'DGRulerControl/lang/en.js',
'DGRulerControl/lang/ar.js'
],
less: {
all: ['DGRulerControl/skin/{skin}/less/dg-control-round.less']
},
deps: ['DGRuler', 'DGRoundControl']
},
DGMuseum: {
desc: 'Museum module',
src: [
'DGMuseum/src/DGMuseum.js'
],
less: {
all: ['DGMuseum/skin/{skin}/less/dg-museum.less']
}
}
};
if (typeof module !== 'undefined' && module.exports) {
module.exports = deps;
}
================================================
FILE: gulp/deps/index.js
================================================
var fs = require('fs');
var glob = require('glob');
var path = require('path');
var imageSize = require('image-size');
var init = function(config) {
var packages = config.packages;
// Generates a list of modules by pkg
function getModulesList(pkg, modules, isLeaflet) { //(String|Null)->Array
modules = modules || config.source.deps;
var modulesListOrig = [];
var modulesListRes = [];
var loadedModules = {};
if (typeof pkg === 'boolean') {
throw new Error('pkg param can\'t be empty');
}
// Package name with no empty modules list on packs.js (example: 'base')
if (pkg && pkg in packages && packages[pkg].modules.length > 0) {
modulesListOrig = packages[pkg].modules;
// Modules list (example: 'Core,JSONP,TileLayer')
} else if (pkg && pkg.indexOf(',') !== -1) {
modulesListOrig = pkg.split(',');
// Modules single (example: 'Core')
} else if (pkg && pkg in modules) {
modulesListOrig.push(pkg);
// Others (null / full package)
} else {
modulesListOrig = modulesListOrig.concat(Object.keys(modules));
}
if (!isLeaflet) {
modulesListOrig = modulesListOrig.concat(config.coreModules);
}
function processModule(name) {
var module = modules[name];
if (module && module.deps) {
module.deps.forEach(processModule);
}
if (!loadedModules[name]) {
modulesListRes.push(name);
loadedModules[name] = true;
}
}
modulesListOrig.forEach(processModule);
return modulesListRes;
}
function getJSFiles(options) {
options = options || {};
var source = config[options.source || 'source'];
var modules = source.deps;
var sourcePath = source.path;
var isLeaflet = options.source === 'leaflet';
return getModulesList(options.pkg, modules, isLeaflet)
.map(function(name) {
return modules[name];
})
.map(function(module) {
return module.src;
})
.reduce(function(array, items) {
return array.concat(items);
})
.filter(function(item, index, list) { //filter dublicates
return list.indexOf(item) == index;
})
.map(function(file) {
return sourcePath + file;
});
}
function getCSSFiles(options) {
options = options || {};
var source = config[options.source || 'source'];
var modules = source.deps;
var sourcePath = source.path;
var skin = options.skin || config.appConfig.defaultSkin;
return getModulesList(options.pkg, modules)
.map(function(name) {
return modules[name];
})
.map(function(module) {
return module[options.type || 'less'];
})
.filter(Boolean)
.reduce(function(array, item) {
var items = [];
if (!options.excludeBaseCss && item.all) {
items.push(item.all);
}
if (options.ie8 && item.ie) {
items.push(item.ie);
}
return array.concat(items);
}, [])
.reduce(function(array, items) {
return array.concat(items);
}, [])
.reduce(function(array, item) { // if css have skin, we add basic theme
if (item.indexOf('{skin}') !== -1) {
array.push(item.replace('{skin}', 'basic'));
}
return array.concat(item);
}, [])
.map(function(file) { // add selected theme
return file.replace('{skin}', skin);
})
.map(function(file) {
return sourcePath + file;
})
.filter(fs.existsSync);
}
function getImgGlob(options) {
options = options || {};
var source = config[options.source || 'source'];
var modules = source.deps;
return getModulesList(options.pkg, modules)
.map(function(name) {
return 'src/' + name + '/**/img/**/*.{png,gif,jpg,jpeg,svg}';
});
}
// Build string with Less variables and imports
function lessHeader(options) {
options = options || {};
var header = '';
if (options.variables) {
Object.keys(options.variables).forEach(function(varableName) {
header = header + '\n' + '@' + varableName + ': ' + options.variables[varableName] + ';';
});
}
var importsBase = '';
if (typeof options.importsBase === 'string' && options.importsBase.length) {
importsBase = options.importsBase.replace(/\/*$/, '/');
}
if (options.imports) {
for (var i = 0, type = '', imoportPath = ''; i < options.imports.length; i++) {
type = options.imports[i].replace(/^.*\:/, '');
imoportPath = options.imports[i].replace(/\:.*$/, '');
header = header + '\n' + '@import (' + type + ') \'' + importsBase + imoportPath + '\';';
}
}
return header;
}
// Scans the project for skins directories to get skins names
function getSkinsList() {
var skinsDirectories = glob.sync(__dirname + '/../../src/**/skin/*');
var skins = [];
skinsDirectories.forEach(function(directory) {
var skinName = path.basename(directory);
if (skins.indexOf(skinName) === -1) {
skins.push(skinName);
}
});
return skins;
}
// Gets images per skin formats statistics
function getImagesFilesStats(skins) {
skins = skins || getSkinsList();
var perSkinStats = {};
var imgModulesGlobs = getImgGlob();
imgModulesGlobs.forEach(function(imgGlob) {
glob.sync(imgGlob).forEach(function(imagePath) {
var skinName = imagePath.split('/')[3];
var extname = path.extname(imagePath);
var name = path.basename(imagePath, extname);
var imageDimensions;
if (skins.indexOf(skinName) === -1) {
return; // continue
}
if (!(skinName in perSkinStats)) {
perSkinStats[skinName] = {};
}
if (!(name in perSkinStats[skinName])) {
perSkinStats[skinName][name] = {};
}
if (extname === '.svg') {
perSkinStats[skinName][name].hasVectorVersion = true;
} else {
perSkinStats[skinName][name].extension = extname.replace('.', '');
imageDimensions = imageSize(imagePath);
perSkinStats[skinName][name].width = imageDimensions.width;
perSkinStats[skinName][name].height = imageDimensions.height;
}
});
});
return perSkinStats;
}
// Analyzes Less, gets images usage statistics per skin
function getImagesUsageStats(skins) {
skins = skins || getSkinsList();
var perSkinStats = {};
skins.forEach(function(skinName) {
var stats = {};
var statsFilePath = __dirname + '/../tmp/less/images-usage-statistics.' + skinName + '.less';
var statsFileContent = fs.readFileSync(statsFilePath).toString();
var preparedStatsFileContent = statsFileContent.slice(6).replace(/\;/g, ','); // 6 is 'stats '.length
var rawStats = Function('return ' + preparedStatsFileContent + ';')();
stats.repeatable = rawStats.repeatable.split(',');
stats.notRepeatableSprited = rawStats.notRepeatableSprited.split(',');
stats.notRepeatableNotSprited = rawStats.notRepeatableNotSprited.split(',');
// Repeatable images can be used as no-repeatable images,
// so we should exclude repeatable images from no-repeatable images list
stats.notRepeatableSprited = rawStats.notRepeatableSprited.split(',').filter(function(name) {
return stats.repeatable.indexOf(name) === -1;
});
perSkinStats[skinName] = stats;
});
return perSkinStats;
}
return {
getModulesList: getModulesList,
getJSFiles: getJSFiles,
getCSSFiles: getCSSFiles,
lessHeader: lessHeader,
getSkinsList: getSkinsList,
getImagesFilesStats: getImagesFilesStats,
getImagesUsageStats: getImagesUsageStats,
getImgGlob: getImgGlob
};
};
if (typeof module !== 'undefined' && module.exports) {
module.exports = init;
}
================================================
FILE: gulp/deps/packs.js
================================================
var packages = {
basic: {
name: 'Basic package',
desc: 'Provides basic functionality: map, markers, popups, geometries',
modules: ['DGCustomization', 'DGFullScreen', 'DGAttribution', 'DGAjax', 'DGPopup', 'DGZoomControl']
},
full: {
name: 'Full package',
desc: 'Complete package. Includes all the features of 2GIS Maps API',
modules: []
}
};
if (typeof module !== 'undefined' && module.exports) {
module.exports = packages;
}
================================================
FILE: gulp/sprite-template.mustache
================================================
{{#items}}
.spriteData('{{name}}') {
@backgroundImage: '{{{escaped_image}}}';
@backgroundPosition: {{px.offset_x}} {{px.offset_y}};
@backgroundPositionLeft: {{px.offset_x}};
@backgroundPositionTop: {{px.offset_y}};
@width: {{px.width}};
@height: {{px.height}};
@totalWidth: {{px.total_width}};
@totalHeight: {{px.total_height}};
}
.isSprited(@name) when (@name = '{{name}}') {
@isSprited: true;
}
{{/items}}
================================================
FILE: gulp/tasks/build.js
================================================
var { buildEnd } = require('../util/buildEnd.js');
var config = require('../../app/config.js');
var argv = require('minimist')(process.argv.slice(2));
var gulp = require('gulp');
var { clean } = require('./clean');
var { buildStyles } = require('./buildStyles');
var { buildScripts } = require('./buildScripts');
var { doc } = require('./doc');
var { loader } = require('./loader');
var { copyAssets } = require('./copyAssets');
var { copyIndexPage } = require('./copyIndexPage');
function npmConfigModify(done) {
if (argv.npm) {
// Disable local config for npm builds
config.appConfig = config.mainConfig;
// Make npm builds https-only
config.appConfig.protocol = 'https:';
}
done();
}
exports.build = gulp.series(npmConfigModify, clean, buildStyles, gulp.parallel(
buildScripts,
doc,
loader,
copyAssets,
copyIndexPage
), buildEnd);
================================================
FILE: gulp/tasks/buildLeaflet.js
================================================
var concat = require('gulp-concat');
var gulp = require('gulp');
var log = require('fancy-log');
var argv = require('minimist')(process.argv.slice(2));
var path = require('path');
var config = require('../../app/config.js');
var deps = require('../deps')(config);
function getLeafletFiles(compsBase32) {
var memo = {},
deps = require('leaflet/build/deps.js').deps,
comps;
if (compsBase32) {
comps = parseInt(compsBase32, 32).toString(2).split('');
log('Managing dependencies...');
}
function addFiles(srcs) {
for (var j = 0, len = srcs.length; j < len; j++) {
memo[srcs[j]] = true;
}
}
for (var i in deps) {
if (comps) {
if (parseInt(comps.pop(), 2) === 1) {
log(' * ' + i);
addFiles(deps[i].src);
} else {
log(' ' + i);
}
} else {
addFiles(deps[i].src);
}
}
log('\n');
var files = [];
for (var src in memo) {
files.push('src/' + src);
}
return files;
}
// leaflet-custom-build parameter for set id of leaflet build. See more in leaflet/build/build.html
exports.buildLeaflet = function buildLeaflet() {
var leafletCustomBuild = argv['leaflet-custom-build'];
return (leafletCustomBuild ? gulp.src(getLeafletFiles(leafletCustomBuild).map(function (file) {
return path.resolve(path.join(__dirname, '../../node_modules/leaflet/', file))
})) : gulp.src(deps.getJSFiles({source: 'leaflet'})))
.pipe(concat('leaflet-src.js'))
.pipe(gulp.dest('node_modules/leaflet/dist/'));
};
================================================
FILE: gulp/tasks/buildScripts.js
================================================
var config = require('../../app/config.js');
var stat = require('../util/stat');
var source = require('vinyl-source-stream');
var derequire = require('gulp-derequire');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var header = require('gulp-header');
var mergeStream = require('merge-stream');
var gulpif = require('gulp-if');
var argv = require('minimist')(process.argv.slice(2));
var gulp = require('gulp');
var path = require('path');
var map = require('map-stream');
var insert = require('gulp-insert');
var sourcemaps = require('gulp-sourcemaps');
var { concatScripts } = require('./concatScripts');
function buildScripts() {
var isCustom = argv.pkg || argv.skin;
var packages;
if (global.isTestBuild) {
packages = ['full'];
} else if (isCustom) {
packages = [argv.pkg || 'full'];
} else {
packages = Object.keys(config.packages);
}
return mergeStream(packages.map(function(pkg) {
var name = 'script.' + (!isCustom ? pkg + '.' : '') + 'js';
var src = path.join('gulp', 'tmp', 'js', name);
var bundler = browserify(src, {
debug: !argv.release,
entry: true,
standalone: argv.npm ? 'DG': false,
cache: {},
packageCache: {},
sourceMaps: argv.release
});
bundler.transform('browserify-css', {
autoInject: true,
minify: true
});
return bundler.bundle()
.pipe(source(name))
.pipe(buffer())
.pipe(derequire())
.pipe(gulpif(argv.release, sourcemaps.init()))
.pipe(gulpif(argv.release, uglify()))
.pipe(gulpif(argv.release, header(config.copyright)))
.pipe(gulpif(
Boolean(argv['leaflet-custom-build']),
insert.prepend('// leaflet-custom-build: ' + argv['leaflet-custom-build'] + '\n')
))
.pipe(gulpif(argv.release, sourcemaps.write('./')))
.pipe(map(stat.save))
.pipe(gulp.dest('dist/js/'));
}));
}
exports.buildScripts = gulp.series(concatScripts, buildScripts);
================================================
FILE: gulp/tasks/buildStyles.js
================================================
var gulp = require('gulp');
var { destCSS } = require('../util/destCSS');
var { collectImagesStats } = require('./collectImagesStats');
var { generateSprites } = require('./generateSprites');
var { imageMinify } = require('./imageMinify');
exports.buildStyles = gulp.series(gulp.parallel(
collectImagesStats,
generateSprites,
imageMinify
), destCSS);
================================================
FILE: gulp/tasks/buildTest.js
================================================
var gulp = require('gulp');
var { buildEnd } = require('../util/buildEnd.js');
var { buildStyles } = require('./buildStyles');
var { buildScripts } = require('./buildScripts');
var { doc } = require('./doc');
var { clean } = require('./clean');
var { loader } = require('./loader');
var { copyAssets } = require('./copyAssets');
var { copyIndexPage } = require('./copyIndexPage');
function enableTestBuild(done) {
global.isTestBuild = true;
done();
}
exports.buildTest = gulp.series(enableTestBuild, clean, gulp.parallel(
buildScripts,
buildStyles,
doc,
loader,
copyAssets,
copyIndexPage
), buildEnd);
================================================
FILE: gulp/tasks/clean.js
================================================
var del = require('del');
exports.clean = function clean() {
return del(['dist', 'gulp/tmp']);
};
================================================
FILE: gulp/tasks/collectImagesStats.js
================================================
var gulp = require('gulp');
var fs = require('fs');
var mkdirp = require('mkdirp');
var config = require('../../app/config');
var deps = require('../deps')(config);
var { copyImg } = require('./copyImg');
function collectImagesStats(cb) {
var skins = deps.getSkinsList();
var imagesStatsPerSkin = deps.getImagesFilesStats(skins);
mkdirp.sync('./gulp/tmp');
mkdirp.sync('./gulp/tmp/less');
skins.forEach(function(skinName) {
var skinImagesFilesStats = imagesStatsPerSkin[skinName];
var statisticsObject;
var statisticsString = '';
var imageExtension;
var originalImageName;
var originalImageStatisticObject;
for (var imageName in skinImagesFilesStats) {
originalImageName = imageName.replace(/@\d+(\.\d+)?x/, '');
statisticsObject = skinImagesFilesStats[imageName];
originalImageStatisticObject = skinImagesFilesStats[originalImageName];
imageExtension = (typeof statisticsObject.extension === 'undefined') ? 'svg' : statisticsObject.extension;
statisticsString += '.imageData(\'' + imageName + '\') { ' +
'@filename: \'' + imageName + '\'; ' +
'@extension: \'' + imageExtension + '\'; ' +
'@hasVectorVersion: ' + !!statisticsObject.hasVectorVersion + '; ' +
'@width: ' + statisticsObject.width + 'px; ' +
'@height: ' + statisticsObject.height + 'px; ' +
'@originalWidth: ' + originalImageStatisticObject.width + 'px; ' +
'@originalHeight: ' + originalImageStatisticObject.height + 'px; ' +
'}\n';
}
fs.writeFileSync('./gulp/tmp/less/images-files-statistics.' + skinName + '.less', statisticsString);
});
cb();
}
exports.collectImagesStats = gulp.series(copyImg, collectImagesStats);
================================================
FILE: gulp/tasks/collectImagesUsageStats.js
================================================
var header = require('gulp-header');
var rename = require('gulp-rename');
var mergeStream = require('merge-stream');
var less = require('gulp-less');
var gulp = require('gulp');
var path = require('path');
var glob = require('glob');
var error = require('../util/error');
var config = require('../../app/config');
var deps = require('../deps')(config);
exports.collectImagesUsageStats = function collectImagesUsageStats() {
var skins = deps.getSkinsList();
var imagesBasePath = path.resolve(__dirname + '/../../dist/img');
var statisticsStreams = skins.map(function(skinName) {
var skinLessFiles = glob.sync('./src/**/' + skinName + '/less/*.less');
skinLessFiles.unshift('./src/less/mixins.images-usage-statistics.less');
skinLessFiles.unshift('./src/less/mixins.ie8.less');
skinLessFiles = skinLessFiles.map(function(lessFilePath) {
return lessFilePath + ':reference';
});
return gulp.src('src/less/images-usage-statistics.less')
.pipe(error.handle())
.pipe(header(deps.lessHeader({
variables: {
baseURL: '\'__BASE_URL__\'',
spritesURL: '\'__BASE_URL__\'',
ie8: true,
useSprites: true,
mobile: false,
retina: false,
skinName: skinName,
imagesBasePath: '\'' + imagesBasePath + '\''
},
imports: skinLessFiles
})))
.pipe(less())
.pipe(rename('images-usage-statistics.' + skinName + '.less'))
.pipe(gulp.dest('gulp/tmp/less/'));
});
return mergeStream(statisticsStreams);
};
================================================
FILE: gulp/tasks/concatScripts.js
================================================
var sourcemaps = require('gulp-sourcemaps');
var streamqueue = require('streamqueue');
var concat = require('gulp-concat');
var footer = require('gulp-footer');
var mergeStream = require('merge-stream');
var gulpif = require('gulp-if');
var argv = require('minimist')(process.argv.slice(2));
var gulp = require('gulp');
var config = require('../../app/config.js');
var deps = require('../deps')(config);
var templateStream = require('../util/templateStream');
var projectList = require('../util/projectList');
var error = require('../util/error');
var { loadProjectList } = require('./loadProjectList');
var { buildLeaflet } = require('./buildLeaflet');
function getStyleRequireStatement(pack, skin) {
return 'require("../../../dist/css/styles.' + pack + '.' + skin + '.css");';
}
function concatScripts() {
var isCustom = argv.pkg || argv.skin;
var packages;
if (global.isTestBuild) {
packages = ['full'];
} else if (isCustom) {
packages = [argv.pkg || 'full'];
} else {
packages = Object.keys(config.packages);
}
if (global.isTestBuild) {
// Disable tile loading in test build
config.appConfig.tileServer = '';
}
return mergeStream(packages.map(function(pkg) {
var stream = streamqueue(
{objectMode: true},
gulp.src(deps.getJSFiles({pkg: pkg}), {base: '.'}),
templateStream(pkg)
)
.pipe(error.handle())
.pipe(gulpif(!argv.release, sourcemaps.init()))
.pipe(concat('script.' + (!isCustom ? pkg + '.' : '') + 'js'))
.pipe(footer(projectList.get()))
.pipe(footer('DG.config = ' + JSON.stringify(config.appConfig) + ';'));
if (argv.npm) {
stream = stream.pipe(footer(getStyleRequireStatement(pkg, 'dark')));
}
return stream
.pipe(gulpif(!argv.release, sourcemaps.write()))
.pipe(gulp.dest('gulp/tmp/js'));
}));
}
const projectListTask = argv['project-list'] !== false ? [loadProjectList] : [];
exports.concatScripts = gulp.series(gulp.parallel(
...projectListTask,
buildLeaflet
), concatScripts);
================================================
FILE: gulp/tasks/copyAssets.js
================================================
var gulp = require('gulp');
var error = require('../util/error');
exports.copyAssets = function copyAssets() {
return gulp.src(['assets/**/*'])
.pipe(error.handle())
.pipe(gulp.dest('dist'));
};
================================================
FILE: gulp/tasks/copyImg.js
================================================
var rename = require('gulp-rename');
var argv = require('minimist')(process.argv.slice(2));
var gulp = require('gulp');
var error = require('../util/error');
var config = require('../../app/config');
var deps = require('../deps')(config);
exports.copyImg = function copyImg() {
return gulp.src(deps.getImgGlob(argv))
.pipe(error.handle())
.pipe(rename(function(p) {
p.dirname = '';
}))
.pipe(gulp.dest('dist/img'));
};
================================================
FILE: gulp/tasks/copyIndexPage.js
================================================
var gulp = require('gulp');
var error = require('../util/error');
exports.copyIndexPage = function copyIndexPage() {
return gulp.src(['app/index.html'])
.pipe(error.handle())
.pipe(gulp.dest('dist'));
};
================================================
FILE: gulp/tasks/dev.js
================================================
var gulp = require('gulp');
var { build } = require('./build');
var { server } = require('./server');
var { watch } = require('./watch');
exports.dev = gulp.series(build, server, watch);
================================================
FILE: gulp/tasks/doc.js
================================================
var gendoc = require('../util/gendoc');
var config = require('../../app/config');
exports.doc = function doc(done) {
var doc = config.doc;
gendoc.generateDocumentation(doc.menu, doc.input, doc.output);
done();
};
================================================
FILE: gulp/tasks/generateSprites.js
================================================
var spritesmith = require('gulp.spritesmith');
var mergeStream = require('merge-stream');
var gulp = require('gulp');
var error = require('../util/error');
var config = require('../../app/config');
var deps = require('../deps')(config);
var { collectImagesUsageStats } = require('./collectImagesUsageStats');
function generateSprites() {
var skins = deps.getSkinsList();
var stats = deps.getImagesUsageStats(skins);
var statisticsStreams = skins.map(function(skinName) {
// Adds comma to make glob’s {} working properly,
// even there is only one should be excluded
var filesToExclude = stats[skinName].repeatable.join(',') + ',' +
stats[skinName].notRepeatableNotSprited.join(',');
var pngList = [
'src/**/' + skinName + '/img/**/*.png',
'!src/**/' + skinName + '/img/**/*@2x.png',
'!src/**/' + skinName + '/img/**/{' + filesToExclude + '}.png'
];
var png2xList = [
'src/**/' + skinName + '/img/**/*@2x.png',
'!src/**/' + skinName + '/img/**/{' + filesToExclude + '}@2x.png'
];
var spriteData = gulp.src(pngList)
.pipe(error.handle())
.pipe(spritesmith({
cssTemplate: 'gulp/sprite-template.mustache',
imgName: 'sprite.' + skinName + '.png',
cssName: 'sprite.' + skinName + '.less',
engine: 'pixelsmith'
}));
var spriteData2x = gulp.src(png2xList)
.pipe(error.handle())
.pipe(spritesmith({
cssTemplate: 'gulp/sprite-template.mustache',
//padding: 1, // генерирует неправильные смещения :(
imgName: 'sprite@2x.' + skinName + '.png',
cssName: 'sprite@2x.' + skinName + '.less',
engine: 'pixelsmith'
}));
return mergeStream(
spriteData.img
.pipe(gulp.dest('dist/img/')),
spriteData2x.img
.pipe(gulp.dest('dist/img/')),
spriteData.css
.pipe(gulp.dest('gulp/tmp/less/')),
spriteData2x.css
.pipe(gulp.dest('gulp/tmp/less/'))
);
});
return mergeStream(statisticsStreams);
}
exports.generateSprites = gulp.series(collectImagesUsageStats, generateSprites);
================================================
FILE: gulp/tasks/imageMinify.js
================================================
var imagemin = require('gulp-imagemin');
var argv = require('minimist')(process.argv.slice(2));
var gulpif = require('gulp-if');
var gulp = require('gulp');
var { copyAssets } = require('./copyAssets');
var { copyImg } = require('./copyImg');
var { generateSprites } = require('./generateSprites');
function imageMinify() {
return gulp.src('dist/img/**/*.{png,gif,jpg,jpeg}')
.pipe(gulpif(argv.release, imagemin()))
.pipe(gulp.dest('dist/img'));
}
exports.imageMinify = gulp.series(
gulp.parallel(
copyAssets,
copyImg,
generateSprites
),
imageMinify,
);
================================================
FILE: gulp/tasks/lint.js
================================================
var gulp = require('gulp');
var { lintJS } = require('./lintJS');
var { lintCSS } = require('./lintCSS');
exports.lint = gulp.parallel(lintJS, lintCSS);
================================================
FILE: gulp/tasks/lintCSS.js
================================================
var gulp = require('gulp');
var csslint = require('../util/csslint/gulp-csslint');
var error = require('../util/error');
var {buildStyles} = require('./buildStyles');
function lintCSS() {
return gulp.src('dist/css/**.css')
.pipe(error.handle())
.pipe(csslint({
'adjoining-classes': false,
'box-model': false,
'box-sizing': false,
'compatible-vendor-prefixes': false,
'empty-rules': false,
'display-property-grouping': false,
'duplicate-background-images': false,
'fallback-colors': false,
'font-sizes': false,
'gradients': false,
'important': false,
'overqualified-elements': false,
'outline-none': false,
'regex-selectors': false,
'vendor-prefix': false,
'unqualified-attributes': false,
'zero-units': false
}))
.pipe(csslint.reporter());
}
exports.lintCSS = gulp.series(buildStyles, lintCSS);
================================================
FILE: gulp/tasks/lintJS.js
================================================
var eslint = require('gulp-eslint');
var gulp = require('gulp');
var error = require('../util/error');
exports.lintJS = function lintJS() {
return gulp.src('src/**/src/**/*.js')
.pipe(error.handle())
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
};
================================================
FILE: gulp/tasks/loadProjectList.js
================================================
var request = require('request');
var PluginError = require('plugin-error');
var projectList = require('../util/projectList');
var config = require('../../app/config.js');
var errorNotifier = require('../util/error');
exports.loadProjectList = function loadProjectList(cb) {
if (projectList.get()) {
return cb();
}
var fields = [
'items.bounds',
'items.zoom_level',
'items.time_zone',
'items.code',
'items.flags',
'items.country_code',
'items.domain'
].join(',');
var protocol = config.appConfig.protocol;
var apiServer = config.appConfig.webApiServer;
var apiVersion = config.appConfig.webApiVersion;
var apiKey = config.appConfig.webApiKey;
var url = protocol + apiServer + '/' + apiVersion + '/region/list?key=' + apiKey + '&fields=' + fields;
request(url, function(err, res, body) {
if (err) {
var error = new PluginError({
plugin: 'loadProjectList',
message: err
});
errorNotifier.notify(error);
return cb();
}
var data = JSON.parse(body);
var projects = data.result.items;
var projectListString = 'DG.fallbackProjectsList = JSON.parse(\'' +
JSON.stringify(projects) +
'\');';
projectList.set(projectListString);
cb();
});
};
================================================
FILE: gulp/tasks/loader.js
================================================
var gulp = require('gulp');
var argv = require('minimist')(process.argv.slice(2));
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var replace = require('gulp-replace');
var error = require('../util/error');
var config = require('../../app/config.js');
exports.loader = function loader() {
var originalBaseUrl = config.appConfig.protocol + config.appConfig.baseUrl;
return gulp.src('app/loader.js')
.pipe(error.handle())
.pipe(replace(/__ORIGINAL_BASE_URL__/g, originalBaseUrl))
.pipe(gulpif(argv.release, uglify()))
.pipe(gulp.dest('dist'));
};
================================================
FILE: gulp/tasks/rebuildStyles.js
================================================
var { destCSS } = require('../util/destCSS');
exports.rebuildStyles = destCSS;
================================================
FILE: gulp/tasks/server.js
================================================
var spawn = require('child_process').spawn;
var nodeServer = null;
exports.server = function server(cb) {
function start() {
nodeServer = spawn('node', ['app'], {stdio: 'inherit'});
cb();
}
if (nodeServer) {
nodeServer.once('close', start);
nodeServer.kill();
} else {
start();
}
};
process.on('exit', function() {
if (nodeServer) {
nodeServer.kill();
}
});
================================================
FILE: gulp/tasks/test.js
================================================
var Server = require('karma').Server;
var argv = require('minimist')(process.argv.slice(2));
var gulp = require('gulp');
var path = require('path');
var glob = require('glob');
var log = require('fancy-log');
var _ = require('lodash');
var { buildTest } = require('./buildTest');
var test = require('../../test/test');
var excludedTests = require('../../test/excludedTests.js') || [];
var isTestDebug = argv.d || argv.debug;
var testRequirements = isTestDebug ? [] : [buildTest];
var itemsInChunk = 10; // items in chunk by default
function performTest(done) {
var cliOptions = _.cloneDeep(argv);
var modulesToTest = [];
var currentChunk = 0;
var sourcesList = [
'dist/js/script.full.js',
'node_modules/leaflet/spec/after.js',
'node_modules/happen/happen.js',
'node_modules/prosthetic-hand/dist/prosthetic-hand.js',
'node_modules/leaflet/spec/suites/SpecHelper.js',
'node_modules/mock-geolocation/dist/geolocate.js',
'test/after.js'
];
if ('m' in cliOptions) {
modulesToTest = cliOptions.m.split(',');
}
if ('module' in cliOptions) {
modulesToTest = cliOptions.module.split(',');
}
var modulesToTestSourceList = [];
if (modulesToTest.length) {
modulesToTest.forEach(function(moduleName) {
modulesToTestSourceList = modulesToTestSourceList.concat(glob.sync('src/' + moduleName + '/test/*Spec.js'));
});
} else {
modulesToTestSourceList = modulesToTestSourceList.concat(glob.sync('src/**/test/*Spec.js'));
}
modulesToTestSourceList = modulesToTestSourceList.concat(glob.sync('node_modules/leaflet/spec/suites/**/*Spec.js'));
modulesToTestSourceList = _.difference(modulesToTestSourceList, excludedTests);
var splittedModules = _.chunk(modulesToTestSourceList, itemsInChunk);
var numberOfChunks = splittedModules.length;
log('\nITEMS IN CHUNK: ' + itemsInChunk);
log('NUMBER OF CHUNKS: ' + numberOfChunks);
// Flag of existing errors.
var totalErr = false;
// Function will be run recursive, because need execute chunks in order.
function startServer(err) {
totalErr = err || totalErr;
log('\nCHUNK #' + currentChunk.toString());
var localeSourceList = sourcesList.concat(splittedModules[currentChunk]);
currentChunk++;
localeSourceList.push('node_modules/leaflet/spec/suites/SpecHelper.js');
function localDone(errDone) {
totalErr = errDone || totalErr;
done(totalErr);
}
new Server({
files: localeSourceList,
configFile: path.join(__dirname, '../../test/karma.conf.js'),
browsers: test.getBrowsers(),
reporters: test.getReporters(isTestDebug),
junitReporter: test.getJunitReporter(),
action: 'run',
preprocessors: {
'gulp/tmp/testJS/src/**/*.js': ['coverage']
},
singleRun: true
// Function localDone will be executed in the last iteration.
}, currentChunk === numberOfChunks ? localDone : startServer).start();
}
startServer();
}
exports.test = gulp.series(...testRequirements, performTest);
================================================
FILE: gulp/tasks/watch.js
================================================
var gulp = require('gulp');
var { doc } = require('./doc');
var { copyAssets } = require('./copyAssets');
var { server } = require('./server');
var { buildScripts } = require('./buildScripts');
var { rebuildStyles } = require('./rebuildStyles');
var { build } = require('./build');
var { loader } = require('./loader');
var { copyIndexPage } = require('./copyIndexPage');
exports.watch = function watch() {
gulp.watch('src/doc/**/*.*', doc);
gulp.watch('assets/**/*', gulp.series(copyAssets, server));
gulp.watch([
'src/**/*.js',
'vendors/leaflet/src/**/*.*'
], gulp.series(buildScripts, server));
gulp.watch('src/**/*.less', gulp.series(rebuildStyles, server));
gulp.watch('config.main.json', gulp.series(build, server));
gulp.watch(['app/index.js', 'config.local.json'], server);
gulp.watch('app/loader.js', gulp.series(loader, server));
gulp.watch('app/index.html', gulp.series(copyIndexPage, server));
};
================================================
FILE: gulp/util/buildCSS.js
================================================
var autoprefixer = require('gulp-autoprefixer');
var clean = require('gulp-clean-css');
var remember = require('gulp-remember');
var concat = require('gulp-concat');
var header = require('gulp-header');
var cache = require('gulp-cached');
var gulpif = require('gulp-if');
var less = require('gulp-less');
var argv = require('minimist')(process.argv.slice(2));
var map = require('map-stream');
var gulp = require('gulp');
var path = require('path');
var fs = require('fs');
var config = require('../../app/config.js');
var deps = require('../deps')(config);
var stat = require('../util/stat');
var error = require('./error');
exports.buildCSS = function(options) {
var imagesBasePath = path.resolve(__dirname + '/../../dist/img');
var baseURL = config.appConfig.protocol + config.appConfig.baseUrl;
var lessList = deps.getCSSFiles(options);
var lessHeaderImports;
if (options.isTest) {
lessHeaderImports = [
'./src/less/mixins.less:reference',
'./src/less/mixins.ie8.less:reference'
];
} else {
lessHeaderImports = [
'./gulp/tmp/less/sprite.basic.less:reference',
'./gulp/tmp/less/sprite@2x.basic.less:reference',
'./gulp/tmp/less/sprite.' + options.skin + '.less:reference',
'./gulp/tmp/less/sprite@2x.' + options.skin + '.less:reference',
'./gulp/tmp/less/images-files-statistics.basic.less:reference',
'./gulp/tmp/less/images-files-statistics.' + options.skin + '.less:reference',
'./src/less/mixins.less:reference',
'./src/less/mixins.ie8.less:reference'
];
}
lessHeaderImports = lessHeaderImports.filter(function(src) {
var lessFileSrc = src.split(':')[0];
try {
return fs.readFileSync(path.join(__dirname, '../..', lessFileSrc));
} catch (e) {
return false;
}
});
var lessPrerequirements = deps.lessHeader({
variables: {
baseURL: "'" + baseURL + "'",
skinName: options.skin,
ie8: options.ie8,
imagesBasePath: "'" + imagesBasePath + "'"
},
imports: lessHeaderImports
});
return gulp.src(lessList)
.pipe(error.handle())
.pipe(cache('css.' + options.suffix))
.pipe(header(lessPrerequirements))
.pipe(less())
.pipe(autoprefixer({browsers: ['last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4']}))
.pipe(remember('css.' + options.suffix))
.pipe(concat('styles.' + (options.suffix ? options.suffix + '.' : '') + 'css'))
.pipe(gulpif(argv.release, clean()))
.pipe(header(config.copyright))
.pipe(map(stat.save));
};
================================================
FILE: gulp/util/buildEnd.js
================================================
var argv = require('minimist')(process.argv.slice(2));
var log = require('fancy-log');
var stat = require('./stat');
var config = require('../../app/config');
var deps = require('../deps')(config);
exports.buildEnd = function buildEnd(done) {
log('Build contains the next modules:');
deps.getModulesList(argv.pkg).forEach(function(module) {
log('- ' + module);
});
if (argv.sprite == 'true') {
log('Builded with sprites');
} else if (argv.base64 != 'false' && typeof argv.base64 != 'undefined') {
log('Builded with base64 encode');
}
log('\nDist files statistic:');
var statValues = stat.get();
Object.keys(statValues).forEach(function(file) {
log('- ' + file + ': ' + statValues[file]);
});
log('Build successfully complete');
done();
};
================================================
FILE: gulp/util/csslint/gulp-csslint.js
================================================
var log = require('fancy-log');
var PluginError = require('plugin-error');
var es = require('event-stream');
var fs = require('fs');
var csslint = require('./lib/csslint').CSSLint;
var formatOutput = function (report, file, options) {
if (!report.messages.length) {
return {
success: true
};
}
var filePath = file.path || 'stdin';
// Handle errors
var results = report.messages.map(function (err) {
if (!err) {
return;
}
return {
file: filePath,
error: err
};
}).filter(function (err) {
return err;
});
var output = {
errorCount: results.length,
success: false,
results: results,
options: options
};
return output;
};
var cssLintPlugin = function (options) {
if (!options) {
options = {};
}
var ruleset = {};
// Read CSSLint options from a specified csslintrc file.
if (typeof options == 'string') {
// Don't catch readFile errors, let them bubble up
var externalOptions = fs.readFileSync('./' + options);
try {
options = JSON.parse(externalOptions);
} catch(err) {
throw new Error('Error parsing csslintrc: ' + err);
}
}
// Build a list of all available rules
csslint.getRules().forEach(function (rule) {
ruleset[rule.id] = 1;
});
for (var rule in options) {
if (!options[rule]) {
// Remove rules that are turned off
delete ruleset[rule];
} else {
ruleset[rule] = options[rule];
}
}
return es.map(function (file, cb) {
var report = csslint.verify(String(file.contents), ruleset);
// send status down-stream
file.csslint = formatOutput(report, file, options);
cb(null, file);
});
};
var defaultReporter = function (file) {
var errorCount = file.csslint.errorCount;
var plural = errorCount == 1 ? '' : 's';
log(errorCount + ' error' + plural + ' found in ' + file.path);
file.csslint.results.forEach(function (result) {
var message = result.error;
log('[' + (typeof message.line != 'undefined'
? 'L' + message.line + ':' + 'C' + message.col
: 'GENERAL'
) + '] ' + message.message + ' ' + message.rule.desc + ' (' + message.rule.id + ')'
);
});
};
cssLintPlugin.reporter = function (customReporter) {
var reporter = defaultReporter;
if (typeof customReporter == 'function') {
reporter = customReporter;
}
if (typeof reporter == 'undefined') {
throw new Error('Invalid reporter');
}
return es.map(function (file, cb) {
// Only report if CSSLint was ran and errors were found
if (file.csslint && !file.csslint.success) {
reporter(file);
}
return cb(null, file);
});
};
cssLintPlugin.failReporter = function () {
return es.map(function (file, cb) {
// Nothing to report or no errors
if (!file.csslint || file.csslint.success) {
return cb(null, file);
}
return cb(new PluginError('gulp-csslint', 'CSSLint failed for ' + file.relative), file);
});
};
module.exports = cssLintPlugin;
================================================
FILE: gulp/util/csslint/lib/csslint.js
================================================
/*!
CSSLint
Copyright (c) 2013 Nicole Sullivan and Nicholas C. Zakas. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* Build: v0.10.0 15-August-2013 01:07:22 */
var parserlib = require("./parserlib");
/**
* Main CSSLint object.
* @class CSSLint
* @static
* @extends parserlib.util.EventTarget
*/
/*global parserlib, Reporter*/
var CSSLint = (function(){
var rules = [],
formatters = [],
embeddedRuleset = /\/\*csslint([^\*]*)\*\//,
api = new parserlib.util.EventTarget();
api.version = "0.10.0";
//-------------------------------------------------------------------------
// Rule Management
//-------------------------------------------------------------------------
/**
* Adds a new rule to the engine.
* @param {Object} rule The rule to add.
* @method addRule
*/
api.addRule = function(rule){
rules.push(rule);
rules[rule.id] = rule;
};
/**
* Clears all rule from the engine.
* @method clearRules
*/
api.clearRules = function(){
rules = [];
};
/**
* Returns the rule objects.
* @return An array of rule objects.
* @method getRules
*/
api.getRules = function(){
return [].concat(rules).sort(function(a,b){
return a.id > b.id ? 1 : 0;
});
};
/**
* Returns a ruleset configuration object with all current rules.
* @return A ruleset object.
* @method getRuleset
*/
api.getRuleset = function() {
var ruleset = {},
i = 0,
len = rules.length;
while (i < len){
ruleset[rules[i++].id] = 1; //by default, everything is a warning
}
return ruleset;
};
/**
* Returns a ruleset object based on embedded rules.
* @param {String} text A string of css containing embedded rules.
* @param {Object} ruleset A ruleset object to modify.
* @return {Object} A ruleset object.
* @method getEmbeddedRuleset
*/
function applyEmbeddedRuleset(text, ruleset){
var valueMap,
embedded = text && text.match(embeddedRuleset),
rules = embedded && embedded[1];
if (rules) {
valueMap = {
"true": 2, // true is error
"": 1, // blank is warning
"false": 0, // false is ignore
"2": 2, // explicit error
"1": 1, // explicit warning
"0": 0 // explicit ignore
};
rules.toLowerCase().split(",").forEach(function(rule){
var pair = rule.split(":"),
property = pair[0] || "",
value = pair[1] || "";
ruleset[property.trim()] = valueMap[value.trim()];
});
}
return ruleset;
}
//-------------------------------------------------------------------------
// Formatters
//-------------------------------------------------------------------------
/**
* Adds a new formatter to the engine.
* @param {Object} formatter The formatter to add.
* @method addFormatter
*/
api.addFormatter = function(formatter) {
// formatters.push(formatter);
formatters[formatter.id] = formatter;
};
/**
* Retrieves a formatter for use.
* @param {String} formatId The name of the format to retrieve.
* @return {Object} The formatter or undefined.
* @method getFormatter
*/
api.getFormatter = function(formatId){
return formatters[formatId];
};
/**
* Formats the results in a particular format for a single file.
* @param {Object} result The results returned from CSSLint.verify().
* @param {String} filename The filename for which the results apply.
* @param {String} formatId The name of the formatter to use.
* @param {Object} options (Optional) for special output handling.
* @return {String} A formatted string for the results.
* @method format
*/
api.format = function(results, filename, formatId, options) {
var formatter = this.getFormatter(formatId),
result = null;
if (formatter){
result = formatter.startFormat();
result += formatter.formatResults(results, filename, options || {});
result += formatter.endFormat();
}
return result;
};
/**
* Indicates if the given format is supported.
* @param {String} formatId The ID of the format to check.
* @return {Boolean} True if the format exists, false if not.
* @method hasFormat
*/
api.hasFormat = function(formatId){
return formatters.hasOwnProperty(formatId);
};
//-------------------------------------------------------------------------
// Verification
//-------------------------------------------------------------------------
/**
* Starts the verification process for the given CSS text.
* @param {String} text The CSS text to verify.
* @param {Object} ruleset (Optional) List of rules to apply. If null, then
* all rules are used. If a rule has a value of 1 then it's a warning,
* a value of 2 means it's an error.
* @return {Object} Results of the verification.
* @method verify
*/
api.verify = function(text, ruleset){
var i = 0,
len = rules.length,
reporter,
lines,
report,
parser = new parserlib.css.Parser({ starHack: true, ieFilters: true,
underscoreHack: true, strict: false });
// normalize line endings
lines = text.replace(/\n\r?/g, "$split$").split('$split$');
if (!ruleset){
ruleset = this.getRuleset();
}
if (embeddedRuleset.test(text)){
ruleset = applyEmbeddedRuleset(text, ruleset);
}
reporter = new Reporter(lines, ruleset);
ruleset.errors = 2; //always report parsing errors as errors
for (i in ruleset){
if(ruleset.hasOwnProperty(i) && ruleset[i]){
if (rules[i]){
rules[i].init(parser, reporter);
}
}
}
//capture most horrible error type
try {
parser.parse(text);
} catch (ex) {
reporter.error("Fatal error, cannot continue: " + ex.message, ex.line, ex.col, {});
}
report = {
messages : reporter.messages,
stats : reporter.stats,
ruleset : reporter.ruleset
};
//sort by line numbers, rollups at the bottom
report.messages.sort(function (a, b){
if (a.rollup && !b.rollup){
return 1;
} else if (!a.rollup && b.rollup){
return -1;
} else {
return a.line - b.line;
}
});
return report;
};
//-------------------------------------------------------------------------
// Publish the API
//-------------------------------------------------------------------------
return api;
})();
/*global CSSLint*/
/**
* An instance of Report is used to report results of the
* verification back to the main API.
* @class Reporter
* @constructor
* @param {String[]} lines The text lines of the source.
* @param {Object} ruleset The set of rules to work with, including if
* they are errors or warnings.
*/
function Reporter(lines, ruleset){
/**
* List of messages being reported.
* @property messages
* @type String[]
*/
this.messages = [];
/**
* List of statistics being reported.
* @property stats
* @type String[]
*/
this.stats = [];
/**
* Lines of code being reported on. Used to provide contextual information
* for messages.
* @property lines
* @type String[]
*/
this.lines = lines;
/**
* Information about the rules. Used to determine whether an issue is an
* error or warning.
* @property ruleset
* @type Object
*/
this.ruleset = ruleset;
}
Reporter.prototype = {
//restore constructor
constructor: Reporter,
/**
* Report an error.
* @param {String} message The message to store.
* @param {int} line The line number.
* @param {int} col The column number.
* @param {Object} rule The rule this message relates to.
* @method error
*/
error: function(message, line, col, rule){
this.messages.push({
type : "error",
line : line,
col : col,
message : message,
evidence: this.lines[line-1],
rule : rule || {}
});
},
/**
* Report an warning.
* @param {String} message The message to store.
* @param {int} line The line number.
* @param {int} col The column number.
* @param {Object} rule The rule this message relates to.
* @method warn
* @deprecated Use report instead.
*/
warn: function(message, line, col, rule){
this.report(message, line, col, rule);
},
/**
* Report an issue.
* @param {String} message The message to store.
* @param {int} line The line number.
* @param {int} col The column number.
* @param {Object} rule The rule this message relates to.
* @method report
*/
report: function(message, line, col, rule){
this.messages.push({
type : this.ruleset[rule.id] == 2 ? "error" : "warning",
line : line,
col : col,
message : message,
evidence: this.lines[line-1],
rule : rule
});
},
/**
* Report some informational text.
* @param {String} message The message to store.
* @param {int} line The line number.
* @param {int} col The column number.
* @param {Object} rule The rule this message relates to.
* @method info
*/
info: function(message, line, col, rule){
this.messages.push({
type : "info",
line : line,
col : col,
message : message,
evidence: this.lines[line-1],
rule : rule
});
},
/**
* Report some rollup error information.
* @param {String} message The message to store.
* @param {Object} rule The rule this message relates to.
* @method rollupError
*/
rollupError: function(message, rule){
this.messages.push({
type : "error",
rollup : true,
message : message,
rule : rule
});
},
/**
* Report some rollup warning information.
* @param {String} message The message to store.
* @param {Object} rule The rule this message relates to.
* @method rollupWarn
*/
rollupWarn: function(message, rule){
this.messages.push({
type : "warning",
rollup : true,
message : message,
rule : rule
});
},
/**
* Report a statistic.
* @param {String} name The name of the stat to store.
* @param {Variant} value The value of the stat.
* @method stat
*/
stat: function(name, value){
this.stats[name] = value;
}
};
//expose for testing purposes
CSSLint._Reporter = Reporter;
/*global CSSLint*/
/*
* Utility functions that make life easier.
*/
CSSLint.Util = {
/*
* Adds all properties from supplier onto receiver,
* overwriting if the same name already exists on
* reciever.
* @param {Object} The object to receive the properties.
* @param {Object} The object to provide the properties.
* @return {Object} The receiver
*/
mix: function(receiver, supplier){
var prop;
for (prop in supplier){
if (supplier.hasOwnProperty(prop)){
receiver[prop] = supplier[prop];
}
}
return prop;
},
/*
* Polyfill for array indexOf() method.
* @param {Array} values The array to search.
* @param {Variant} value The value to search for.
* @return {int} The index of the value if found, -1 if not.
*/
indexOf: function(values, value){
if (values.indexOf){
return values.indexOf(value);
} else {
for (var i=0, len=values.length; i < len; i++){
if (values[i] === value){
return i;
}
}
return -1;
}
},
/*
* Polyfill for array forEach() method.
* @param {Array} values The array to operate on.
* @param {Function} func The function to call on each item.
* @return {void}
*/
forEach: function(values, func) {
if (values.forEach){
return values.forEach(func);
} else {
for (var i=0, len=values.length; i < len; i++){
func(values[i], i, values);
}
}
}
};
/*global CSSLint*/
/*
* Rule: Don't use adjoining classes (.foo.bar).
*/
CSSLint.addRule({
//rule information
id: "adjoining-classes",
name: "Disallow adjoining classes",
desc: "Don't use adjoining classes.",
browsers: "IE6",
//initialization
init: function(parser, reporter){
var rule = this;
parser.addListener("startrule", function(event){
var selectors = event.selectors,
selector,
part,
modifier,
classCount,
i, j, k;
for (i=0; i < selectors.length; i++){
selector = selectors[i];
for (j=0; j < selector.parts.length; j++){
part = selector.parts[j];
if (part.type == parser.SELECTOR_PART_TYPE){
classCount = 0;
for (k=0; k < part.modifiers.length; k++){
modifier = part.modifiers[k];
if (modifier.type == "class"){
classCount++;
}
if (classCount > 1){
reporter.report("Don't use adjoining classes.", part.line, part.col, rule);
}
}
}
}
}
});
}
});
/*global CSSLint*/
/*
* Rule: Don't use width or height when using padding or border.
*/
CSSLint.addRule({
//rule information
id: "box-model",
name: "Beware of broken box size",
desc: "Don't use width or height when using padding or border.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
widthProperties = {
border: 1,
"border-left": 1,
"border-right": 1,
padding: 1,
"padding-left": 1,
"padding-right": 1
},
heightProperties = {
border: 1,
"border-bottom": 1,
"border-top": 1,
padding: 1,
"padding-bottom": 1,
"padding-top": 1
},
properties,
boxSizing = false;
function startRule(){
properties = {};
boxSizing = false;
}
function endRule(){
var prop, value;
if (!boxSizing) {
if (properties.height){
for (prop in heightProperties){
if (heightProperties.hasOwnProperty(prop) && properties[prop]){
value = properties[prop].value;
//special case for padding
if (!(prop == "padding" && value.parts.length === 2 && value.parts[0].value === 0)){
reporter.report("Using height with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
}
}
}
}
if (properties.width){
for (prop in widthProperties){
if (widthProperties.hasOwnProperty(prop) && properties[prop]){
value = properties[prop].value;
if (!(prop == "padding" && value.parts.length === 2 && value.parts[1].value === 0)){
reporter.report("Using width with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
}
}
}
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("property", function(event){
var name = event.property.text.toLowerCase();
if (heightProperties[name] || widthProperties[name]){
if (!/^0\S*$/.test(event.value) && !(name == "border" && event.value == "none")){
properties[name] = { line: event.property.line, col: event.property.col, value: event.value };
}
} else {
if (/^(width|height)/i.test(name) && /^(length|percentage)/.test(event.value.parts[0].type)){
properties[name] = 1;
} else if (name == "box-sizing") {
boxSizing = true;
}
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
parser.addListener("endpage", endRule);
parser.addListener("endpagemargin", endRule);
parser.addListener("endkeyframerule", endRule);
}
});
/*global CSSLint*/
/*
* Rule: box-sizing doesn't work in IE6 and IE7.
*/
CSSLint.addRule({
//rule information
id: "box-sizing",
name: "Disallow use of box-sizing",
desc: "The box-sizing properties isn't supported in IE6 and IE7.",
browsers: "IE6, IE7",
tags: ["Compatibility"],
//initialization
init: function(parser, reporter){
var rule = this;
parser.addListener("property", function(event){
var name = event.property.text.toLowerCase();
if (name == "box-sizing"){
reporter.report("The box-sizing property isn't supported in IE6 and IE7.", event.line, event.col, rule);
}
});
}
});
/*
* Rule: Use the bulletproof @font-face syntax to avoid 404's in old IE
* (http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax)
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "bulletproof-font-face",
name: "Use the bulletproof @font-face syntax",
desc: "Use the bulletproof @font-face syntax to avoid 404's in old IE (http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax).",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
count = 0,
fontFaceRule = false,
firstSrc = true,
ruleFailed = false,
line, col;
// Mark the start of a @font-face declaration so we only test properties inside it
parser.addListener("startfontface", function(event){
fontFaceRule = true;
});
parser.addListener("property", function(event){
// If we aren't inside an @font-face declaration then just return
if (!fontFaceRule) {
return;
}
var propertyName = event.property.toString().toLowerCase(),
value = event.value.toString();
// Set the line and col numbers for use in the endfontface listener
line = event.line;
col = event.col;
// This is the property that we care about, we can ignore the rest
if (propertyName === 'src') {
var regex = /^\s?url\(['"].+\.eot\?.*['"]\)\s*format\(['"]embedded-opentype['"]\).*$/i;
// We need to handle the advanced syntax with two src properties
if (!value.match(regex) && firstSrc) {
ruleFailed = true;
firstSrc = false;
} else if (value.match(regex) && !firstSrc) {
ruleFailed = false;
}
}
});
// Back to normal rules that we don't need to test
parser.addListener("endfontface", function(event){
fontFaceRule = false;
if (ruleFailed) {
reporter.report("@font-face declaration doesn't follow the fontspring bulletproof syntax.", line, col, rule);
}
});
}
});
/*
* Rule: Include all compatible vendor prefixes to reach a wider
* range of users.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "compatible-vendor-prefixes",
name: "Require compatible vendor prefixes",
desc: "Include all compatible vendor prefixes to reach a wider range of users.",
browsers: "All",
//initialization
init: function (parser, reporter) {
var rule = this,
compatiblePrefixes,
properties,
prop,
variations,
prefixed,
i,
len,
inKeyFrame = false,
arrayPush = Array.prototype.push,
applyTo = [];
// See http://peter.sh/experiments/vendor-prefixed-css-property-overview/ for details
compatiblePrefixes = {
"animation" : "webkit moz",
"animation-delay" : "webkit moz",
"animation-direction" : "webkit moz",
"animation-duration" : "webkit moz",
"animation-fill-mode" : "webkit moz",
"animation-iteration-count" : "webkit moz",
"animation-name" : "webkit moz",
"animation-play-state" : "webkit moz",
"animation-timing-function" : "webkit moz",
"appearance" : "webkit moz",
"border-end" : "webkit moz",
"border-end-color" : "webkit moz",
"border-end-style" : "webkit moz",
"border-end-width" : "webkit moz",
"border-image" : "webkit moz o",
"border-radius" : "webkit",
"border-start" : "webkit moz",
"border-start-color" : "webkit moz",
"border-start-style" : "webkit moz",
"border-start-width" : "webkit moz",
"box-align" : "webkit moz ms",
"box-direction" : "webkit moz ms",
"box-flex" : "webkit moz ms",
"box-lines" : "webkit ms",
"box-ordinal-group" : "webkit moz ms",
"box-orient" : "webkit moz ms",
"box-pack" : "webkit moz ms",
"box-sizing" : "webkit moz",
"box-shadow" : "webkit moz",
"column-count" : "webkit moz ms",
"column-gap" : "webkit moz ms",
"column-rule" : "webkit moz ms",
"column-rule-color" : "webkit moz ms",
"column-rule-style" : "webkit moz ms",
"column-rule-width" : "webkit moz ms",
"column-width" : "webkit moz ms",
"hyphens" : "epub moz",
"line-break" : "webkit ms",
"margin-end" : "webkit moz",
"margin-start" : "webkit moz",
"marquee-speed" : "webkit wap",
"marquee-style" : "webkit wap",
"padding-end" : "webkit moz",
"padding-start" : "webkit moz",
"tab-size" : "moz o",
"text-size-adjust" : "webkit ms",
"transform" : "webkit moz ms o",
"transform-origin" : "webkit moz ms o",
"transition" : "webkit moz o",
"transition-delay" : "webkit moz o",
"transition-duration" : "webkit moz o",
"transition-property" : "webkit moz o",
"transition-timing-function" : "webkit moz o",
"user-modify" : "webkit moz",
"user-select" : "webkit moz ms",
"word-break" : "epub ms",
"writing-mode" : "epub ms"
};
for (prop in compatiblePrefixes) {
if (compatiblePrefixes.hasOwnProperty(prop)) {
variations = [];
prefixed = compatiblePrefixes[prop].split(' ');
for (i = 0, len = prefixed.length; i < len; i++) {
variations.push('-' + prefixed[i] + '-' + prop);
}
compatiblePrefixes[prop] = variations;
arrayPush.apply(applyTo, variations);
}
}
parser.addListener("startrule", function () {
properties = [];
});
parser.addListener("startkeyframes", function (event) {
inKeyFrame = event.prefix || true;
});
parser.addListener("endkeyframes", function (event) {
inKeyFrame = false;
});
parser.addListener("property", function (event) {
var name = event.property;
if (CSSLint.Util.indexOf(applyTo, name.text) > -1) {
// e.g., -moz-transform is okay to be alone in @-moz-keyframes
if (!inKeyFrame || typeof inKeyFrame != "string" ||
name.text.indexOf("-" + inKeyFrame + "-") !== 0) {
properties.push(name);
}
}
});
parser.addListener("endrule", function (event) {
if (!properties.length) {
return;
}
var propertyGroups = {},
i,
len,
name,
prop,
variations,
value,
full,
actual,
item,
propertiesSpecified;
for (i = 0, len = properties.length; i < len; i++) {
name = properties[i];
for (prop in compatiblePrefixes) {
if (compatiblePrefixes.hasOwnProperty(prop)) {
variations = compatiblePrefixes[prop];
if (CSSLint.Util.indexOf(variations, name.text) > -1) {
if (!propertyGroups[prop]) {
propertyGroups[prop] = {
full : variations.slice(0),
actual : [],
actualNodes: []
};
}
if (CSSLint.Util.indexOf(propertyGroups[prop].actual, name.text) === -1) {
propertyGroups[prop].actual.push(name.text);
propertyGroups[prop].actualNodes.push(name);
}
}
}
}
}
for (prop in propertyGroups) {
if (propertyGroups.hasOwnProperty(prop)) {
value = propertyGroups[prop];
full = value.full;
actual = value.actual;
if (full.length > actual.length) {
for (i = 0, len = full.length; i < len; i++) {
item = full[i];
if (CSSLint.Util.indexOf(actual, item) === -1) {
propertiesSpecified = (actual.length === 1) ? actual[0] : (actual.length == 2) ? actual.join(" and ") : actual.join(", ");
reporter.report("The property " + item + " is compatible with " + propertiesSpecified + " and should be included as well.", value.actualNodes[0].line, value.actualNodes[0].col, rule);
}
}
}
}
}
});
}
});
/*
* Rule: Certain properties don't play well with certain display values.
* - float should not be used with inline-block
* - height, width, margin-top, margin-bottom, float should not be used with inline
* - vertical-align should not be used with block
* - margin, float should not be used with table-*
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "display-property-grouping",
name: "Require properties appropriate for display",
desc: "Certain properties shouldn't be used with certain display property values.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
var propertiesToCheck = {
display: 1,
"float": "none",
height: 1,
width: 1,
margin: 1,
"margin-left": 1,
"margin-right": 1,
"margin-bottom": 1,
"margin-top": 1,
padding: 1,
"padding-left": 1,
"padding-right": 1,
"padding-bottom": 1,
"padding-top": 1,
"vertical-align": 1
},
properties;
function reportProperty(name, display, msg){
if (properties[name]){
if (typeof propertiesToCheck[name] != "string" || properties[name].value.toLowerCase() != propertiesToCheck[name]){
reporter.report(msg || name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
}
}
}
function startRule(){
properties = {};
}
function endRule(){
var display = properties.display ? properties.display.value : null;
if (display){
switch(display){
case "inline":
//height, width, margin-top, margin-bottom, float should not be used with inline
reportProperty("height", display);
reportProperty("width", display);
reportProperty("margin", display);
reportProperty("margin-top", display);
reportProperty("margin-bottom", display);
reportProperty("float", display, "display:inline has no effect on floated elements (but may be used to fix the IE6 double-margin bug).");
break;
case "block":
//vertical-align should not be used with block
reportProperty("vertical-align", display);
break;
case "inline-block":
//float should not be used with inline-block
reportProperty("float", display);
break;
default:
//margin, float should not be used with table
if (display.indexOf("table-") === 0){
reportProperty("margin", display);
reportProperty("margin-left", display);
reportProperty("margin-right", display);
reportProperty("margin-top", display);
reportProperty("margin-bottom", display);
reportProperty("float", display);
}
//otherwise do nothing
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startpage", startRule);
parser.addListener("property", function(event){
var name = event.property.text.toLowerCase();
if (propertiesToCheck[name]){
properties[name] = { value: event.value.text, line: event.property.line, col: event.property.col };
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
parser.addListener("endkeyframerule", endRule);
parser.addListener("endpagemargin", endRule);
parser.addListener("endpage", endRule);
}
});
/*
* Rule: Disallow duplicate background-images (using url).
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "duplicate-background-images",
name: "Disallow duplicate background images",
desc: "Every background-image should be unique. Use a common class for e.g. sprites.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
stack = {};
parser.addListener("property", function(event){
var name = event.property.text,
value = event.value,
i, len;
if (name.match(/background/i)) {
for (i=0, len=value.parts.length; i < len; i++) {
if (value.parts[i].type == 'uri') {
if (typeof stack[value.parts[i].uri] === 'undefined') {
stack[value.parts[i].uri] = event;
}
else {
reporter.report("Background image '" + value.parts[i].uri + "' was used multiple times, first declared at line " + stack[value.parts[i].uri].line + ", col " + stack[value.parts[i].uri].col + ".", event.line, event.col, rule);
}
}
}
}
});
}
});
/*
* Rule: Duplicate properties must appear one after the other. If an already-defined
* property appears somewhere else in the rule, then it's likely an error.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "duplicate-properties",
name: "Disallow duplicate properties",
desc: "Duplicate properties must appear one after the other.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
properties,
lastProperty;
function startRule(event){
properties = {};
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("property", function(event){
var property = event.property,
name = property.text.toLowerCase();
if (properties[name] && (lastProperty != name || properties[name] == event.value.text)){
reporter.report("Duplicate property '" + event.property + "' found.", event.line, event.col, rule);
}
properties[name] = event.value.text;
lastProperty = name;
});
}
});
/*
* Rule: Style rules without any properties defined should be removed.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "empty-rules",
name: "Disallow empty rules",
desc: "Rules without any properties specified should be removed.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
count = 0;
parser.addListener("startrule", function(){
count=0;
});
parser.addListener("property", function(){
count++;
});
parser.addListener("endrule", function(event){
var selectors = event.selectors;
if (count === 0){
reporter.report("Rule is empty.", selectors[0].line, selectors[0].col, rule);
}
});
}
});
/*
* Rule: There should be no syntax errors. (Duh.)
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "errors",
name: "Parsing Errors",
desc: "This rule looks for recoverable syntax errors.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
parser.addListener("error", function(event){
reporter.error(event.message, event.line, event.col, rule);
});
}
});
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "fallback-colors",
name: "Require fallback colors",
desc: "For older browsers that don't support RGBA, HSL, or HSLA, provide a fallback color.",
browsers: "IE6,IE7,IE8",
//initialization
init: function(parser, reporter){
var rule = this,
lastProperty,
propertiesToCheck = {
color: 1,
background: 1,
"border-color": 1,
"border-top-color": 1,
"border-right-color": 1,
"border-bottom-color": 1,
"border-left-color": 1,
border: 1,
"border-top": 1,
"border-right": 1,
"border-bottom": 1,
"border-left": 1,
"background-color": 1
},
properties;
function startRule(event){
properties = {};
lastProperty = null;
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("property", function(event){
var property = event.property,
name = property.text.toLowerCase(),
parts = event.value.parts,
i = 0,
colorType = "",
len = parts.length;
if(propertiesToCheck[name]){
while(i < len){
if (parts[i].type == "color"){
if ("alpha" in parts[i] || "hue" in parts[i]){
if (/([^\)]+)\(/.test(parts[i])){
colorType = RegExp.$1.toUpperCase();
}
if (!lastProperty || (lastProperty.property.text.toLowerCase() != name || lastProperty.colorType != "compat")){
reporter.report("Fallback " + name + " (hex or RGB) should precede " + colorType + " " + name + ".", event.line, event.col, rule);
}
} else {
event.colorType = "compat";
}
}
i++;
}
}
lastProperty = event;
});
}
});
/*
* Rule: You shouldn't use more than 10 floats. If you do, there's probably
* room for some abstraction.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "floats",
name: "Disallow too many floats",
desc: "This rule tests if the float property is used too many times",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
var count = 0;
//count how many times "float" is used
parser.addListener("property", function(event){
if (event.property.text.toLowerCase() == "float" &&
event.value.text.toLowerCase() != "none"){
count++;
}
});
//report the results
parser.addListener("endstylesheet", function(){
reporter.stat("floats", count);
if (count >= 10){
reporter.rollupWarn("Too many floats (" + count + "), you're probably using them for layout. Consider using a grid system instead.", rule);
}
});
}
});
/*
* Rule: Avoid too many @font-face declarations in the same stylesheet.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "font-faces",
name: "Don't use too many web fonts",
desc: "Too many different web fonts in the same stylesheet.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
count = 0;
parser.addListener("startfontface", function(){
count++;
});
parser.addListener("endstylesheet", function(){
if (count > 5){
reporter.rollupWarn("Too many @font-face declarations (" + count + ").", rule);
}
});
}
});
/*
* Rule: You shouldn't need more than 9 font-size declarations.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "font-sizes",
name: "Disallow too many font sizes",
desc: "Checks the number of font-size declarations.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
count = 0;
//check for use of "font-size"
parser.addListener("property", function(event){
if (event.property == "font-size"){
count++;
}
});
//report the results
parser.addListener("endstylesheet", function(){
reporter.stat("font-sizes", count);
if (count >= 10){
reporter.rollupWarn("Too many font-size declarations (" + count + "), abstraction needed.", rule);
}
});
}
});
/*
* Rule: When using a vendor-prefixed gradient, make sure to use them all.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "gradients",
name: "Require all gradient definitions",
desc: "When using a vendor-prefixed gradient, make sure to use them all.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
gradients;
parser.addListener("startrule", function(){
gradients = {
moz: 0,
webkit: 0,
oldWebkit: 0,
o: 0
};
});
parser.addListener("property", function(event){
if (/\-(moz|o|webkit)(?:\-(?:linear|radial))\-gradient/i.test(event.value)){
gradients[RegExp.$1] = 1;
} else if (/\-webkit\-gradient/i.test(event.value)){
gradients.oldWebkit = 1;
}
});
parser.addListener("endrule", function(event){
var missing = [];
if (!gradients.moz){
missing.push("Firefox 3.6+");
}
if (!gradients.webkit){
missing.push("Webkit (Safari 5+, Chrome)");
}
if (!gradients.oldWebkit){
missing.push("Old Webkit (Safari 4+, Chrome)");
}
if (!gradients.o){
missing.push("Opera 11.1+");
}
if (missing.length && missing.length < 4){
reporter.report("Missing vendor-prefixed CSS gradients for " + missing.join(", ") + ".", event.selectors[0].line, event.selectors[0].col, rule);
}
});
}
});
/*
* Rule: Don't use IDs for selectors.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "ids",
name: "Disallow IDs in selectors",
desc: "Selectors should not contain IDs.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
parser.addListener("startrule", function(event){
var selectors = event.selectors,
selector,
part,
modifier,
idCount,
i, j, k;
for (i=0; i < selectors.length; i++){
selector = selectors[i];
idCount = 0;
for (j=0; j < selector.parts.length; j++){
part = selector.parts[j];
if (part.type == parser.SELECTOR_PART_TYPE){
for (k=0; k < part.modifiers.length; k++){
modifier = part.modifiers[k];
if (modifier.type == "id"){
idCount++;
}
}
}
}
if (idCount == 1){
reporter.report("Don't use IDs in selectors.", selector.line, selector.col, rule);
} else if (idCount > 1){
reporter.report(idCount + " IDs in the selector, really?", selector.line, selector.col, rule);
}
}
});
}
});
/*
* Rule: Don't use @import, use instead.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "import",
name: "Disallow @import",
desc: "Don't use @import, use instead.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
parser.addListener("import", function(event){
reporter.report("@import prevents parallel downloads, use instead.", event.line, event.col, rule);
});
}
});
/*
* Rule: Make sure !important is not overused, this could lead to specificity
* war. Display a warning on !important declarations, an error if it's
* used more at least 10 times.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "important",
name: "Disallow !important",
desc: "Be careful when using !important declaration",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
count = 0;
//warn that important is used and increment the declaration counter
parser.addListener("property", function(event){
if (event.important === true){
count++;
reporter.report("Use of !important", event.line, event.col, rule);
}
});
//if there are more than 10, show an error
parser.addListener("endstylesheet", function(){
reporter.stat("important", count);
if (count >= 10){
reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specificity issues.", rule);
}
});
}
});
/*
* Rule: Properties should be known (listed in CSS3 specification) or
* be a vendor-prefixed property.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "known-properties",
name: "Require use of known properties",
desc: "Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
parser.addListener("property", function(event){
var name = event.property.text.toLowerCase();
// the check is handled entirely by the parser-lib (https://github.com/nzakas/parser-lib)
if (event.invalid) {
reporter.report(event.invalid.message, event.line, event.col, rule);
}
});
}
});
/*
* Rule: outline: none or outline: 0 should only be used in a :focus rule
* and only if there are other properties in the same rule.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "outline-none",
name: "Disallow outline: none",
desc: "Use of outline: none or outline: 0 should be limited to :focus rules.",
browsers: "All",
tags: ["Accessibility"],
//initialization
init: function(parser, reporter){
var rule = this,
lastRule;
function startRule(event){
if (event.selectors){
lastRule = {
line: event.line,
col: event.col,
selectors: event.selectors,
propCount: 0,
outline: false
};
} else {
lastRule = null;
}
}
function endRule(event){
if (lastRule){
if (lastRule.outline){
if (lastRule.selectors.toString().toLowerCase().indexOf(":focus") == -1){
reporter.report("Outlines should only be modified using :focus.", lastRule.line, lastRule.col, rule);
} else if (lastRule.propCount == 1) {
reporter.report("Outlines shouldn't be hidden unless other visual changes are made.", lastRule.line, lastRule.col, rule);
}
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("property", function(event){
var name = event.property.text.toLowerCase(),
value = event.value;
if (lastRule){
lastRule.propCount++;
if (name == "outline" && (value == "none" || value == "0")){
lastRule.outline = true;
}
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
parser.addListener("endpage", endRule);
parser.addListener("endpagemargin", endRule);
parser.addListener("endkeyframerule", endRule);
}
});
/*
* Rule: Don't use classes or IDs with elements (a.foo or a#foo).
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "overqualified-elements",
name: "Disallow overqualified elements",
desc: "Don't use classes or IDs with elements (a.foo or a#foo).",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
classes = {};
parser.addListener("startrule", function(event){
var selectors = event.selectors,
selector,
part,
modifier,
i, j, k;
for (i=0; i < selectors.length; i++){
selector = selectors[i];
for (j=0; j < selector.parts.length; j++){
part = selector.parts[j];
if (part.type == parser.SELECTOR_PART_TYPE){
for (k=0; k < part.modifiers.length; k++){
modifier = part.modifiers[k];
if (part.elementName && modifier.type == "id"){
reporter.report("Element (" + part + ") is overqualified, just use " + modifier + " without element name.", part.line, part.col, rule);
} else if (modifier.type == "class"){
if (!classes[modifier]){
classes[modifier] = [];
}
classes[modifier].push({ modifier: modifier, part: part });
}
}
}
}
}
});
parser.addListener("endstylesheet", function(){
var prop;
for (prop in classes){
if (classes.hasOwnProperty(prop)){
//one use means that this is overqualified
if (classes[prop].length == 1 && classes[prop][0].part.elementName){
reporter.report("Element (" + classes[prop][0].part + ") is overqualified, just use " + classes[prop][0].modifier + " without element name.", classes[prop][0].part.line, classes[prop][0].part.col, rule);
}
}
}
});
}
});
/*
* Rule: Headings (h1-h6) should not be qualified (namespaced).
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "qualified-headings",
name: "Disallow qualified headings",
desc: "Headings should not be qualified (namespaced).",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
parser.addListener("startrule", function(event){
var selectors = event.selectors,
selector,
part,
i, j;
for (i=0; i < selectors.length; i++){
selector = selectors[i];
for (j=0; j < selector.parts.length; j++){
part = selector.parts[j];
if (part.type == parser.SELECTOR_PART_TYPE){
if (part.elementName && /h[1-6]/.test(part.elementName.toString()) && j > 0){
reporter.report("Heading (" + part.elementName + ") should not be qualified.", part.line, part.col, rule);
}
}
}
}
});
}
});
/*
* Rule: Selectors that look like regular expressions are slow and should be avoided.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "regex-selectors",
name: "Disallow selectors that look like regexs",
desc: "Selectors that look like regular expressions are slow and should be avoided.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
parser.addListener("startrule", function(event){
var selectors = event.selectors,
selector,
part,
modifier,
i, j, k;
for (i=0; i < selectors.length; i++){
selector = selectors[i];
for (j=0; j < selector.parts.length; j++){
part = selector.parts[j];
if (part.type == parser.SELECTOR_PART_TYPE){
for (k=0; k < part.modifiers.length; k++){
modifier = part.modifiers[k];
if (modifier.type == "attribute"){
if (/([\~\|\^\$\*]=)/.test(modifier)){
reporter.report("Attribute selectors with " + RegExp.$1 + " are slow!", modifier.line, modifier.col, rule);
}
}
}
}
}
}
});
}
});
/*
* Rule: Total number of rules should not exceed x.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "rules-count",
name: "Rules Count",
desc: "Track how many rules there are.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
count = 0;
//count each rule
parser.addListener("startrule", function(){
count++;
});
parser.addListener("endstylesheet", function(){
reporter.stat("rule-count", count);
});
}
});
/*
* Rule: Warn people with approaching the IE 4095 limit
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "selector-max-approaching",
name: "Warn when approaching the 4095 selector limit for IE",
desc: "Will warn when selector count is >= 3800 selectors.",
browsers: "IE",
//initialization
init: function(parser, reporter) {
var rule = this, count = 0;
parser.addListener('startrule', function(event) {
count += event.selectors.length;
});
parser.addListener("endstylesheet", function() {
if (count >= 3800) {
reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,rule);
}
});
}
});
/*
* Rule: Warn people past the IE 4095 limit
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "selector-max",
name: "Error when past the 4095 selector limit for IE",
desc: "Will error when selector count is > 4095.",
browsers: "IE",
//initialization
init: function(parser, reporter){
var rule = this, count = 0;
parser.addListener('startrule',function(event) {
count += event.selectors.length;
});
parser.addListener("endstylesheet", function() {
if (count > 4095) {
reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,rule);
}
});
}
});
/*
* Rule: Use shorthand properties where possible.
*
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "shorthand",
name: "Require shorthand properties",
desc: "Use shorthand properties where possible.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
prop, i, len,
propertiesToCheck = {},
properties,
mapping = {
"margin": [
"margin-top",
"margin-bottom",
"margin-left",
"margin-right"
],
"padding": [
"padding-top",
"padding-bottom",
"padding-left",
"padding-right"
]
};
//initialize propertiesToCheck
for (prop in mapping){
if (mapping.hasOwnProperty(prop)){
for (i=0, len=mapping[prop].length; i < len; i++){
propertiesToCheck[mapping[prop][i]] = prop;
}
}
}
function startRule(event){
properties = {};
}
//event handler for end of rules
function endRule(event){
var prop, i, len, total;
//check which properties this rule has
for (prop in mapping){
if (mapping.hasOwnProperty(prop)){
total=0;
for (i=0, len=mapping[prop].length; i < len; i++){
total += properties[mapping[prop][i]] ? 1 : 0;
}
if (total == mapping[prop].length){
reporter.report("The properties " + mapping[prop].join(", ") + " can be replaced by " + prop + ".", event.line, event.col, rule);
}
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
//check for use of "font-size"
parser.addListener("property", function(event){
var name = event.property.toString().toLowerCase(),
value = event.value.parts[0].value;
if (propertiesToCheck[name]){
properties[name] = 1;
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
}
});
/*
* Rule: Don't use properties with a star prefix.
*
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "star-property-hack",
name: "Disallow properties with a star prefix",
desc: "Checks for the star property hack (targets IE6/7)",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
//check if property name starts with "*"
parser.addListener("property", function(event){
var property = event.property;
if (property.hack == "*") {
reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
}
});
}
});
/*
* Rule: Don't use text-indent for image replacement if you need to support rtl.
*
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "text-indent",
name: "Disallow negative text-indent",
desc: "Checks for text indent less than -99px",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
textIndent,
direction;
function startRule(event){
textIndent = false;
direction = "inherit";
}
//event handler for end of rules
function endRule(event){
if (textIndent && direction != "ltr"){
reporter.report("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", textIndent.line, textIndent.col, rule);
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
//check for use of "font-size"
parser.addListener("property", function(event){
var name = event.property.toString().toLowerCase(),
value = event.value;
if (name == "text-indent" && value.parts[0].value < -99){
textIndent = event.property;
} else if (name == "direction" && value == "ltr"){
direction = "ltr";
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
}
});
/*
* Rule: Don't use properties with a underscore prefix.
*
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "underscore-property-hack",
name: "Disallow properties with an underscore prefix",
desc: "Checks for the underscore property hack (targets IE6)",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
//check if property name starts with "_"
parser.addListener("property", function(event){
var property = event.property;
if (property.hack == "_") {
reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
}
});
}
});
/*
* Rule: Headings (h1-h6) should be defined only once.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "unique-headings",
name: "Headings should only be defined once",
desc: "Headings should be defined only once.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
var headings = {
h1: 0,
h2: 0,
h3: 0,
h4: 0,
h5: 0,
h6: 0
};
parser.addListener("startrule", function(event){
var selectors = event.selectors,
selector,
part,
pseudo,
i, j;
for (i=0; i < selectors.length; i++){
selector = selectors[i];
part = selector.parts[selector.parts.length-1];
if (part.elementName && /(h[1-6])/i.test(part.elementName.toString())){
for (j=0; j < part.modifiers.length; j++){
if (part.modifiers[j].type == "pseudo"){
pseudo = true;
break;
}
}
if (!pseudo){
headings[RegExp.$1]++;
if (headings[RegExp.$1] > 1) {
reporter.report("Heading (" + part.elementName + ") has already been defined.", part.line, part.col, rule);
}
}
}
}
});
parser.addListener("endstylesheet", function(event){
var prop,
messages = [];
for (prop in headings){
if (headings.hasOwnProperty(prop)){
if (headings[prop] > 1){
messages.push(headings[prop] + " " + prop + "s");
}
}
}
if (messages.length){
reporter.rollupWarn("You have " + messages.join(", ") + " defined in this stylesheet.", rule);
}
});
}
});
/*
* Rule: Don't use universal selector because it's slow.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "universal-selector",
name: "Disallow universal selector",
desc: "The universal selector (*) is known to be slow.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
parser.addListener("startrule", function(event){
var selectors = event.selectors,
selector,
part,
modifier,
i, j, k;
for (i=0; i < selectors.length; i++){
selector = selectors[i];
part = selector.parts[selector.parts.length-1];
if (part.elementName == "*"){
reporter.report(rule.desc, part.line, part.col, rule);
}
}
});
}
});
/*
* Rule: Don't use unqualified attribute selectors because they're just like universal selectors.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "unqualified-attributes",
name: "Disallow unqualified attribute selectors",
desc: "Unqualified attribute selectors are known to be slow.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
parser.addListener("startrule", function(event){
var selectors = event.selectors,
selector,
part,
modifier,
i, j, k;
for (i=0; i < selectors.length; i++){
selector = selectors[i];
part = selector.parts[selector.parts.length-1];
if (part.type == parser.SELECTOR_PART_TYPE){
for (k=0; k < part.modifiers.length; k++){
modifier = part.modifiers[k];
if (modifier.type == "attribute" && (!part.elementName || part.elementName == "*")){
reporter.report(rule.desc, part.line, part.col, rule);
}
}
}
}
});
}
});
/*
* Rule: When using a vendor-prefixed property, make sure to
* include the standard one.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "vendor-prefix",
name: "Require standard property with vendor prefix",
desc: "When using a vendor-prefixed property, make sure to include the standard one.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
properties,
num,
propertiesToCheck = {
"-webkit-border-radius": "border-radius",
"-webkit-border-top-left-radius": "border-top-left-radius",
"-webkit-border-top-right-radius": "border-top-right-radius",
"-webkit-border-bottom-left-radius": "border-bottom-left-radius",
"-webkit-border-bottom-right-radius": "border-bottom-right-radius",
"-o-border-radius": "border-radius",
"-o-border-top-left-radius": "border-top-left-radius",
"-o-border-top-right-radius": "border-top-right-radius",
"-o-border-bottom-left-radius": "border-bottom-left-radius",
"-o-border-bottom-right-radius": "border-bottom-right-radius",
"-moz-border-radius": "border-radius",
"-moz-border-radius-topleft": "border-top-left-radius",
"-moz-border-radius-topright": "border-top-right-radius",
"-moz-border-radius-bottomleft": "border-bottom-left-radius",
"-moz-border-radius-bottomright": "border-bottom-right-radius",
"-moz-column-count": "column-count",
"-webkit-column-count": "column-count",
"-moz-column-gap": "column-gap",
"-webkit-column-gap": "column-gap",
"-moz-column-rule": "column-rule",
"-webkit-column-rule": "column-rule",
"-moz-column-rule-style": "column-rule-style",
"-webkit-column-rule-style": "column-rule-style",
"-moz-column-rule-color": "column-rule-color",
"-webkit-column-rule-color": "column-rule-color",
"-moz-column-rule-width": "column-rule-width",
"-webkit-column-rule-width": "column-rule-width",
"-moz-column-width": "column-width",
"-webkit-column-width": "column-width",
"-webkit-column-span": "column-span",
"-webkit-columns": "columns",
"-moz-box-shadow": "box-shadow",
"-webkit-box-shadow": "box-shadow",
"-moz-transform" : "transform",
"-webkit-transform" : "transform",
"-o-transform" : "transform",
"-ms-transform" : "transform",
"-moz-transform-origin" : "transform-origin",
"-webkit-transform-origin" : "transform-origin",
"-o-transform-origin" : "transform-origin",
"-ms-transform-origin" : "transform-origin",
"-moz-box-sizing" : "box-sizing",
"-webkit-box-sizing" : "box-sizing",
"-moz-user-select" : "user-select",
"-khtml-user-select" : "user-select",
"-webkit-user-select" : "user-select"
};
//event handler for beginning of rules
function startRule(){
properties = {};
num=1;
}
//event handler for end of rules
function endRule(event){
var prop,
i, len,
standard,
needed,
actual,
needsStandard = [];
for (prop in properties){
if (propertiesToCheck[prop]){
needsStandard.push({ actual: prop, needed: propertiesToCheck[prop]});
}
}
for (i=0, len=needsStandard.length; i < len; i++){
needed = needsStandard[i].needed;
actual = needsStandard[i].actual;
if (!properties[needed]){
reporter.report("Missing standard property '" + needed + "' to go along with '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
} else {
//make sure standard property is last
if (properties[needed][0].pos < properties[actual][0].pos){
reporter.report("Standard property '" + needed + "' should come after vendor-prefixed property '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
}
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("property", function(event){
var name = event.property.text.toLowerCase();
if (!properties[name]){
properties[name] = [];
}
properties[name].push({ name: event.property, value : event.value, pos:num++ });
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
parser.addListener("endpage", endRule);
parser.addListener("endpagemargin", endRule);
parser.addListener("endkeyframerule", endRule);
}
});
/*
* Rule: You don't need to specify units when a value is 0.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "zero-units",
name: "Disallow units for 0 values",
desc: "You don't need to specify units when a value is 0.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
//count how many times "float" is used
parser.addListener("property", function(event){
var parts = event.value.parts,
i = 0,
len = parts.length;
while(i < len){
if ((parts[i].units || parts[i].type == "percentage") && parts[i].value === 0 && parts[i].type != "time"){
reporter.report("Values of 0 shouldn't have units specified.", parts[i].line, parts[i].col, rule);
}
i++;
}
});
}
});
/*global CSSLint*/
(function() {
/**
* Replace special characters before write to output.
*
* Rules:
* - single quotes is the escape sequence for double-quotes
* - & is the escape sequence for &
* - < is the escape sequence for <
* - > is the escape sequence for >
*
* @param {String} message to escape
* @return escaped message as {String}
*/
var xmlEscape = function(str) {
if (!str || str.constructor !== String) {
return "";
}
return str.replace(/[\"&><]/g, function(match) {
switch (match) {
case "\"":
return """;
case "&":
return "&";
case "<":
return "<";
case ">":
return ">";
}
});
};
CSSLint.addFormatter({
//format information
id: "checkstyle-xml",
name: "Checkstyle XML format",
/**
* Return opening root XML tag.
* @return {String} to prepend before all results
*/
startFormat: function(){
return "";
},
/**
* Return closing root XML tag.
* @return {String} to append after all results
*/
endFormat: function(){
return "";
},
/**
* Returns message when there is a file read error.
* @param {String} filename The name of the file that caused the error.
* @param {String} message The error message
* @return {String} The error message.
*/
readError: function(filename, message) {
return "";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (UNUSED for now) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = [];
/**
* Generate a source string for a rule.
* Checkstyle source strings usually resemble Java class names e.g
* net.csslint.SomeRuleName
* @param {Object} rule
* @return rule source as {String}
*/
var generateSource = function(rule) {
if (!rule || !('name' in rule)) {
return "";
}
return 'net.csslint.' + rule.name.replace(/\s/g,'');
};
if (messages.length > 0) {
output.push("");
CSSLint.Util.forEach(messages, function (message, i) {
//ignore rollups for now
if (!message.rollup) {
output.push("");
}
});
output.push("");
}
return output.join("");
}
});
}());
/*global CSSLint*/
CSSLint.addFormatter({
//format information
id: "compact",
name: "Compact, 'porcelain' format",
/**
* Return content to be printed before all file results.
* @return {String} to prepend before all results
*/
startFormat: function() {
return "";
},
/**
* Return content to be printed after all file results.
* @return {String} to append after all results
*/
endFormat: function() {
return "";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (Optional) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = "";
options = options || {};
/**
* Capitalize and return given string.
* @param str {String} to capitalize
* @return {String} capitalized
*/
var capitalize = function(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
};
if (messages.length === 0) {
return options.quiet ? "" : filename + ": Lint Free!";
}
CSSLint.Util.forEach(messages, function(message, i) {
if (message.rollup) {
output += filename + ": " + capitalize(message.type) + " - " + message.message + "\n";
} else {
output += filename + ": " + "line " + message.line +
", col " + message.col + ", " + capitalize(message.type) + " - " + message.message + "\n";
}
});
return output;
}
});
/*global CSSLint*/
CSSLint.addFormatter({
//format information
id: "csslint-xml",
name: "CSSLint XML format",
/**
* Return opening root XML tag.
* @return {String} to prepend before all results
*/
startFormat: function(){
return "";
},
/**
* Return closing root XML tag.
* @return {String} to append after all results
*/
endFormat: function(){
return "";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (UNUSED for now) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = [];
/**
* Replace special characters before write to output.
*
* Rules:
* - single quotes is the escape sequence for double-quotes
* - & is the escape sequence for &
* - < is the escape sequence for <
* - > is the escape sequence for >
*
* @param {String} message to escape
* @return escaped message as {String}
*/
var escapeSpecialCharacters = function(str) {
if (!str || str.constructor !== String) {
return "";
}
return str.replace(/\"/g, "'").replace(/&/g, "&").replace(//g, ">");
};
if (messages.length > 0) {
output.push("");
CSSLint.Util.forEach(messages, function (message, i) {
if (message.rollup) {
output.push("");
} else {
output.push("");
}
});
output.push("");
}
return output.join("");
}
});
/*global CSSLint*/
CSSLint.addFormatter({
//format information
id: "junit-xml",
name: "JUNIT XML format",
/**
* Return opening root XML tag.
* @return {String} to prepend before all results
*/
startFormat: function(){
return "";
},
/**
* Return closing root XML tag.
* @return {String} to append after all results
*/
endFormat: function() {
return "";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (UNUSED for now) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = [],
tests = {
'error': 0,
'failure': 0
};
/**
* Generate a source string for a rule.
* JUNIT source strings usually resemble Java class names e.g
* net.csslint.SomeRuleName
* @param {Object} rule
* @return rule source as {String}
*/
var generateSource = function(rule) {
if (!rule || !('name' in rule)) {
return "";
}
return 'net.csslint.' + rule.name.replace(/\s/g,'');
};
/**
* Replace special characters before write to output.
*
* Rules:
* - single quotes is the escape sequence for double-quotes
* - < is the escape sequence for <
* - > is the escape sequence for >
*
* @param {String} message to escape
* @return escaped message as {String}
*/
var escapeSpecialCharacters = function(str) {
if (!str || str.constructor !== String) {
return "";
}
return str.replace(/\"/g, "'").replace(//g, ">");
};
if (messages.length > 0) {
messages.forEach(function (message, i) {
// since junit has no warning class
// all issues as errors
var type = message.type === 'warning' ? 'error' : message.type;
//ignore rollups for now
if (!message.rollup) {
// build the test case seperately, once joined
// we'll add it to a custom array filtered by type
output.push("");
output.push("<" + type + " message=\"" + escapeSpecialCharacters(message.message) + "\">" + type + ">");
output.push("");
tests[type] += 1;
}
});
output.unshift("");
output.push("");
}
return output.join("");
}
});
/*global CSSLint*/
CSSLint.addFormatter({
//format information
id: "lint-xml",
name: "Lint XML format",
/**
* Return opening root XML tag.
* @return {String} to prepend before all results
*/
startFormat: function(){
return "";
},
/**
* Return closing root XML tag.
* @return {String} to append after all results
*/
endFormat: function(){
return "";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (UNUSED for now) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = [];
/**
* Replace special characters before write to output.
*
* Rules:
* - single quotes is the escape sequence for double-quotes
* - & is the escape sequence for &
* - < is the escape sequence for <
* - > is the escape sequence for >
*
* @param {String} message to escape
* @return escaped message as {String}
*/
var escapeSpecialCharacters = function(str) {
if (!str || str.constructor !== String) {
return "";
}
return str.replace(/\"/g, "'").replace(/&/g, "&").replace(//g, ">");
};
if (messages.length > 0) {
output.push("");
CSSLint.Util.forEach(messages, function (message, i) {
if (message.rollup) {
output.push("");
} else {
output.push("");
}
});
output.push("");
}
return output.join("");
}
});
/*global CSSLint*/
CSSLint.addFormatter({
//format information
id: "text",
name: "Plain Text",
/**
* Return content to be printed before all file results.
* @return {String} to prepend before all results
*/
startFormat: function() {
return "";
},
/**
* Return content to be printed after all file results.
* @return {String} to append after all results
*/
endFormat: function() {
return "";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (Optional) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = "";
options = options || {};
if (messages.length === 0) {
return options.quiet ? "" : "\n\ncsslint: No errors in " + filename + ".";
}
output = "\n\ncsslint: There are " + messages.length + " problems in " + filename + ".";
var pos = filename.lastIndexOf("/"),
shortFilename = filename;
if (pos === -1){
pos = filename.lastIndexOf("\\");
}
if (pos > -1){
shortFilename = filename.substring(pos+1);
}
CSSLint.Util.forEach(messages, function (message, i) {
output = output + "\n\n" + shortFilename;
if (message.rollup) {
output += "\n" + (i+1) + ": " + message.type;
output += "\n" + message.message;
} else {
output += "\n" + (i+1) + ": " + message.type + " at line " + message.line + ", col " + message.col;
output += "\n" + message.message;
output += "\n" + message.evidence;
}
});
return output;
}
});
exports.CSSLint = CSSLint;
================================================
FILE: gulp/util/csslint/lib/parserlib.js
================================================
/*!
Parser-Lib
Copyright (c) 2009-2011 Nicholas C. Zakas. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* Version v0.2.5, Build time: 7-May-2014 03:37:38 */
var parserlib = {};
(function(){
/**
* A generic base to inherit from for any object
* that needs event handling.
* @class EventTarget
* @constructor
*/
function EventTarget(){
/**
* The array of listeners for various events.
* @type Object
* @property _listeners
* @private
*/
this._listeners = {};
}
EventTarget.prototype = {
//restore constructor
constructor: EventTarget,
/**
* Adds a listener for a given event type.
* @param {String} type The type of event to add a listener for.
* @param {Function} listener The function to call when the event occurs.
* @return {void}
* @method addListener
*/
addListener: function(type, listener){
if (!this._listeners[type]){
this._listeners[type] = [];
}
this._listeners[type].push(listener);
},
/**
* Fires an event based on the passed-in object.
* @param {Object|String} event An object with at least a 'type' attribute
* or a string indicating the event name.
* @return {void}
* @method fire
*/
fire: function(event){
if (typeof event == "string"){
event = { type: event };
}
if (typeof event.target != "undefined"){
event.target = this;
}
if (typeof event.type == "undefined"){
throw new Error("Event object missing 'type' property.");
}
if (this._listeners[event.type]){
//create a copy of the array and use that so listeners can't chane
var listeners = this._listeners[event.type].concat();
for (var i=0, len=listeners.length; i < len; i++){
listeners[i].call(this, event);
}
}
},
/**
* Removes a listener for a given event type.
* @param {String} type The type of event to remove a listener from.
* @param {Function} listener The function to remove from the event.
* @return {void}
* @method removeListener
*/
removeListener: function(type, listener){
if (this._listeners[type]){
var listeners = this._listeners[type];
for (var i=0, len=listeners.length; i < len; i++){
if (listeners[i] === listener){
listeners.splice(i, 1);
break;
}
}
}
}
};
/**
* Convenient way to read through strings.
* @namespace parserlib.util
* @class StringReader
* @constructor
* @param {String} text The text to read.
*/
function StringReader(text){
/**
* The input text with line endings normalized.
* @property _input
* @type String
* @private
*/
this._input = text.replace(/\n\r?/g, "\n");
/**
* The row for the character to be read next.
* @property _line
* @type int
* @private
*/
this._line = 1;
/**
* The column for the character to be read next.
* @property _col
* @type int
* @private
*/
this._col = 1;
/**
* The index of the character in the input to be read next.
* @property _cursor
* @type int
* @private
*/
this._cursor = 0;
}
StringReader.prototype = {
//restore constructor
constructor: StringReader,
//-------------------------------------------------------------------------
// Position info
//-------------------------------------------------------------------------
/**
* Returns the column of the character to be read next.
* @return {int} The column of the character to be read next.
* @method getCol
*/
getCol: function(){
return this._col;
},
/**
* Returns the row of the character to be read next.
* @return {int} The row of the character to be read next.
* @method getLine
*/
getLine: function(){
return this._line ;
},
/**
* Determines if you're at the end of the input.
* @return {Boolean} True if there's no more input, false otherwise.
* @method eof
*/
eof: function(){
return (this._cursor == this._input.length);
},
//-------------------------------------------------------------------------
// Basic reading
//-------------------------------------------------------------------------
/**
* Reads the next character without advancing the cursor.
* @param {int} count How many characters to look ahead (default is 1).
* @return {String} The next character or null if there is no next character.
* @method peek
*/
peek: function(count){
var c = null;
count = (typeof count == "undefined" ? 1 : count);
//if we're not at the end of the input...
if (this._cursor < this._input.length){
//get character and increment cursor and column
c = this._input.charAt(this._cursor + count - 1);
}
return c;
},
/**
* Reads the next character from the input and adjusts the row and column
* accordingly.
* @return {String} The next character or null if there is no next character.
* @method read
*/
read: function(){
var c = null;
//if we're not at the end of the input...
if (this._cursor < this._input.length){
//if the last character was a newline, increment row count
//and reset column count
if (this._input.charAt(this._cursor) == "\n"){
this._line++;
this._col=1;
} else {
this._col++;
}
//get character and increment cursor and column
c = this._input.charAt(this._cursor++);
}
return c;
},
//-------------------------------------------------------------------------
// Misc
//-------------------------------------------------------------------------
/**
* Saves the current location so it can be returned to later.
* @method mark
* @return {void}
*/
mark: function(){
this._bookmark = {
cursor: this._cursor,
line: this._line,
col: this._col
};
},
reset: function(){
if (this._bookmark){
this._cursor = this._bookmark.cursor;
this._line = this._bookmark.line;
this._col = this._bookmark.col;
delete this._bookmark;
}
},
//-------------------------------------------------------------------------
// Advanced reading
//-------------------------------------------------------------------------
/**
* Reads up to and including the given string. Throws an error if that
* string is not found.
* @param {String} pattern The string to read.
* @return {String} The string when it is found.
* @throws Error when the string pattern is not found.
* @method readTo
*/
readTo: function(pattern){
var buffer = "",
c;
/*
* First, buffer must be the same length as the pattern.
* Then, buffer must end with the pattern or else reach the
* end of the input.
*/
while (buffer.length < pattern.length || buffer.lastIndexOf(pattern) != buffer.length - pattern.length){
c = this.read();
if (c){
buffer += c;
} else {
throw new Error("Expected \"" + pattern + "\" at line " + this._line + ", col " + this._col + ".");
}
}
return buffer;
},
/**
* Reads characters while each character causes the given
* filter function to return true. The function is passed
* in each character and either returns true to continue
* reading or false to stop.
* @param {Function} filter The function to read on each character.
* @return {String} The string made up of all characters that passed the
* filter check.
* @method readWhile
*/
readWhile: function(filter){
var buffer = "",
c = this.read();
while(c !== null && filter(c)){
buffer += c;
c = this.read();
}
return buffer;
},
/**
* Reads characters that match either text or a regular expression and
* returns those characters. If a match is found, the row and column
* are adjusted; if no match is found, the reader's state is unchanged.
* reading or false to stop.
* @param {String|RegExp} matchter If a string, then the literal string
* value is searched for. If a regular expression, then any string
* matching the pattern is search for.
* @return {String} The string made up of all characters that matched or
* null if there was no match.
* @method readMatch
*/
readMatch: function(matcher){
var source = this._input.substring(this._cursor),
value = null;
//if it's a string, just do a straight match
if (typeof matcher == "string"){
if (source.indexOf(matcher) === 0){
value = this.readCount(matcher.length);
}
} else if (matcher instanceof RegExp){
if (matcher.test(source)){
value = this.readCount(RegExp.lastMatch.length);
}
}
return value;
},
/**
* Reads a given number of characters. If the end of the input is reached,
* it reads only the remaining characters and does not throw an error.
* @param {int} count The number of characters to read.
* @return {String} The string made up the read characters.
* @method readCount
*/
readCount: function(count){
var buffer = "";
while(count--){
buffer += this.read();
}
return buffer;
}
};
/**
* Type to use when a syntax error occurs.
* @class SyntaxError
* @namespace parserlib.util
* @constructor
* @param {String} message The error message.
* @param {int} line The line at which the error occurred.
* @param {int} col The column at which the error occurred.
*/
function SyntaxError(message, line, col){
/**
* The column at which the error occurred.
* @type int
* @property col
*/
this.col = col;
/**
* The line at which the error occurred.
* @type int
* @property line
*/
this.line = line;
/**
* The text representation of the unit.
* @type String
* @property text
*/
this.message = message;
}
//inherit from Error
SyntaxError.prototype = new Error();
/**
* Base type to represent a single syntactic unit.
* @class SyntaxUnit
* @namespace parserlib.util
* @constructor
* @param {String} text The text of the unit.
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
*/
function SyntaxUnit(text, line, col, type){
/**
* The column of text on which the unit resides.
* @type int
* @property col
*/
this.col = col;
/**
* The line of text on which the unit resides.
* @type int
* @property line
*/
this.line = line;
/**
* The text representation of the unit.
* @type String
* @property text
*/
this.text = text;
/**
* The type of syntax unit.
* @type int
* @property type
*/
this.type = type;
}
/**
* Create a new syntax unit based solely on the given token.
* Convenience method for creating a new syntax unit when
* it represents a single token instead of multiple.
* @param {Object} token The token object to represent.
* @return {parserlib.util.SyntaxUnit} The object representing the token.
* @static
* @method fromToken
*/
SyntaxUnit.fromToken = function(token){
return new SyntaxUnit(token.value, token.startLine, token.startCol);
};
SyntaxUnit.prototype = {
//restore constructor
constructor: SyntaxUnit,
/**
* Returns the text representation of the unit.
* @return {String} The text representation of the unit.
* @method valueOf
*/
valueOf: function(){
return this.toString();
},
/**
* Returns the text representation of the unit.
* @return {String} The text representation of the unit.
* @method toString
*/
toString: function(){
return this.text;
}
};
/*global StringReader, SyntaxError*/
/**
* Generic TokenStream providing base functionality.
* @class TokenStreamBase
* @namespace parserlib.util
* @constructor
* @param {String|StringReader} input The text to tokenize or a reader from
* which to read the input.
*/
function TokenStreamBase(input, tokenData){
/**
* The string reader for easy access to the text.
* @type StringReader
* @property _reader
* @private
*/
this._reader = input ? new StringReader(input.toString()) : null;
/**
* Token object for the last consumed token.
* @type Token
* @property _token
* @private
*/
this._token = null;
/**
* The array of token information.
* @type Array
* @property _tokenData
* @private
*/
this._tokenData = tokenData;
/**
* Lookahead token buffer.
* @type Array
* @property _lt
* @private
*/
this._lt = [];
/**
* Lookahead token buffer index.
* @type int
* @property _ltIndex
* @private
*/
this._ltIndex = 0;
this._ltIndexCache = [];
}
/**
* Accepts an array of token information and outputs
* an array of token data containing key-value mappings
* and matching functions that the TokenStream needs.
* @param {Array} tokens An array of token descriptors.
* @return {Array} An array of processed token data.
* @method createTokenData
* @static
*/
TokenStreamBase.createTokenData = function(tokens){
var nameMap = [],
typeMap = {},
tokenData = tokens.concat([]),
i = 0,
len = tokenData.length+1;
tokenData.UNKNOWN = -1;
tokenData.unshift({name:"EOF"});
for (; i < len; i++){
nameMap.push(tokenData[i].name);
tokenData[tokenData[i].name] = i;
if (tokenData[i].text){
typeMap[tokenData[i].text] = i;
}
}
tokenData.name = function(tt){
return nameMap[tt];
};
tokenData.type = function(c){
return typeMap[c];
};
return tokenData;
};
TokenStreamBase.prototype = {
//restore constructor
constructor: TokenStreamBase,
//-------------------------------------------------------------------------
// Matching methods
//-------------------------------------------------------------------------
/**
* Determines if the next token matches the given token type.
* If so, that token is consumed; if not, the token is placed
* back onto the token stream. You can pass in any number of
* token types and this will return true if any of the token
* types is found.
* @param {int|int[]} tokenTypes Either a single token type or an array of
* token types that the next token might be. If an array is passed,
* it's assumed that the token can be any of these.
* @param {variant} channel (Optional) The channel to read from. If not
* provided, reads from the default (unnamed) channel.
* @return {Boolean} True if the token type matches, false if not.
* @method match
*/
match: function(tokenTypes, channel){
//always convert to an array, makes things easier
if (!(tokenTypes instanceof Array)){
tokenTypes = [tokenTypes];
}
var tt = this.get(channel),
i = 0,
len = tokenTypes.length;
while(i < len){
if (tt == tokenTypes[i++]){
return true;
}
}
//no match found, put the token back
this.unget();
return false;
},
/**
* Determines if the next token matches the given token type.
* If so, that token is consumed; if not, an error is thrown.
* @param {int|int[]} tokenTypes Either a single token type or an array of
* token types that the next token should be. If an array is passed,
* it's assumed that the token must be one of these.
* @param {variant} channel (Optional) The channel to read from. If not
* provided, reads from the default (unnamed) channel.
* @return {void}
* @method mustMatch
*/
mustMatch: function(tokenTypes, channel){
var token;
//always convert to an array, makes things easier
if (!(tokenTypes instanceof Array)){
tokenTypes = [tokenTypes];
}
if (!this.match.apply(this, arguments)){
token = this.LT(1);
throw new SyntaxError("Expected " + this._tokenData[tokenTypes[0]].name +
" at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
}
},
//-------------------------------------------------------------------------
// Consuming methods
//-------------------------------------------------------------------------
/**
* Keeps reading from the token stream until either one of the specified
* token types is found or until the end of the input is reached.
* @param {int|int[]} tokenTypes Either a single token type or an array of
* token types that the next token should be. If an array is passed,
* it's assumed that the token must be one of these.
* @param {variant} channel (Optional) The channel to read from. If not
* provided, reads from the default (unnamed) channel.
* @return {void}
* @method advance
*/
advance: function(tokenTypes, channel){
while(this.LA(0) !== 0 && !this.match(tokenTypes, channel)){
this.get();
}
return this.LA(0);
},
/**
* Consumes the next token from the token stream.
* @return {int} The token type of the token that was just consumed.
* @method get
*/
get: function(channel){
var tokenInfo = this._tokenData,
reader = this._reader,
value,
i =0,
len = tokenInfo.length,
found = false,
token,
info;
//check the lookahead buffer first
if (this._lt.length && this._ltIndex >= 0 && this._ltIndex < this._lt.length){
i++;
this._token = this._lt[this._ltIndex++];
info = tokenInfo[this._token.type];
//obey channels logic
while((info.channel !== undefined && channel !== info.channel) &&
this._ltIndex < this._lt.length){
this._token = this._lt[this._ltIndex++];
info = tokenInfo[this._token.type];
i++;
}
//here be dragons
if ((info.channel === undefined || channel === info.channel) &&
this._ltIndex <= this._lt.length){
this._ltIndexCache.push(i);
return this._token.type;
}
}
//call token retriever method
token = this._getToken();
//if it should be hidden, don't save a token
if (token.type > -1 && !tokenInfo[token.type].hide){
//apply token channel
token.channel = tokenInfo[token.type].channel;
//save for later
this._token = token;
this._lt.push(token);
//save space that will be moved (must be done before array is truncated)
this._ltIndexCache.push(this._lt.length - this._ltIndex + i);
//keep the buffer under 5 items
if (this._lt.length > 5){
this._lt.shift();
}
//also keep the shift buffer under 5 items
if (this._ltIndexCache.length > 5){
this._ltIndexCache.shift();
}
//update lookahead index
this._ltIndex = this._lt.length;
}
/*
* Skip to the next token if:
* 1. The token type is marked as hidden.
* 2. The token type has a channel specified and it isn't the current channel.
*/
info = tokenInfo[token.type];
if (info &&
(info.hide ||
(info.channel !== undefined && channel !== info.channel))){
return this.get(channel);
} else {
//return just the type
return token.type;
}
},
/**
* Looks ahead a certain number of tokens and returns the token type at
* that position. This will throw an error if you lookahead past the
* end of input, past the size of the lookahead buffer, or back past
* the first token in the lookahead buffer.
* @param {int} The index of the token type to retrieve. 0 for the
* current token, 1 for the next, -1 for the previous, etc.
* @return {int} The token type of the token in the given position.
* @method LA
*/
LA: function(index){
var total = index,
tt;
if (index > 0){
//TODO: Store 5 somewhere
if (index > 5){
throw new Error("Too much lookahead.");
}
//get all those tokens
while(total){
tt = this.get();
total--;
}
//unget all those tokens
while(total < index){
this.unget();
total++;
}
} else if (index < 0){
if(this._lt[this._ltIndex+index]){
tt = this._lt[this._ltIndex+index].type;
} else {
throw new Error("Too much lookbehind.");
}
} else {
tt = this._token.type;
}
return tt;
},
/**
* Looks ahead a certain number of tokens and returns the token at
* that position. This will throw an error if you lookahead past the
* end of input, past the size of the lookahead buffer, or back past
* the first token in the lookahead buffer.
* @param {int} The index of the token type to retrieve. 0 for the
* current token, 1 for the next, -1 for the previous, etc.
* @return {Object} The token of the token in the given position.
* @method LA
*/
LT: function(index){
//lookahead first to prime the token buffer
this.LA(index);
//now find the token, subtract one because _ltIndex is already at the next index
return this._lt[this._ltIndex+index-1];
},
/**
* Returns the token type for the next token in the stream without
* consuming it.
* @return {int} The token type of the next token in the stream.
* @method peek
*/
peek: function(){
return this.LA(1);
},
/**
* Returns the actual token object for the last consumed token.
* @return {Token} The token object for the last consumed token.
* @method token
*/
token: function(){
return this._token;
},
/**
* Returns the name of the token for the given token type.
* @param {int} tokenType The type of token to get the name of.
* @return {String} The name of the token or "UNKNOWN_TOKEN" for any
* invalid token type.
* @method tokenName
*/
tokenName: function(tokenType){
if (tokenType < 0 || tokenType > this._tokenData.length){
return "UNKNOWN_TOKEN";
} else {
return this._tokenData[tokenType].name;
}
},
/**
* Returns the token type value for the given token name.
* @param {String} tokenName The name of the token whose value should be returned.
* @return {int} The token type value for the given token name or -1
* for an unknown token.
* @method tokenName
*/
tokenType: function(tokenName){
return this._tokenData[tokenName] || -1;
},
/**
* Returns the last consumed token to the token stream.
* @method unget
*/
unget: function(){
//if (this._ltIndex > -1){
if (this._ltIndexCache.length){
this._ltIndex -= this._ltIndexCache.pop();//--;
this._token = this._lt[this._ltIndex - 1];
} else {
throw new Error("Too much lookahead.");
}
}
};
parserlib.util = {
StringReader: StringReader,
SyntaxError : SyntaxError,
SyntaxUnit : SyntaxUnit,
EventTarget : EventTarget,
TokenStreamBase : TokenStreamBase
};
})();
/*
Parser-Lib
Copyright (c) 2009-2011 Nicholas C. Zakas. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* Version v0.2.5, Build time: 7-May-2014 03:37:38 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
StringReader = parserlib.util.StringReader,
SyntaxError = parserlib.util.SyntaxError,
SyntaxUnit = parserlib.util.SyntaxUnit;
var Colors = {
aliceblue :"#f0f8ff",
antiquewhite :"#faebd7",
aqua :"#00ffff",
aquamarine :"#7fffd4",
azure :"#f0ffff",
beige :"#f5f5dc",
bisque :"#ffe4c4",
black :"#000000",
blanchedalmond :"#ffebcd",
blue :"#0000ff",
blueviolet :"#8a2be2",
brown :"#a52a2a",
burlywood :"#deb887",
cadetblue :"#5f9ea0",
chartreuse :"#7fff00",
chocolate :"#d2691e",
coral :"#ff7f50",
cornflowerblue :"#6495ed",
cornsilk :"#fff8dc",
crimson :"#dc143c",
cyan :"#00ffff",
darkblue :"#00008b",
darkcyan :"#008b8b",
darkgoldenrod :"#b8860b",
darkgray :"#a9a9a9",
darkgrey :"#a9a9a9",
darkgreen :"#006400",
darkkhaki :"#bdb76b",
darkmagenta :"#8b008b",
darkolivegreen :"#556b2f",
darkorange :"#ff8c00",
darkorchid :"#9932cc",
darkred :"#8b0000",
darksalmon :"#e9967a",
darkseagreen :"#8fbc8f",
darkslateblue :"#483d8b",
darkslategray :"#2f4f4f",
darkslategrey :"#2f4f4f",
darkturquoise :"#00ced1",
darkviolet :"#9400d3",
deeppink :"#ff1493",
deepskyblue :"#00bfff",
dimgray :"#696969",
dimgrey :"#696969",
dodgerblue :"#1e90ff",
firebrick :"#b22222",
floralwhite :"#fffaf0",
forestgreen :"#228b22",
fuchsia :"#ff00ff",
gainsboro :"#dcdcdc",
ghostwhite :"#f8f8ff",
gold :"#ffd700",
goldenrod :"#daa520",
gray :"#808080",
grey :"#808080",
green :"#008000",
greenyellow :"#adff2f",
honeydew :"#f0fff0",
hotpink :"#ff69b4",
indianred :"#cd5c5c",
indigo :"#4b0082",
ivory :"#fffff0",
khaki :"#f0e68c",
lavender :"#e6e6fa",
lavenderblush :"#fff0f5",
lawngreen :"#7cfc00",
lemonchiffon :"#fffacd",
lightblue :"#add8e6",
lightcoral :"#f08080",
lightcyan :"#e0ffff",
lightgoldenrodyellow :"#fafad2",
lightgray :"#d3d3d3",
lightgrey :"#d3d3d3",
lightgreen :"#90ee90",
lightpink :"#ffb6c1",
lightsalmon :"#ffa07a",
lightseagreen :"#20b2aa",
lightskyblue :"#87cefa",
lightslategray :"#778899",
lightslategrey :"#778899",
lightsteelblue :"#b0c4de",
lightyellow :"#ffffe0",
lime :"#00ff00",
limegreen :"#32cd32",
linen :"#faf0e6",
magenta :"#ff00ff",
maroon :"#800000",
mediumaquamarine:"#66cdaa",
mediumblue :"#0000cd",
mediumorchid :"#ba55d3",
mediumpurple :"#9370d8",
mediumseagreen :"#3cb371",
mediumslateblue :"#7b68ee",
mediumspringgreen :"#00fa9a",
mediumturquoise :"#48d1cc",
mediumvioletred :"#c71585",
midnightblue :"#191970",
mintcream :"#f5fffa",
mistyrose :"#ffe4e1",
moccasin :"#ffe4b5",
navajowhite :"#ffdead",
navy :"#000080",
oldlace :"#fdf5e6",
olive :"#808000",
olivedrab :"#6b8e23",
orange :"#ffa500",
orangered :"#ff4500",
orchid :"#da70d6",
palegoldenrod :"#eee8aa",
palegreen :"#98fb98",
paleturquoise :"#afeeee",
palevioletred :"#d87093",
papayawhip :"#ffefd5",
peachpuff :"#ffdab9",
peru :"#cd853f",
pink :"#ffc0cb",
plum :"#dda0dd",
powderblue :"#b0e0e6",
purple :"#800080",
red :"#ff0000",
rosybrown :"#bc8f8f",
royalblue :"#4169e1",
saddlebrown :"#8b4513",
salmon :"#fa8072",
sandybrown :"#f4a460",
seagreen :"#2e8b57",
seashell :"#fff5ee",
sienna :"#a0522d",
silver :"#c0c0c0",
skyblue :"#87ceeb",
slateblue :"#6a5acd",
slategray :"#708090",
slategrey :"#708090",
snow :"#fffafa",
springgreen :"#00ff7f",
steelblue :"#4682b4",
tan :"#d2b48c",
teal :"#008080",
thistle :"#d8bfd8",
tomato :"#ff6347",
turquoise :"#40e0d0",
violet :"#ee82ee",
wheat :"#f5deb3",
white :"#ffffff",
whitesmoke :"#f5f5f5",
yellow :"#ffff00",
yellowgreen :"#9acd32",
//CSS2 system colors http://www.w3.org/TR/css3-color/#css2-system
activeBorder :"Active window border.",
activecaption :"Active window caption.",
appworkspace :"Background color of multiple document interface.",
background :"Desktop background.",
buttonface :"The face background color for 3-D elements that appear 3-D due to one layer of surrounding border.",
buttonhighlight :"The color of the border facing the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
buttonshadow :"The color of the border away from the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
buttontext :"Text on push buttons.",
captiontext :"Text in caption, size box, and scrollbar arrow box.",
graytext :"Grayed (disabled) text. This color is set to #000 if the current display driver does not support a solid gray color.",
greytext :"Greyed (disabled) text. This color is set to #000 if the current display driver does not support a solid grey color.",
highlight :"Item(s) selected in a control.",
highlighttext :"Text of item(s) selected in a control.",
inactiveborder :"Inactive window border.",
inactivecaption :"Inactive window caption.",
inactivecaptiontext :"Color of text in an inactive caption.",
infobackground :"Background color for tooltip controls.",
infotext :"Text color for tooltip controls.",
menu :"Menu background.",
menutext :"Text in menus.",
scrollbar :"Scroll bar gray area.",
threeddarkshadow :"The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
threedface :"The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
threedhighlight :"The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
threedlightshadow :"The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
threedshadow :"The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
window :"Window background.",
windowframe :"Window frame.",
windowtext :"Text in windows."
};
/*global SyntaxUnit, Parser*/
/**
* Represents a selector combinator (whitespace, +, >).
* @namespace parserlib.css
* @class Combinator
* @extends parserlib.util.SyntaxUnit
* @constructor
* @param {String} text The text representation of the unit.
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
*/
function Combinator(text, line, col){
SyntaxUnit.call(this, text, line, col, Parser.COMBINATOR_TYPE);
/**
* The type of modifier.
* @type String
* @property type
*/
this.type = "unknown";
//pretty simple
if (/^\s+$/.test(text)){
this.type = "descendant";
} else if (text == ">"){
this.type = "child";
} else if (text == "+"){
this.type = "adjacent-sibling";
} else if (text == "~"){
this.type = "sibling";
}
}
Combinator.prototype = new SyntaxUnit();
Combinator.prototype.constructor = Combinator;
/*global SyntaxUnit, Parser*/
/**
* Represents a media feature, such as max-width:500.
* @namespace parserlib.css
* @class MediaFeature
* @extends parserlib.util.SyntaxUnit
* @constructor
* @param {SyntaxUnit} name The name of the feature.
* @param {SyntaxUnit} value The value of the feature or null if none.
*/
function MediaFeature(name, value){
SyntaxUnit.call(this, "(" + name + (value !== null ? ":" + value : "") + ")", name.startLine, name.startCol, Parser.MEDIA_FEATURE_TYPE);
/**
* The name of the media feature
* @type String
* @property name
*/
this.name = name;
/**
* The value for the feature or null if there is none.
* @type SyntaxUnit
* @property value
*/
this.value = value;
}
MediaFeature.prototype = new SyntaxUnit();
MediaFeature.prototype.constructor = MediaFeature;
/*global SyntaxUnit, Parser*/
/**
* Represents an individual media query.
* @namespace parserlib.css
* @class MediaQuery
* @extends parserlib.util.SyntaxUnit
* @constructor
* @param {String} modifier The modifier "not" or "only" (or null).
* @param {String} mediaType The type of media (i.e., "print").
* @param {Array} parts Array of selectors parts making up this selector.
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
*/
function MediaQuery(modifier, mediaType, features, line, col){
SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
/**
* The media modifier ("not" or "only")
* @type String
* @property modifier
*/
this.modifier = modifier;
/**
* The mediaType (i.e., "print")
* @type String
* @property mediaType
*/
this.mediaType = mediaType;
/**
* The parts that make up the selector.
* @type Array
* @property features
*/
this.features = features;
}
MediaQuery.prototype = new SyntaxUnit();
MediaQuery.prototype.constructor = MediaQuery;
/*global Tokens, TokenStream, SyntaxError, Properties, Validation, ValidationError, SyntaxUnit,
PropertyValue, PropertyValuePart, SelectorPart, SelectorSubPart, Selector,
PropertyName, Combinator, MediaFeature, MediaQuery, EventTarget */
/**
* A CSS3 parser.
* @namespace parserlib.css
* @class Parser
* @constructor
* @param {Object} options (Optional) Various options for the parser:
* starHack (true|false) to allow IE6 star hack as valid,
* underscoreHack (true|false) to interpret leading underscores
* as IE6-7 targeting for known properties, ieFilters (true|false)
* to indicate that IE < 8 filters should be accepted and not throw
* syntax errors.
*/
function Parser(options){
//inherit event functionality
EventTarget.call(this);
this.options = options || {};
this._tokenStream = null;
}
//Static constants
Parser.DEFAULT_TYPE = 0;
Parser.COMBINATOR_TYPE = 1;
Parser.MEDIA_FEATURE_TYPE = 2;
Parser.MEDIA_QUERY_TYPE = 3;
Parser.PROPERTY_NAME_TYPE = 4;
Parser.PROPERTY_VALUE_TYPE = 5;
Parser.PROPERTY_VALUE_PART_TYPE = 6;
Parser.SELECTOR_TYPE = 7;
Parser.SELECTOR_PART_TYPE = 8;
Parser.SELECTOR_SUB_PART_TYPE = 9;
Parser.prototype = function(){
var proto = new EventTarget(), //new prototype
prop,
additions = {
//restore constructor
constructor: Parser,
//instance constants - yuck
DEFAULT_TYPE : 0,
COMBINATOR_TYPE : 1,
MEDIA_FEATURE_TYPE : 2,
MEDIA_QUERY_TYPE : 3,
PROPERTY_NAME_TYPE : 4,
PROPERTY_VALUE_TYPE : 5,
PROPERTY_VALUE_PART_TYPE : 6,
SELECTOR_TYPE : 7,
SELECTOR_PART_TYPE : 8,
SELECTOR_SUB_PART_TYPE : 9,
//-----------------------------------------------------------------
// Grammar
//-----------------------------------------------------------------
_stylesheet: function(){
/*
* stylesheet
* : [ CHARSET_SYM S* STRING S* ';' ]?
* [S|CDO|CDC]* [ import [S|CDO|CDC]* ]*
* [ namespace [S|CDO|CDC]* ]*
* [ [ ruleset | media | page | font_face | keyframes ] [S|CDO|CDC]* ]*
* ;
*/
var tokenStream = this._tokenStream,
charset = null,
count,
token,
tt;
this.fire("startstylesheet");
//try to read character set
this._charset();
this._skipCruft();
//try to read imports - may be more than one
while (tokenStream.peek() == Tokens.IMPORT_SYM){
this._import();
this._skipCruft();
}
//try to read namespaces - may be more than one
while (tokenStream.peek() == Tokens.NAMESPACE_SYM){
this._namespace();
this._skipCruft();
}
//get the next token
tt = tokenStream.peek();
//try to read the rest
while(tt > Tokens.EOF){
try {
switch(tt){
case Tokens.MEDIA_SYM:
this._media();
this._skipCruft();
break;
case Tokens.PAGE_SYM:
this._page();
this._skipCruft();
break;
case Tokens.FONT_FACE_SYM:
this._font_face();
this._skipCruft();
break;
case Tokens.KEYFRAMES_SYM:
this._keyframes();
this._skipCruft();
break;
case Tokens.VIEWPORT_SYM:
this._viewport();
this._skipCruft();
break;
case Tokens.UNKNOWN_SYM: //unknown @ rule
tokenStream.get();
if (!this.options.strict){
//fire error event
this.fire({
type: "error",
error: null,
message: "Unknown @ rule: " + tokenStream.LT(0).value + ".",
line: tokenStream.LT(0).startLine,
col: tokenStream.LT(0).startCol
});
//skip braces
count=0;
while (tokenStream.advance([Tokens.LBRACE, Tokens.RBRACE]) == Tokens.LBRACE){
count++; //keep track of nesting depth
}
while(count){
tokenStream.advance([Tokens.RBRACE]);
count--;
}
} else {
//not a syntax error, rethrow it
throw new SyntaxError("Unknown @ rule.", tokenStream.LT(0).startLine, tokenStream.LT(0).startCol);
}
break;
case Tokens.S:
this._readWhitespace();
break;
default:
if(!this._ruleset()){
//error handling for known issues
switch(tt){
case Tokens.CHARSET_SYM:
token = tokenStream.LT(1);
this._charset(false);
throw new SyntaxError("@charset not allowed here.", token.startLine, token.startCol);
case Tokens.IMPORT_SYM:
token = tokenStream.LT(1);
this._import(false);
throw new SyntaxError("@import not allowed here.", token.startLine, token.startCol);
case Tokens.NAMESPACE_SYM:
token = tokenStream.LT(1);
this._namespace(false);
throw new SyntaxError("@namespace not allowed here.", token.startLine, token.startCol);
default:
tokenStream.get(); //get the last token
this._unexpectedToken(tokenStream.token());
}
}
}
} catch(ex) {
if (ex instanceof SyntaxError && !this.options.strict){
this.fire({
type: "error",
error: ex,
message: ex.message,
line: ex.line,
col: ex.col
});
} else {
throw ex;
}
}
tt = tokenStream.peek();
}
if (tt != Tokens.EOF){
this._unexpectedToken(tokenStream.token());
}
this.fire("endstylesheet");
},
_charset: function(emit){
var tokenStream = this._tokenStream,
charset,
token,
line,
col;
if (tokenStream.match(Tokens.CHARSET_SYM)){
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
tokenStream.mustMatch(Tokens.STRING);
token = tokenStream.token();
charset = token.value;
this._readWhitespace();
tokenStream.mustMatch(Tokens.SEMICOLON);
if (emit !== false){
this.fire({
type: "charset",
charset:charset,
line: line,
col: col
});
}
}
},
_import: function(emit){
/*
* import
* : IMPORT_SYM S*
* [STRING|URI] S* media_query_list? ';' S*
*/
var tokenStream = this._tokenStream,
tt,
uri,
importToken,
mediaList = [];
//read import symbol
tokenStream.mustMatch(Tokens.IMPORT_SYM);
importToken = tokenStream.token();
this._readWhitespace();
tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
//grab the URI value
uri = tokenStream.token().value.replace(/^(?:url\()?["']?([^"']+?)["']?\)?$/, "$1");
this._readWhitespace();
mediaList = this._media_query_list();
//must end with a semicolon
tokenStream.mustMatch(Tokens.SEMICOLON);
this._readWhitespace();
if (emit !== false){
this.fire({
type: "import",
uri: uri,
media: mediaList,
line: importToken.startLine,
col: importToken.startCol
});
}
},
_namespace: function(emit){
/*
* namespace
* : NAMESPACE_SYM S* [namespace_prefix S*]? [STRING|URI] S* ';' S*
*/
var tokenStream = this._tokenStream,
line,
col,
prefix,
uri;
//read import symbol
tokenStream.mustMatch(Tokens.NAMESPACE_SYM);
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
//it's a namespace prefix - no _namespace_prefix() method because it's just an IDENT
if (tokenStream.match(Tokens.IDENT)){
prefix = tokenStream.token().value;
this._readWhitespace();
}
tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
/*if (!tokenStream.match(Tokens.STRING)){
tokenStream.mustMatch(Tokens.URI);
}*/
//grab the URI value
uri = tokenStream.token().value.replace(/(?:url\()?["']([^"']+)["']\)?/, "$1");
this._readWhitespace();
//must end with a semicolon
tokenStream.mustMatch(Tokens.SEMICOLON);
this._readWhitespace();
if (emit !== false){
this.fire({
type: "namespace",
prefix: prefix,
uri: uri,
line: line,
col: col
});
}
},
_media: function(){
/*
* media
* : MEDIA_SYM S* media_query_list S* '{' S* ruleset* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
line,
col,
mediaList;// = [];
//look for @media
tokenStream.mustMatch(Tokens.MEDIA_SYM);
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
mediaList = this._media_query_list();
tokenStream.mustMatch(Tokens.LBRACE);
this._readWhitespace();
this.fire({
type: "startmedia",
media: mediaList,
line: line,
col: col
});
while(true) {
if (tokenStream.peek() == Tokens.PAGE_SYM){
this._page();
} else if (tokenStream.peek() == Tokens.FONT_FACE_SYM){
this._font_face();
} else if (tokenStream.peek() == Tokens.VIEWPORT_SYM){
this._viewport();
} else if (!this._ruleset()){
break;
}
}
tokenStream.mustMatch(Tokens.RBRACE);
this._readWhitespace();
this.fire({
type: "endmedia",
media: mediaList,
line: line,
col: col
});
},
//CSS3 Media Queries
_media_query_list: function(){
/*
* media_query_list
* : S* [media_query [ ',' S* media_query ]* ]?
* ;
*/
var tokenStream = this._tokenStream,
mediaList = [];
this._readWhitespace();
if (tokenStream.peek() == Tokens.IDENT || tokenStream.peek() == Tokens.LPAREN){
mediaList.push(this._media_query());
}
while(tokenStream.match(Tokens.COMMA)){
this._readWhitespace();
mediaList.push(this._media_query());
}
return mediaList;
},
/*
* Note: "expression" in the grammar maps to the _media_expression
* method.
*/
_media_query: function(){
/*
* media_query
* : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
* | expression [ AND S* expression ]*
* ;
*/
var tokenStream = this._tokenStream,
type = null,
ident = null,
token = null,
expressions = [];
if (tokenStream.match(Tokens.IDENT)){
ident = tokenStream.token().value.toLowerCase();
//since there's no custom tokens for these, need to manually check
if (ident != "only" && ident != "not"){
tokenStream.unget();
ident = null;
} else {
token = tokenStream.token();
}
}
this._readWhitespace();
if (tokenStream.peek() == Tokens.IDENT){
type = this._media_type();
if (token === null){
token = tokenStream.token();
}
} else if (tokenStream.peek() == Tokens.LPAREN){
if (token === null){
token = tokenStream.LT(1);
}
expressions.push(this._media_expression());
}
if (type === null && expressions.length === 0){
return null;
} else {
this._readWhitespace();
while (tokenStream.match(Tokens.IDENT)){
if (tokenStream.token().value.toLowerCase() != "and"){
this._unexpectedToken(tokenStream.token());
}
this._readWhitespace();
expressions.push(this._media_expression());
}
}
return new MediaQuery(ident, type, expressions, token.startLine, token.startCol);
},
//CSS3 Media Queries
_media_type: function(){
/*
* media_type
* : IDENT
* ;
*/
return this._media_feature();
},
/**
* Note: in CSS3 Media Queries, this is called "expression".
* Renamed here to avoid conflict with CSS3 Selectors
* definition of "expression". Also note that "expr" in the
* grammar now maps to "expression" from CSS3 selectors.
* @method _media_expression
* @private
*/
_media_expression: function(){
/*
* expression
* : '(' S* media_feature S* [ ':' S* expr ]? ')' S*
* ;
*/
var tokenStream = this._tokenStream,
feature = null,
token,
expression = null;
tokenStream.mustMatch(Tokens.LPAREN);
feature = this._media_feature();
this._readWhitespace();
if (tokenStream.match(Tokens.COLON)){
this._readWhitespace();
token = tokenStream.LT(1);
expression = this._expression();
}
tokenStream.mustMatch(Tokens.RPAREN);
this._readWhitespace();
return new MediaFeature(feature, (expression ? new SyntaxUnit(expression, token.startLine, token.startCol) : null));
},
//CSS3 Media Queries
_media_feature: function(){
/*
* media_feature
* : IDENT
* ;
*/
var tokenStream = this._tokenStream;
tokenStream.mustMatch(Tokens.IDENT);
return SyntaxUnit.fromToken(tokenStream.token());
},
//CSS3 Paged Media
_page: function(){
/*
* page:
* PAGE_SYM S* IDENT? pseudo_page? S*
* '{' S* [ declaration | margin ]? [ ';' S* [ declaration | margin ]? ]* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
line,
col,
identifier = null,
pseudoPage = null;
//look for @page
tokenStream.mustMatch(Tokens.PAGE_SYM);
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
if (tokenStream.match(Tokens.IDENT)){
identifier = tokenStream.token().value;
//The value 'auto' may not be used as a page name and MUST be treated as a syntax error.
if (identifier.toLowerCase() === "auto"){
this._unexpectedToken(tokenStream.token());
}
}
//see if there's a colon upcoming
if (tokenStream.peek() == Tokens.COLON){
pseudoPage = this._pseudo_page();
}
this._readWhitespace();
this.fire({
type: "startpage",
id: identifier,
pseudo: pseudoPage,
line: line,
col: col
});
this._readDeclarations(true, true);
this.fire({
type: "endpage",
id: identifier,
pseudo: pseudoPage,
line: line,
col: col
});
},
//CSS3 Paged Media
_margin: function(){
/*
* margin :
* margin_sym S* '{' declaration [ ';' S* declaration? ]* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
line,
col,
marginSym = this._margin_sym();
if (marginSym){
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this.fire({
type: "startpagemargin",
margin: marginSym,
line: line,
col: col
});
this._readDeclarations(true);
this.fire({
type: "endpagemargin",
margin: marginSym,
line: line,
col: col
});
return true;
} else {
return false;
}
},
//CSS3 Paged Media
_margin_sym: function(){
/*
* margin_sym :
* TOPLEFTCORNER_SYM |
* TOPLEFT_SYM |
* TOPCENTER_SYM |
* TOPRIGHT_SYM |
* TOPRIGHTCORNER_SYM |
* BOTTOMLEFTCORNER_SYM |
* BOTTOMLEFT_SYM |
* BOTTOMCENTER_SYM |
* BOTTOMRIGHT_SYM |
* BOTTOMRIGHTCORNER_SYM |
* LEFTTOP_SYM |
* LEFTMIDDLE_SYM |
* LEFTBOTTOM_SYM |
* RIGHTTOP_SYM |
* RIGHTMIDDLE_SYM |
* RIGHTBOTTOM_SYM
* ;
*/
var tokenStream = this._tokenStream;
if(tokenStream.match([Tokens.TOPLEFTCORNER_SYM, Tokens.TOPLEFT_SYM,
Tokens.TOPCENTER_SYM, Tokens.TOPRIGHT_SYM, Tokens.TOPRIGHTCORNER_SYM,
Tokens.BOTTOMLEFTCORNER_SYM, Tokens.BOTTOMLEFT_SYM,
Tokens.BOTTOMCENTER_SYM, Tokens.BOTTOMRIGHT_SYM,
Tokens.BOTTOMRIGHTCORNER_SYM, Tokens.LEFTTOP_SYM,
Tokens.LEFTMIDDLE_SYM, Tokens.LEFTBOTTOM_SYM, Tokens.RIGHTTOP_SYM,
Tokens.RIGHTMIDDLE_SYM, Tokens.RIGHTBOTTOM_SYM]))
{
return SyntaxUnit.fromToken(tokenStream.token());
} else {
return null;
}
},
_pseudo_page: function(){
/*
* pseudo_page
* : ':' IDENT
* ;
*/
var tokenStream = this._tokenStream;
tokenStream.mustMatch(Tokens.COLON);
tokenStream.mustMatch(Tokens.IDENT);
//TODO: CSS3 Paged Media says only "left", "center", and "right" are allowed
return tokenStream.token().value;
},
_font_face: function(){
/*
* font_face
* : FONT_FACE_SYM S*
* '{' S* declaration [ ';' S* declaration ]* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
line,
col;
//look for @page
tokenStream.mustMatch(Tokens.FONT_FACE_SYM);
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
this.fire({
type: "startfontface",
line: line,
col: col
});
this._readDeclarations(true);
this.fire({
type: "endfontface",
line: line,
col: col
});
},
_viewport: function(){
/*
* viewport
* : VIEWPORT_SYM S*
* '{' S* declaration? [ ';' S* declaration? ]* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
line,
col;
tokenStream.mustMatch(Tokens.VIEWPORT_SYM);
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
this.fire({
type: "startviewport",
line: line,
col: col
});
this._readDeclarations(true);
this.fire({
type: "endviewport",
line: line,
col: col
});
},
_operator: function(inFunction){
/*
* operator (outside function)
* : '/' S* | ',' S* | /( empty )/
* operator (inside function)
* : '/' S* | '+' S* | '*' S* | '-' S* /( empty )/
* ;
*/
var tokenStream = this._tokenStream,
token = null;
if (tokenStream.match([Tokens.SLASH, Tokens.COMMA]) ||
(inFunction && tokenStream.match([Tokens.PLUS, Tokens.STAR, Tokens.MINUS]))){
token = tokenStream.token();
this._readWhitespace();
}
return token ? PropertyValuePart.fromToken(token) : null;
},
_combinator: function(){
/*
* combinator
* : PLUS S* | GREATER S* | TILDE S* | S+
* ;
*/
var tokenStream = this._tokenStream,
value = null,
token;
if(tokenStream.match([Tokens.PLUS, Tokens.GREATER, Tokens.TILDE])){
token = tokenStream.token();
value = new Combinator(token.value, token.startLine, token.startCol);
this._readWhitespace();
}
return value;
},
_unary_operator: function(){
/*
* unary_operator
* : '-' | '+'
* ;
*/
var tokenStream = this._tokenStream;
if (tokenStream.match([Tokens.MINUS, Tokens.PLUS])){
return tokenStream.token().value;
} else {
return null;
}
},
_property: function(){
/*
* property
* : IDENT S*
* ;
*/
var tokenStream = this._tokenStream,
value = null,
hack = null,
tokenValue,
token,
line,
col;
//check for star hack - throws error if not allowed
if (tokenStream.peek() == Tokens.STAR && this.options.starHack){
tokenStream.get();
token = tokenStream.token();
hack = token.value;
line = token.startLine;
col = token.startCol;
}
if(tokenStream.match(Tokens.IDENT)){
token = tokenStream.token();
tokenValue = token.value;
//check for underscore hack - no error if not allowed because it's valid CSS syntax
if (tokenValue.charAt(0) == "_" && this.options.underscoreHack){
hack = "_";
tokenValue = tokenValue.substring(1);
}
value = new PropertyName(tokenValue, hack, (line||token.startLine), (col||token.startCol));
this._readWhitespace();
}
return value;
},
//Augmented with CSS3 Selectors
_ruleset: function(){
/*
* ruleset
* : selectors_group
* '{' S* declaration? [ ';' S* declaration? ]* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
tt,
selectors;
/*
* Error Recovery: If even a single selector fails to parse,
* then the entire ruleset should be thrown away.
*/
try {
selectors = this._selectors_group();
} catch (ex){
if (ex instanceof SyntaxError && !this.options.strict){
//fire error event
this.fire({
type: "error",
error: ex,
message: ex.message,
line: ex.line,
col: ex.col
});
//skip over everything until closing brace
tt = tokenStream.advance([Tokens.RBRACE]);
if (tt == Tokens.RBRACE){
//if there's a right brace, the rule is finished so don't do anything
} else {
//otherwise, rethrow the error because it wasn't handled properly
throw ex;
}
} else {
//not a syntax error, rethrow it
throw ex;
}
//trigger parser to continue
return true;
}
//if it got here, all selectors parsed
if (selectors){
this.fire({
type: "startrule",
selectors: selectors,
line: selectors[0].line,
col: selectors[0].col
});
this._readDeclarations(true);
this.fire({
type: "endrule",
selectors: selectors,
line: selectors[0].line,
col: selectors[0].col
});
}
return selectors;
},
//CSS3 Selectors
_selectors_group: function(){
/*
* selectors_group
* : selector [ COMMA S* selector ]*
* ;
*/
var tokenStream = this._tokenStream,
selectors = [],
selector;
selector = this._selector();
if (selector !== null){
selectors.push(selector);
while(tokenStream.match(Tokens.COMMA)){
this._readWhitespace();
selector = this._selector();
if (selector !== null){
selectors.push(selector);
} else {
this._unexpectedToken(tokenStream.LT(1));
}
}
}
return selectors.length ? selectors : null;
},
//CSS3 Selectors
_selector: function(){
/*
* selector
* : simple_selector_sequence [ combinator simple_selector_sequence ]*
* ;
*/
var tokenStream = this._tokenStream,
selector = [],
nextSelector = null,
combinator = null,
ws = null;
//if there's no simple selector, then there's no selector
nextSelector = this._simple_selector_sequence();
if (nextSelector === null){
return null;
}
selector.push(nextSelector);
do {
//look for a combinator
combinator = this._combinator();
if (combinator !== null){
selector.push(combinator);
nextSelector = this._simple_selector_sequence();
//there must be a next selector
if (nextSelector === null){
this._unexpectedToken(tokenStream.LT(1));
} else {
//nextSelector is an instance of SelectorPart
selector.push(nextSelector);
}
} else {
//if there's not whitespace, we're done
if (this._readWhitespace()){
//add whitespace separator
ws = new Combinator(tokenStream.token().value, tokenStream.token().startLine, tokenStream.token().startCol);
//combinator is not required
combinator = this._combinator();
//selector is required if there's a combinator
nextSelector = this._simple_selector_sequence();
if (nextSelector === null){
if (combinator !== null){
this._unexpectedToken(tokenStream.LT(1));
}
} else {
if (combinator !== null){
selector.push(combinator);
} else {
selector.push(ws);
}
selector.push(nextSelector);
}
} else {
break;
}
}
} while(true);
return new Selector(selector, selector[0].line, selector[0].col);
},
//CSS3 Selectors
_simple_selector_sequence: function(){
/*
* simple_selector_sequence
* : [ type_selector | universal ]
* [ HASH | class | attrib | pseudo | negation ]*
* | [ HASH | class | attrib | pseudo | negation ]+
* ;
*/
var tokenStream = this._tokenStream,
//parts of a simple selector
elementName = null,
modifiers = [],
//complete selector text
selectorText= "",
//the different parts after the element name to search for
components = [
//HASH
function(){
return tokenStream.match(Tokens.HASH) ?
new SelectorSubPart(tokenStream.token().value, "id", tokenStream.token().startLine, tokenStream.token().startCol) :
null;
},
this._class,
this._attrib,
this._pseudo,
this._negation
],
i = 0,
len = components.length,
component = null,
found = false,
line,
col;
//get starting line and column for the selector
line = tokenStream.LT(1).startLine;
col = tokenStream.LT(1).startCol;
elementName = this._type_selector();
if (!elementName){
elementName = this._universal();
}
if (elementName !== null){
selectorText += elementName;
}
while(true){
//whitespace means we're done
if (tokenStream.peek() === Tokens.S){
break;
}
//check for each component
while(i < len && component === null){
component = components[i++].call(this);
}
if (component === null){
//we don't have a selector
if (selectorText === ""){
return null;
} else {
break;
}
} else {
i = 0;
modifiers.push(component);
selectorText += component.toString();
component = null;
}
}
return selectorText !== "" ?
new SelectorPart(elementName, modifiers, selectorText, line, col) :
null;
},
//CSS3 Selectors
_type_selector: function(){
/*
* type_selector
* : [ namespace_prefix ]? element_name
* ;
*/
var tokenStream = this._tokenStream,
ns = this._namespace_prefix(),
elementName = this._element_name();
if (!elementName){
/*
* Need to back out the namespace that was read due to both
* type_selector and universal reading namespace_prefix
* first. Kind of hacky, but only way I can figure out
* right now how to not change the grammar.
*/
if (ns){
tokenStream.unget();
if (ns.length > 1){
tokenStream.unget();
}
}
return null;
} else {
if (ns){
elementName.text = ns + elementName.text;
elementName.col -= ns.length;
}
return elementName;
}
},
//CSS3 Selectors
_class: function(){
/*
* class
* : '.' IDENT
* ;
*/
var tokenStream = this._tokenStream,
token;
if (tokenStream.match(Tokens.DOT)){
tokenStream.mustMatch(Tokens.IDENT);
token = tokenStream.token();
return new SelectorSubPart("." + token.value, "class", token.startLine, token.startCol - 1);
} else {
return null;
}
},
//CSS3 Selectors
_element_name: function(){
/*
* element_name
* : IDENT
* ;
*/
var tokenStream = this._tokenStream,
token;
if (tokenStream.match(Tokens.IDENT)){
token = tokenStream.token();
return new SelectorSubPart(token.value, "elementName", token.startLine, token.startCol);
} else {
return null;
}
},
//CSS3 Selectors
_namespace_prefix: function(){
/*
* namespace_prefix
* : [ IDENT | '*' ]? '|'
* ;
*/
var tokenStream = this._tokenStream,
value = "";
//verify that this is a namespace prefix
if (tokenStream.LA(1) === Tokens.PIPE || tokenStream.LA(2) === Tokens.PIPE){
if(tokenStream.match([Tokens.IDENT, Tokens.STAR])){
value += tokenStream.token().value;
}
tokenStream.mustMatch(Tokens.PIPE);
value += "|";
}
return value.length ? value : null;
},
//CSS3 Selectors
_universal: function(){
/*
* universal
* : [ namespace_prefix ]? '*'
* ;
*/
var tokenStream = this._tokenStream,
value = "",
ns;
ns = this._namespace_prefix();
if(ns){
value += ns;
}
if(tokenStream.match(Tokens.STAR)){
value += "*";
}
return value.length ? value : null;
},
//CSS3 Selectors
_attrib: function(){
/*
* attrib
* : '[' S* [ namespace_prefix ]? IDENT S*
* [ [ PREFIXMATCH |
* SUFFIXMATCH |
* SUBSTRINGMATCH |
* '=' |
* INCLUDES |
* DASHMATCH ] S* [ IDENT | STRING ] S*
* ]? ']'
* ;
*/
var tokenStream = this._tokenStream,
value = null,
ns,
token;
if (tokenStream.match(Tokens.LBRACKET)){
token = tokenStream.token();
value = token.value;
value += this._readWhitespace();
ns = this._namespace_prefix();
if (ns){
value += ns;
}
tokenStream.mustMatch(Tokens.IDENT);
value += tokenStream.token().value;
value += this._readWhitespace();
if(tokenStream.match([Tokens.PREFIXMATCH, Tokens.SUFFIXMATCH, Tokens.SUBSTRINGMATCH,
Tokens.EQUALS, Tokens.INCLUDES, Tokens.DASHMATCH])){
value += tokenStream.token().value;
value += this._readWhitespace();
tokenStream.mustMatch([Tokens.IDENT, Tokens.STRING]);
value += tokenStream.token().value;
value += this._readWhitespace();
}
tokenStream.mustMatch(Tokens.RBRACKET);
return new SelectorSubPart(value + "]", "attribute", token.startLine, token.startCol);
} else {
return null;
}
},
//CSS3 Selectors
_pseudo: function(){
/*
* pseudo
* : ':' ':'? [ IDENT | functional_pseudo ]
* ;
*/
var tokenStream = this._tokenStream,
pseudo = null,
colons = ":",
line,
col;
if (tokenStream.match(Tokens.COLON)){
if (tokenStream.match(Tokens.COLON)){
colons += ":";
}
if (tokenStream.match(Tokens.IDENT)){
pseudo = tokenStream.token().value;
line = tokenStream.token().startLine;
col = tokenStream.token().startCol - colons.length;
} else if (tokenStream.peek() == Tokens.FUNCTION){
line = tokenStream.LT(1).startLine;
col = tokenStream.LT(1).startCol - colons.length;
pseudo = this._functional_pseudo();
}
if (pseudo){
pseudo = new SelectorSubPart(colons + pseudo, "pseudo", line, col);
}
}
return pseudo;
},
//CSS3 Selectors
_functional_pseudo: function(){
/*
* functional_pseudo
* : FUNCTION S* expression ')'
* ;
*/
var tokenStream = this._tokenStream,
value = null;
if(tokenStream.match(Tokens.FUNCTION)){
value = tokenStream.token().value;
value += this._readWhitespace();
value += this._expression();
tokenStream.mustMatch(Tokens.RPAREN);
value += ")";
}
return value;
},
//CSS3 Selectors
_expression: function(){
/*
* expression
* : [ [ PLUS | '-' | DIMENSION | NUMBER | STRING | IDENT ] S* ]+
* ;
*/
var tokenStream = this._tokenStream,
value = "";
while(tokenStream.match([Tokens.PLUS, Tokens.MINUS, Tokens.DIMENSION,
Tokens.NUMBER, Tokens.STRING, Tokens.IDENT, Tokens.LENGTH,
Tokens.FREQ, Tokens.ANGLE, Tokens.TIME,
Tokens.RESOLUTION, Tokens.SLASH])){
value += tokenStream.token().value;
value += this._readWhitespace();
}
return value.length ? value : null;
},
//CSS3 Selectors
_negation: function(){
/*
* negation
* : NOT S* negation_arg S* ')'
* ;
*/
var tokenStream = this._tokenStream,
line,
col,
value = "",
arg,
subpart = null;
if (tokenStream.match(Tokens.NOT)){
value = tokenStream.token().value;
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
value += this._readWhitespace();
arg = this._negation_arg();
value += arg;
value += this._readWhitespace();
tokenStream.match(Tokens.RPAREN);
value += tokenStream.token().value;
subpart = new SelectorSubPart(value, "not", line, col);
subpart.args.push(arg);
}
return subpart;
},
//CSS3 Selectors
_negation_arg: function(){
/*
* negation_arg
* : type_selector | universal | HASH | class | attrib | pseudo
* ;
*/
var tokenStream = this._tokenStream,
args = [
this._type_selector,
this._universal,
function(){
return tokenStream.match(Tokens.HASH) ?
new SelectorSubPart(tokenStream.token().value, "id", tokenStream.token().startLine, tokenStream.token().startCol) :
null;
},
this._class,
this._attrib,
this._pseudo
],
arg = null,
i = 0,
len = args.length,
elementName,
line,
col,
part;
line = tokenStream.LT(1).startLine;
col = tokenStream.LT(1).startCol;
while(i < len && arg === null){
arg = args[i].call(this);
i++;
}
//must be a negation arg
if (arg === null){
this._unexpectedToken(tokenStream.LT(1));
}
//it's an element name
if (arg.type == "elementName"){
part = new SelectorPart(arg, [], arg.toString(), line, col);
} else {
part = new SelectorPart(null, [arg], arg.toString(), line, col);
}
return part;
},
_declaration: function(){
/*
* declaration
* : property ':' S* expr prio?
* | /( empty )/
* ;
*/
var tokenStream = this._tokenStream,
property = null,
expr = null,
prio = null,
error = null,
invalid = null,
propertyName= "";
property = this._property();
if (property !== null){
tokenStream.mustMatch(Tokens.COLON);
this._readWhitespace();
expr = this._expr();
//if there's no parts for the value, it's an error
if (!expr || expr.length === 0){
this._unexpectedToken(tokenStream.LT(1));
}
prio = this._prio();
/*
* If hacks should be allowed, then only check the root
* property. If hacks should not be allowed, treat
* _property or *property as invalid properties.
*/
propertyName = property.toString();
if (this.options.starHack && property.hack == "*" ||
this.options.underscoreHack && property.hack == "_") {
propertyName = property.text;
}
try {
this._validateProperty(propertyName, expr);
} catch (ex) {
invalid = ex;
}
this.fire({
type: "property",
property: property,
value: expr,
important: prio,
line: property.line,
col: property.col,
invalid: invalid
});
return true;
} else {
return false;
}
},
_prio: function(){
/*
* prio
* : IMPORTANT_SYM S*
* ;
*/
var tokenStream = this._tokenStream,
result = tokenStream.match(Tokens.IMPORTANT_SYM);
this._readWhitespace();
return result;
},
_expr: function(inFunction){
/*
* expr
* : term [ operator term ]*
* ;
*/
var tokenStream = this._tokenStream,
values = [],
//valueParts = [],
value = null,
operator = null;
value = this._term(inFunction);
if (value !== null){
values.push(value);
do {
operator = this._operator(inFunction);
//if there's an operator, keep building up the value parts
if (operator){
values.push(operator);
} /*else {
//if there's not an operator, you have a full value
values.push(new PropertyValue(valueParts, valueParts[0].line, valueParts[0].col));
valueParts = [];
}*/
value = this._term(inFunction);
if (value === null){
break;
} else {
values.push(value);
}
} while(true);
}
//cleanup
/*if (valueParts.length){
values.push(new PropertyValue(valueParts, valueParts[0].line, valueParts[0].col));
}*/
return values.length > 0 ? new PropertyValue(values, values[0].line, values[0].col) : null;
},
_term: function(inFunction){
/*
* term
* : unary_operator?
* [ NUMBER S* | PERCENTAGE S* | LENGTH S* | ANGLE S* |
* TIME S* | FREQ S* | function | ie_function ]
* | STRING S* | IDENT S* | URI S* | UNICODERANGE S* | hexcolor
* ;
*/
var tokenStream = this._tokenStream,
unary = null,
value = null,
endChar = null,
token,
line,
col;
//returns the operator or null
unary = this._unary_operator();
if (unary !== null){
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
}
//exception for IE filters
if (tokenStream.peek() == Tokens.IE_FUNCTION && this.options.ieFilters){
value = this._ie_function();
if (unary === null){
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
}
//see if it's a simple block
} else if (inFunction && tokenStream.match([Tokens.LPAREN, Tokens.LBRACE, Tokens.LBRACKET])){
token = tokenStream.token();
endChar = token.endChar;
value = token.value + this._expr(inFunction).text;
if (unary === null){
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
}
tokenStream.mustMatch(Tokens.type(endChar));
value += endChar;
this._readWhitespace();
//see if there's a simple match
} else if (tokenStream.match([Tokens.NUMBER, Tokens.PERCENTAGE, Tokens.LENGTH,
Tokens.ANGLE, Tokens.TIME,
Tokens.FREQ, Tokens.STRING, Tokens.IDENT, Tokens.URI, Tokens.UNICODE_RANGE])){
value = tokenStream.token().value;
if (unary === null){
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
}
this._readWhitespace();
} else {
//see if it's a color
token = this._hexcolor();
if (token === null){
//if there's no unary, get the start of the next token for line/col info
if (unary === null){
line = tokenStream.LT(1).startLine;
col = tokenStream.LT(1).startCol;
}
//has to be a function
if (value === null){
/*
* This checks for alpha(opacity=0) style of IE
* functions. IE_FUNCTION only presents progid: style.
*/
if (tokenStream.LA(3) == Tokens.EQUALS && this.options.ieFilters){
value = this._ie_function();
} else {
value = this._function();
}
}
/*if (value === null){
return null;
//throw new Error("Expected identifier at line " + tokenStream.token().startLine + ", character " + tokenStream.token().startCol + ".");
}*/
} else {
value = token.value;
if (unary === null){
line = token.startLine;
col = token.startCol;
}
}
}
return value !== null ?
new PropertyValuePart(unary !== null ? unary + value : value, line, col) :
null;
},
_function: function(){
/*
* function
* : FUNCTION S* expr ')' S*
* ;
*/
var tokenStream = this._tokenStream,
functionText = null,
expr = null,
lt;
if (tokenStream.match(Tokens.FUNCTION)){
functionText = tokenStream.token().value;
this._readWhitespace();
expr = this._expr(true);
functionText += expr;
//START: Horrible hack in case it's an IE filter
if (this.options.ieFilters && tokenStream.peek() == Tokens.EQUALS){
do {
if (this._readWhitespace()){
functionText += tokenStream.token().value;
}
//might be second time in the loop
if (tokenStream.LA(0) == Tokens.COMMA){
functionText += tokenStream.token().value;
}
tokenStream.match(Tokens.IDENT);
functionText += tokenStream.token().value;
tokenStream.match(Tokens.EQUALS);
functionText += tokenStream.token().value;
//functionText += this._term();
lt = tokenStream.peek();
while(lt != Tokens.COMMA && lt != Tokens.S && lt != Tokens.RPAREN){
tokenStream.get();
functionText += tokenStream.token().value;
lt = tokenStream.peek();
}
} while(tokenStream.match([Tokens.COMMA, Tokens.S]));
}
//END: Horrible Hack
tokenStream.match(Tokens.RPAREN);
functionText += ")";
this._readWhitespace();
}
return functionText;
},
_ie_function: function(){
/* (My own extension)
* ie_function
* : IE_FUNCTION S* IDENT '=' term [S* ','? IDENT '=' term]+ ')' S*
* ;
*/
var tokenStream = this._tokenStream,
functionText = null,
expr = null,
lt;
//IE function can begin like a regular function, too
if (tokenStream.match([Tokens.IE_FUNCTION, Tokens.FUNCTION])){
functionText = tokenStream.token().value;
do {
if (this._readWhitespace()){
functionText += tokenStream.token().value;
}
//might be second time in the loop
if (tokenStream.LA(0) == Tokens.COMMA){
functionText += tokenStream.token().value;
}
tokenStream.match(Tokens.IDENT);
functionText += tokenStream.token().value;
tokenStream.match(Tokens.EQUALS);
functionText += tokenStream.token().value;
//functionText += this._term();
lt = tokenStream.peek();
while(lt != Tokens.COMMA && lt != Tokens.S && lt != Tokens.RPAREN){
tokenStream.get();
functionText += tokenStream.token().value;
lt = tokenStream.peek();
}
} while(tokenStream.match([Tokens.COMMA, Tokens.S]));
tokenStream.match(Tokens.RPAREN);
functionText += ")";
this._readWhitespace();
}
return functionText;
},
_hexcolor: function(){
/*
* There is a constraint on the color that it must
* have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
* after the "#"; e.g., "#000" is OK, but "#abcd" is not.
*
* hexcolor
* : HASH S*
* ;
*/
var tokenStream = this._tokenStream,
token = null,
color;
if(tokenStream.match(Tokens.HASH)){
//need to do some validation here
token = tokenStream.token();
color = token.value;
if (!/#[a-f0-9]{3,6}/i.test(color)){
throw new SyntaxError("Expected a hex color but found '" + color + "' at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
}
this._readWhitespace();
}
return token;
},
//-----------------------------------------------------------------
// Animations methods
//-----------------------------------------------------------------
_keyframes: function(){
/*
* keyframes:
* : KEYFRAMES_SYM S* keyframe_name S* '{' S* keyframe_rule* '}' {
* ;
*/
var tokenStream = this._tokenStream,
token,
tt,
name,
prefix = "";
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
token = tokenStream.token();
if (/^@\-([^\-]+)\-/.test(token.value)) {
prefix = RegExp.$1;
}
this._readWhitespace();
name = this._keyframe_name();
this._readWhitespace();
tokenStream.mustMatch(Tokens.LBRACE);
this.fire({
type: "startkeyframes",
name: name,
prefix: prefix,
line: token.startLine,
col: token.startCol
});
this._readWhitespace();
tt = tokenStream.peek();
//check for key
while(tt == Tokens.IDENT || tt == Tokens.PERCENTAGE) {
this._keyframe_rule();
this._readWhitespace();
tt = tokenStream.peek();
}
this.fire({
type: "endkeyframes",
name: name,
prefix: prefix,
line: token.startLine,
col: token.startCol
});
this._readWhitespace();
tokenStream.mustMatch(Tokens.RBRACE);
},
_keyframe_name: function(){
/*
* keyframe_name:
* : IDENT
* | STRING
* ;
*/
var tokenStream = this._tokenStream,
token;
tokenStream.mustMatch([Tokens.IDENT, Tokens.STRING]);
return SyntaxUnit.fromToken(tokenStream.token());
},
_keyframe_rule: function(){
/*
* keyframe_rule:
* : key_list S*
* '{' S* declaration [ ';' S* declaration ]* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
token,
keyList = this._key_list();
this.fire({
type: "startkeyframerule",
keys: keyList,
line: keyList[0].line,
col: keyList[0].col
});
this._readDeclarations(true);
this.fire({
type: "endkeyframerule",
keys: keyList,
line: keyList[0].line,
col: keyList[0].col
});
},
_key_list: function(){
/*
* key_list:
* : key [ S* ',' S* key]*
* ;
*/
var tokenStream = this._tokenStream,
token,
key,
keyList = [];
//must be least one key
keyList.push(this._key());
this._readWhitespace();
while(tokenStream.match(Tokens.COMMA)){
this._readWhitespace();
keyList.push(this._key());
this._readWhitespace();
}
return keyList;
},
_key: function(){
/*
* There is a restriction that IDENT can be only "from" or "to".
*
* key
* : PERCENTAGE
* | IDENT
* ;
*/
var tokenStream = this._tokenStream,
token;
if (tokenStream.match(Tokens.PERCENTAGE)){
return SyntaxUnit.fromToken(tokenStream.token());
} else if (tokenStream.match(Tokens.IDENT)){
token = tokenStream.token();
if (/from|to/i.test(token.value)){
return SyntaxUnit.fromToken(token);
}
tokenStream.unget();
}
//if it gets here, there wasn't a valid token, so time to explode
this._unexpectedToken(tokenStream.LT(1));
},
//-----------------------------------------------------------------
// Helper methods
//-----------------------------------------------------------------
/**
* Not part of CSS grammar, but useful for skipping over
* combination of white space and HTML-style comments.
* @return {void}
* @method _skipCruft
* @private
*/
_skipCruft: function(){
while(this._tokenStream.match([Tokens.S, Tokens.CDO, Tokens.CDC])){
//noop
}
},
/**
* Not part of CSS grammar, but this pattern occurs frequently
* in the official CSS grammar. Split out here to eliminate
* duplicate code.
* @param {Boolean} checkStart Indicates if the rule should check
* for the left brace at the beginning.
* @param {Boolean} readMargins Indicates if the rule should check
* for margin patterns.
* @return {void}
* @method _readDeclarations
* @private
*/
_readDeclarations: function(checkStart, readMargins){
/*
* Reads the pattern
* S* '{' S* declaration [ ';' S* declaration ]* '}' S*
* or
* S* '{' S* [ declaration | margin ]? [ ';' S* [ declaration | margin ]? ]* '}' S*
* Note that this is how it is described in CSS3 Paged Media, but is actually incorrect.
* A semicolon is only necessary following a declaration is there's another declaration
* or margin afterwards.
*/
var tokenStream = this._tokenStream,
tt;
this._readWhitespace();
if (checkStart){
tokenStream.mustMatch(Tokens.LBRACE);
}
this._readWhitespace();
try {
while(true){
if (tokenStream.match(Tokens.SEMICOLON) || (readMargins && this._margin())){
//noop
} else if (this._declaration()){
if (!tokenStream.match(Tokens.SEMICOLON)){
break;
}
} else {
break;
}
//if ((!this._margin() && !this._declaration()) || !tokenStream.match(Tokens.SEMICOLON)){
// break;
//}
this._readWhitespace();
}
tokenStream.mustMatch(Tokens.RBRACE);
this._readWhitespace();
} catch (ex) {
if (ex instanceof SyntaxError && !this.options.strict){
//fire error event
this.fire({
type: "error",
error: ex,
message: ex.message,
line: ex.line,
col: ex.col
});
//see if there's another declaration
tt = tokenStream.advance([Tokens.SEMICOLON, Tokens.RBRACE]);
if (tt == Tokens.SEMICOLON){
//if there's a semicolon, then there might be another declaration
this._readDeclarations(false, readMargins);
} else if (tt != Tokens.RBRACE){
//if there's a right brace, the rule is finished so don't do anything
//otherwise, rethrow the error because it wasn't handled properly
throw ex;
}
} else {
//not a syntax error, rethrow it
throw ex;
}
}
},
/**
* In some cases, you can end up with two white space tokens in a
* row. Instead of making a change in every function that looks for
* white space, this function is used to match as much white space
* as necessary.
* @method _readWhitespace
* @return {String} The white space if found, empty string if not.
* @private
*/
_readWhitespace: function(){
var tokenStream = this._tokenStream,
ws = "";
while(tokenStream.match(Tokens.S)){
ws += tokenStream.token().value;
}
return ws;
},
/**
* Throws an error when an unexpected token is found.
* @param {Object} token The token that was found.
* @method _unexpectedToken
* @return {void}
* @private
*/
_unexpectedToken: function(token){
throw new SyntaxError("Unexpected token '" + token.value + "' at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
},
/**
* Helper method used for parsing subparts of a style sheet.
* @return {void}
* @method _verifyEnd
* @private
*/
_verifyEnd: function(){
if (this._tokenStream.LA(1) != Tokens.EOF){
this._unexpectedToken(this._tokenStream.LT(1));
}
},
//-----------------------------------------------------------------
// Validation methods
//-----------------------------------------------------------------
_validateProperty: function(property, value){
Validation.validate(property, value);
},
//-----------------------------------------------------------------
// Parsing methods
//-----------------------------------------------------------------
parse: function(input){
this._tokenStream = new TokenStream(input, Tokens);
this._stylesheet();
},
parseStyleSheet: function(input){
//just passthrough
return this.parse(input);
},
parseMediaQuery: function(input){
this._tokenStream = new TokenStream(input, Tokens);
var result = this._media_query();
//if there's anything more, then it's an invalid selector
this._verifyEnd();
//otherwise return result
return result;
},
/**
* Parses a property value (everything after the semicolon).
* @return {parserlib.css.PropertyValue} The property value.
* @throws parserlib.util.SyntaxError If an unexpected token is found.
* @method parserPropertyValue
*/
parsePropertyValue: function(input){
this._tokenStream = new TokenStream(input, Tokens);
this._readWhitespace();
var result = this._expr();
//okay to have a trailing white space
this._readWhitespace();
//if there's anything more, then it's an invalid selector
this._verifyEnd();
//otherwise return result
return result;
},
/**
* Parses a complete CSS rule, including selectors and
* properties.
* @param {String} input The text to parser.
* @return {Boolean} True if the parse completed successfully, false if not.
* @method parseRule
*/
parseRule: function(input){
this._tokenStream = new TokenStream(input, Tokens);
//skip any leading white space
this._readWhitespace();
var result = this._ruleset();
//skip any trailing white space
this._readWhitespace();
//if there's anything more, then it's an invalid selector
this._verifyEnd();
//otherwise return result
return result;
},
/**
* Parses a single CSS selector (no comma)
* @param {String} input The text to parse as a CSS selector.
* @return {Selector} An object representing the selector.
* @throws parserlib.util.SyntaxError If an unexpected token is found.
* @method parseSelector
*/
parseSelector: function(input){
this._tokenStream = new TokenStream(input, Tokens);
//skip any leading white space
this._readWhitespace();
var result = this._selector();
//skip any trailing white space
this._readWhitespace();
//if there's anything more, then it's an invalid selector
this._verifyEnd();
//otherwise return result
return result;
},
/**
* Parses an HTML style attribute: a set of CSS declarations
* separated by semicolons.
* @param {String} input The text to parse as a style attribute
* @return {void}
* @method parseStyleAttribute
*/
parseStyleAttribute: function(input){
input += "}"; // for error recovery in _readDeclarations()
this._tokenStream = new TokenStream(input, Tokens);
this._readDeclarations();
}
};
//copy over onto prototype
for (prop in additions){
if (additions.hasOwnProperty(prop)){
proto[prop] = additions[prop];
}
}
return proto;
}();
/*
nth
: S* [ ['-'|'+']? INTEGER? {N} [ S* ['-'|'+'] S* INTEGER ]? |
['-'|'+']? INTEGER | {O}{D}{D} | {E}{V}{E}{N} ] S*
;
*/
/*global Validation, ValidationTypes, ValidationError*/
var Properties = {
//A
"align-items" : "flex-start | flex-end | center | baseline | stretch",
"align-content" : "flex-start | flex-end | center | space-between | space-around | stretch",
"align-self" : "auto | flex-start | flex-end | center | baseline | stretch",
"-webkit-align-items" : "flex-start | flex-end | center | baseline | stretch",
"-webkit-align-content" : "flex-start | flex-end | center | space-between | space-around | stretch",
"-webkit-align-self" : "auto | flex-start | flex-end | center | baseline | stretch",
"alignment-adjust" : "auto | baseline | before-edge | text-before-edge | middle | central | after-edge | text-after-edge | ideographic | alphabetic | hanging | mathematical | | ",
"alignment-baseline" : "baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
"animation" : 1,
"animation-delay" : { multi: "